public static voID displayShare(){ // show share options CharSequence selections[] = new CharSequence[] {"Email","SMS","Tweet","Phone Call","Cancel"}; final AlertDialog.Builder builder = new AlertDialog.Builder(CommonVariables.mContext); builder.setTitle("Share your location via..."); builder.setItems(selections,new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog,int which) { switch(which){ case 0: // Email callEmailMethod(); break; case 1: // SMS callSMSMethod(); break; case 2: // Tweet callTwitterMethod(); break; case 3: // Phone Call callNumberMethod(); break; case 4: dialog.cancel(); break; } } }); builder.show();}
在以下行收到以下错误:builder.show();
FATAL EXCEPTION: mainProcess: com.au.ewn.melbwater,PID: 2839androID.content.res.Resources$NotFoundException: Resource ID #0x0 at androID.content.res.Resources.getValue(Resources.java:1351) at androID.content.res.Resources.loadXmlResourceParser(Resources.java:2774) at androID.content.res.Resources.getLayout(Resources.java:1165) at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:421) at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:374) at androID.support.v7.app.AlertController$AlertParams.createListVIEw(AlertController.java:879) at androID.support.v7.app.AlertController$AlertParams.apply(AlertController.java:856) at androID.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:899) at androID.support.v7.app.AlertDialog$Builder.show(AlertDialog.java:917) at com.au.ewn.activitIEs.MainFragment.displayShare(MainFragment.java:1081) at com.au.ewn.activitIEs.HelpMeScreen.onClick(HelpMeScreen.java:257) at androID.vIEw.VIEw.performClick(VIEw.java:5198) at androID.vIEw.VIEw$PerformClick.run(VIEw.java:21147) at androID.os.Handler.handleCallback(Handler.java:739) at androID.os.Handler.dispatchMessage(Handler.java:95) at androID.os.Looper.loop(Looper.java:148) at androID.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我已经尝试了一切(除了正确的解决方案,似乎).任何帮助表示赞赏,谢谢.
注意:CommonVariables.mContext是FragmentActivity的上下文,不是null:CommonVariables.mContext = FragmentAct.this;
解决方法 问题是我的项目缺少AlertDialog的样式资源:在styles.xml中放这个:
<style name="MyDialogtheme" parent="theme.AppCompat.light.Dialog.Alert" />
在您创建Alert Dialog的代码中输入:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),R.style.MyDialogtheme);
感谢@Fraranc在这篇文章中的回答:Resources$NotFoundException: Resource ID #0x0 in AlertDialog
总结以上是内存溢出为你收集整理的Android AlertDialog异常“Resources $NotFoundException”全部内容,希望文章能够帮你解决Android AlertDialog异常“Resources $NotFoundException”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)