Search code examples
androidandroid-fragmentsnexus-7nexus-4

Android Application working correctly on Nexus 7 but not on Nexus 4


I'm new to android app development and i'm following a tutorial on fragments, the final application is working correctly on Nexus 7 but not on Nexus 4. Both have android 4.4.2 installed. Here is a zip file of android project: https://dl.dropboxusercontent.com/u/108022472/fragments.zip I'm getting the following error with Nexus 4.

12-31 11:48:29.592  21384-21384/com.example.fragment2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.fragment2, PID: 21384
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragment2/com.example.fragment2.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030002
            at android.content.res.Resources.getValue(Resources.java:1123)
            at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
            at android.content.res.Resources.getLayout(Resources.java:939)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
            at android.app.Activity.setContentView(Activity.java:1929)
            at com.example.fragment2.MainActivity.onCreate(MainActivity.java:20)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

Can someone explains why the error is happening with Nexus 4 and not Nexus 7


Solution

  • The error says it plainly: the system can't find resource with id #0x7f030002, available for Nexus 4.

    To solve this, go to your R class, and look for the name of that resource; I see this is the id of news_articles layout. Now, a simple check in you layout folder will show you that you don't have any file with that name there, but only in the layout-large one.

    So, create a news_articles layout in the layout folder, to be used by all screen sizes; or, if it's not needed for regular phones, use reflection in code, in your java class, to make sure it's not asked for.