尝试启动FragmentActivity时,我一直得到NullPointer。

这是我得到的nullpointer。

09-05 14:44:21.550: ERROR/AndroidRuntime(19409): FATAL EXCEPTION: main
09-05 14:44:21.550: ERROR/AndroidRuntime(19409): java.lang.NullPointerException
09-05 14:44:21.550: ERROR/AndroidRuntime(19409):     at com.fttech.youtubeReaults.searchYoutube(youtubeReaults.java:182)
09-05 14:44:21.550: ERROR/AndroidRuntime(19409):     at com.fttech.youtubeReaults.onActivityCreated(youtubeReaults.java:59)
09-05 14:44:21.550: ERROR/AndroidRuntime(19409):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:760)
09-05 14:44:21.550: ERROR/AndroidRuntime(19409):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:933)
09-05 14:44:21.550: ERROR/AndroidRuntime(19409):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:578)
09-05 14:44:21.550: ERROR/AndroidRuntime(19409):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1219)


09-05 14:44:21.550:错误/ AndroidRuntime(19409):位于android.support.v4.app.FragmentManagerImpl $ 1.run(FragmentManager.java:380)
    09-05 14:44:21.550:错误/ AndroidRuntime(19409):位于android.os.Handler.handleCallback(Handler.java:587)

NullPointer指向我这里。

@Override
public void onActivityCreated(Bundle state){
    super.onActivityCreated(state);

    search = AccessibleYouTube_Fragment.search;

    ((TextView) getView().findViewById(R.id.textViewSearchResultTitle))
            .setText("Captioned search results for " + search);
            //NullPointer is pointing me to this line
    ArrayList<YouTubeResult> ytResults = searchYoutube(search);


我在这做错了吗?

最佳答案

有人在您的代码中为null,然后您尝试访问它。

在Nullpointer上,我只是建议你.......................

System.out.println(“ search” + search); ..

。并打印AccessibleYouTube_Fragment.search,也显示textview内容为null .................

关于android - 用列表启动FragmentActivity时是否为NullPointer?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7311733/

10-09 07:40