Android的不能启动活动 - 了java.lang.RuntimeException:无法启动活动ComponentInfo [英] Android cannot start Activity - java.lang.RuntimeException: Unable to start activity ComponentInfo
问题描述
下面是真的让我一个问题,每当我尝试推出我的应用程序的主要活动,我得到了LogCat中的错误:
了java.lang.RuntimeException:无法启动活动ComponentInfo {me.kworden.atic / me.kworden.atic.MainActivity}:android.content.res.Resources $ NotFoundException:资源ID#0x7f0c00a9
块引用>堆栈跟踪说,问题是我的
super.onCreate(savedInstanceState)
在我的的onCreate()
方法,这是令人沮丧的我,因为我无法控制的超类方法。我使用的内容布局只是一个
的LinearLayout
,所以我不认为这是必要的,你都可以看到我的XML文件,但我将发布根据要求。我已经看到了这样其他类似问题,但唯一的答案是清洁/重建项目,这并没有为我做任何事情。我使用的Android版本工作室。 1.1.0如果这是一个已知的问题,但我还没有看到任何已知的bug。
下面是我MainActivity,我已经剥离了大部分的code,以查明问题,但现在看来,
super.onCreate
是罪魁祸首;尽管是非常准系统,我的应用程序仍然未能甚至开始(即我得到不幸的是,应用程序已停止)。进口android.support.v7.app.ActionBarActivity;
进口android.os.Bundle;
进口android.view.Menu;
进口android.view.MenuItem;公共类MainActivity扩展ActionBarActivity
{
@覆盖
保护无效的onCreate(捆绑savedInstanceState)
{
//创建活动,并设置主要内容视图//
super.onCreate(savedInstanceState); //这是第17行,每堆栈跟踪//
的setContentView(R.layout.activity_main);
} @覆盖
公共布尔onCreateOptionsMenu(菜单菜单)
{
//充气主菜单工具栏//
。getMenuInflater()膨胀(R.menu.menu_main,菜单);
返回true;
} @覆盖
公共布尔onOptionsItemSelected(菜单项项)
{
INT ID = item.getItemId(); 如果(ID == R.id.action_settings)
{
返回true;
} 返回super.onOptionsItemSelected(项目);
}
}下面是我完整的堆栈跟踪:
03-16 23:16:33.572 1494年至1494年/ me.kworden.atic E / AndroidRuntime:致命异常:主要
工艺:me.kworden.atic,PID:1494
了java.lang.RuntimeException:无法启动活动ComponentInfo {me.kworden.atic / me.kworden.atic.MainActivity}:android.content.res.Resources $ NotFoundException:资源ID#0x7f0c00a9
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
在android.app.ActivityThread.access $ 800(ActivityThread.java:144)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:135)
在android.app.ActivityThread.main(ActivityThread.java:5221)
在java.lang.reflect.Method.invoke(本机方法)
在java.lang.reflect.Method.invoke(Method.java:372)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
android.content.res.Resources $ NotFoundException:资源ID#0x7f0c00a9所致
在android.content.res.Resources.getValue(Resources.java:1233)
在android.content.res.Resources.getDrawable(Resources.java:756)
在android.content.Context.getDrawable(Context.java:402)
在com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3514)
在com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3561)
在com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1916)
在android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:151)
在android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
在me.kworden.atic.MainActivity.onCreate(MainActivity.java:17)
在android.app.Activity.performCreate(Activity.java:5933)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
在android.app.ActivityThread.access $ 800(ActivityThread.java:144)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1278)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:135)
在android.app.ActivityThread.main(ActivityThread.java:5221)
在java.lang.reflect.Method.invoke(本机方法)
在java.lang.reflect.Method.invoke(Method.java:372)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
解决方案如果有人在将来对这个绊倒我想确保你可以得到答案......
问题是,在我的风格是使用某些标记,只提供给材料和Android 5.0以上版本。所以,我反而做了一个
RES /值-V21 / styles.xml
文件夹,并把我的适当的设置在那里。这固定的问题。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 myonCreate()
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)
解决方案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.这篇关于Android的不能启动活动 - 了java.lang.RuntimeException:无法启动活动ComponentInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!