无法执行活动的方法。从FragmentActivity调用Fragment的方法

时间:2012-07-19 04:13:34

标签: android android-fragments android-fragmentactivity

尝试调用片段方法时,我收到错误“无法执行活动的方法”。

此方法位于扩展android.support.v4.app.FragmentActivity的类中。您可以在最后一行看到对NasaDailyFragment.onRefresh()的调用。 NasaDailyImage类扩展了android.support.v4.app.Fragment。我也尝试将onRefreshClicked()中的所有内容放在一个线程中,然后运行该线程,但又遇到了另一个我可以复制的奇怪错误,如果这会有所帮助。

 public class NasaAppActivity extends FragmentActivity {
//stuff
 public void onRefreshClicked(View view){
       Log.d("debug", "in run");
       FragmentManager fragmentManager=getSupportFragmentManager();
       NasaDailyImage NasaDailyFragment;
       NasaDailyFragment=(NasaDailyImage)fragmentManager.findFragmentById(R.id.fragment_iotd);
       Log.d("debug", "fragment has been casted");
       NasaDailyFragment.onRefresh();
}
   }

这是名为

的方法
public class NasaDailyImage extends Fragment {
//other methods
     public void onRefresh(){
            System.out.println("in onRefresh");
            new RssParseSync(getActivity()).execute(title,description,date,link);//using a class that extends asynctask
        }
}

logcat log

07-19 03:58:10.906: I/dalvikvm(629): threadid=3: reacting to signal 3
07-19 03:58:10.986: I/dalvikvm(629): Wrote stack traces to '/data/anr/traces.txt'
07-19 03:58:11.156: D/gralloc_goldfish(629): Emulator without GPU emulation detected.
07-19 03:59:06.446: D/debug(629): in run
07-19 03:59:06.446: D/debug(629): fragment has been casted
07-19 03:59:06.446: D/AndroidRuntime(629): Shutting down VM
07-19 03:59:06.446: W/dalvikvm(629): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
07-19 03:59:06.466: E/AndroidRuntime(629): FATAL EXCEPTION: main
07-19 03:59:06.466: E/AndroidRuntime(629): java.lang.IllegalStateException: Could not execute method of the activity
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.view.View$1.onClick(View.java:3044)
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.view.View.performClick(View.java:3511)
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.view.View$PerformClick.run(View.java:14105)
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.os.Handler.handleCallback(Handler.java:605)
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.os.Looper.loop(Looper.java:137)
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.app.ActivityThread.main(ActivityThread.java:4424)
07-19 03:59:06.466: E/AndroidRuntime(629):  at java.lang.reflect.Method.invokeNative(Native Method)
07-19 03:59:06.466: E/AndroidRuntime(629):  at java.lang.reflect.Method.invoke(Method.java:511)
07-19 03:59:06.466: E/AndroidRuntime(629):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-19 03:59:06.466: E/AndroidRuntime(629):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-19 03:59:06.466: E/AndroidRuntime(629):  at dalvik.system.NativeStart.main(Native Method)
07-19 03:59:06.466: E/AndroidRuntime(629): Caused by: java.lang.reflect.InvocationTargetException
07-19 03:59:06.466: E/AndroidRuntime(629):  at java.lang.reflect.Method.invokeNative(Native Method)
07-19 03:59:06.466: E/AndroidRuntime(629):  at java.lang.reflect.Method.invoke(Method.java:511)
07-19 03:59:06.466: E/AndroidRuntime(629):  at android.view.View$1.onClick(View.java:3039)
07-19 03:59:06.466: E/AndroidRuntime(629):  ... 11 more
07-19 03:59:06.466: E/AndroidRuntime(629): Caused by: java.lang.NullPointerException
07-19 03:59:06.466: E/AndroidRuntime(629):  at com.wajumbie.nasadailyimage.NasaAppActivity.onRefresh(NasaAppActivity.java:36)
07-19 03:59:06.466: E/AndroidRuntime(629):  ... 14 more
07-19 03:59:07.066: I/dalvikvm(629): threadid=3: reacting to signal 3
07-19 03:59:07.086: I/dalvikvm(629): Wrote stack traces to '/data/anr/traces.txt'

0 个答案:

没有答案