解決 java.lang.RuntimeException: Unable to start activity ComponentInfo{...}


錯誤信息:

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)

添加上之后,就不報錯了

完結


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM