错误信息:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.express_delivery, PID: 22103 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.express_delivery/com.example.express_delivery.sms.HomeActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3499) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3653) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:151) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:111) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2224) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:238) at android.app.ActivityThread.main(ActivityThread.java:7813) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995) Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:254) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2296) at android.content.res.Resources.getLayout(Resources.java:1183) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at android.view.LayoutInflater.inflate(LayoutInflater.java:481) at com.example.express_delivery.sms.PrivacyDialog.<init>(PrivacyDialog.java:50) at com.example.express_delivery.sms.HomeActivity.onCreate(HomeActivity.java:77) at android.app.Activity.performCreate(Activity.java:7961) at android.app.Activity.performCreate(Activity.java:7950) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3474) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3653) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:151) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:111) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2224) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:238) at android.app.ActivityThread.main(ActivityThread.java:7813) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
解决:
看到图中亮蓝色的字(这个是我们自己代码的错误),然后我就点击了这两个,最后发现下面这个我当初是引用的上边的,所以错误主要在PrivacyDialog.java文件里
我按提示定位到了错误的地方:
图中浅黄色的这一行,当时我就纳闷,这个smsdemo_authorize_dialog是什么?
然后就定位这个方法 getLayoutRes,想找到这个参数是什么
函数是长这样的,是一个layout的名字,我当时是想可能还有一个layout的xml文件没有添加,然后发现果然是(因为我这个也是参考的demo)
添加上之后,就不报错了
完结