Android AlertDialog异常“Resources $NotFoundException”

Android AlertDialog异常“Resources $NotFoundException”,第1张

概述尝试在 Android中显示对话框时出现异常.我的AlertDialog是从FragmentActivity调用的,代码如下: public static void displayShare(){ // show share options CharSequence selections[] = new CharSequence[] {"Email", "SMS", "Tweet" 尝试在 Android中显示对话框时出现异常.我的AlertDialog是从FragmentActivity调用的,代码如下:
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”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1137789.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存