我需要从 AsyncTask 调用一个非静态方法
此方法必须在 onPostExecute 中调用
我用过:
Main.mymethod();
但它说:
Cannot make a static reference to the non-static method mymethod() from the type Main
如何解决?
谢谢
编辑:我尝试过:
protected void onPostExecute(String result) {
new Main().mymethod();
}
抛出:
07-09 01:43:15.248: E/AndroidRuntime(29945): FATAL EXCEPTION: main
07-09 01:43:15.248: E/AndroidRuntime(29945): java.lang.NullPointerException
07-09 01:43:15.248: E/AndroidRuntime(29945): at android.app.Activity.findViewById(Activity.java:1794)
07-09 01:43:15.248: E/AndroidRuntime(29945): at android.os.AsyncTask.finish(AsyncTask.java:602)
07-09 01:43:15.248: E/AndroidRuntime(29945): at android.os.AsyncTask.access$600(AsyncTask.java:156)
07-09 01:43:15.248: E/AndroidRuntime(29945): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
07-09 01:43:15.248: E/AndroidRuntime(29945): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 01:43:15.248: E/AndroidRuntime(29945): at android.os.Looper.loop(Looper.java:137)
07-09 01:43:15.248: E/AndroidRuntime(29945): at android.app.ActivityThread.main(ActivityThread.java:4575)
07-09 01:43:15.248: E/AndroidRuntime(29945): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 01:43:15.248: E/AndroidRuntime(29945): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 01:43:15.248: E/AndroidRuntime(29945): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-09 01:43:15.248: E/AndroidRuntime(29945): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-09 01:43:15.248: E/AndroidRuntime(29945): at dalvik.system.NativeStart.main(Native Method)