-1

当我尝试从我的应用程序init()中的静态调用非静态方法时停止工作。Class1Class2

类1.java:

public class Class1 extends Activity {
    public void init() {
        ...
    }
}

类2.java:

...
Class1 var = new Class1 ();
var.init();
...

编译器没有显示任何错误,但应用程序仍然崩溃。有谁知道问题出在哪里。

4

1 回答 1

2

You can't new an instance of Activity yourself, you have to let the system do it.

You probably want create an Intent that starts an instance of Class1, then you can place your code inside the various lifecycle methods of the Activity subclass.

These are all basic Android concepts - read some documentation, grab some sample code and work from there instead of starting from scratch!

于 2013-09-10T22:16:43.897 回答