2

Here's a problem that's really getting to me, whenever I try to launch my application's main activity, I get the error in LogCat:

java.lang.RuntimeException: Unable to start activity ComponentInfo{me.kworden.atic/me.kworden.atic.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9

The stack trace says that the problem is my super.onCreate(savedInstanceState) in my onCreate() method, which is frustrating me, because I can't control the superclass method.

The content layout I'm using is only a LinearLayout, so I don't think it is necessary for you all to see my xml file, although I will post on request.

I've seen the other similar problems on SO, but the only answers were "Clean/Rebuild the project" which hasn't done anything for me. I'm using Android Studio ver. 1.1.0 if this is a known problem, but I haven't seen any known bugs.

Here is my MainActivity, I've stripped out most of the code in order to pinpoint the problem, but now it seems that super.onCreate is the culprit; despite being extremely barebones, my app still fails to even start (i.e. I get "Unfortunately, app has stopped.").

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // Create the activity and set the main content view //
        super.onCreate(savedInstanceState); // This is line 17, per the stack trace //
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the main menu to the toolbar //
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        int id = item.getItemId();

        if(id == R.id.action_settings)
        {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Here is my full stack trace:

03-16 23:16:33.572    1494-1494/me.kworden.atic E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: me.kworden.atic, PID: 1494
    java.lang.RuntimeException: Unable to start activity ComponentInfo{me.kworden.atic/me.kworden.atic.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
            at android.content.res.Resources.getValue(Resources.java:1233)
            at android.content.res.Resources.getDrawable(Resources.java:756)
            at android.content.Context.getDrawable(Context.java:402)
            at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3514)
            at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3561)
            at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1916)
            at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:151)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
            at me.kworden.atic.MainActivity.onCreate(MainActivity.java:17)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Kenny Worden
  • 4,335
  • 11
  • 35
  • 62

4 Answers4

3

If anyone stumbles on this in the future I want to make sure that you can get an answer...

The problem was that certain tags that are available only to Material and Android 5.0+ were being used in my styles. So I instead made a res/values-v21/styles.xml folder and put my appropriate settings in there. That fixed the issue.

Kenny Worden
  • 4,335
  • 11
  • 35
  • 62
0

Remove setContentView(R.layout.activity_main); method

after removing this method if it run successfully then your layout id cannot be gernerated.

and also make sure that your layout id is generated or not in R.java file

Rakesh Kalashetti
  • 1,049
  • 8
  • 8
0

open manifest file check application package and activity. that is included or not included in file and also check style of application

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="yourapplicationpackage" >
       <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
        >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

           </application>

</manifest>
Muhammad Waleed
  • 2,517
  • 4
  • 27
  • 75
0

If you using tag <view> on xml file just change tag <view> to <View>