unable to startActivity master-detail from another activity

感情迁移 提交于 2019-12-13 09:52:13

问题


I've an activity WelcomeActivity.java in which theres a button bContinue. In the OnClick method of the button, I tried this..

startActivity(new Intent(this, MenuItemDetailActivity.class));
//startActivity(new Intent("com.resto.demo.activity.MENUITEMLISTACTIVITY"));

neither of the above 2 lines work. instead they give me NullPointerException & the program ends abruptly..I cant find the problem.. is the problem in manifest or my call?

<activity
   android:name="com.resto.demo.activity.MenuItemListActivity"
   android:label="@string/title_menuitem_list" >
   <intent-filter>
       <action android:name="com.resto.demo.activity.MENUITEMLISTACTIVITY" />
       <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
</activity>

MenuItemListActivity is the part of master/detail flow. Thanx you. Also tell me if my problem is not understood. Any help/suggestion is welcome :)


回答1:


Edit your manifest

 <application 
    <activity
       android:name="com.resto.demo.activity.MenuItemListActivity"
       android:label="@string/title_menuitem_list" >
       <intent-filter>
           <action android:name="com.resto.demo.activity.MENUITEMLISTACTIVITY" />
           <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>
    </activity>
    <activity android:name="com.resto.demo.activity.MenuItemDetailActivity"/>
 </application>

And add this to OnClick event

startActivity(new Intent(MenuItemListActivity.this, MenuItemDetailActivity.class));



回答2:


The first thing I would do is make sure MenuItemDetailActivity is in the AndroidManifest as well (instead of just MenuItemListActivity)

<activity
   android:name="com.resto.demo.activity.MenuItemDetailActivity"
   android:label="..." >
</activity>

However, this does not normally throw a NullPointerException. Can you post the error message/stack trace for the NullPointerException? Also, it would be great to post the lines of code that the NullPointerException references.



来源:https://stackoverflow.com/questions/18120852/unable-to-startactivity-master-detail-from-another-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!