无法启动活动Resources $ NotFoundException [英] Unable to start activity Resources$NotFoundException

查看:86
本文介绍了无法启动活动Resources $ NotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发布了一个应用程序,并在Google Play上运行了几个月.

I've had an app published and running on google play for several months.

今天,我收到一个来自用户的错误,资源未找到异常.我以为我可能忘了一些绘画.从错误中我获得了对象ID(我从错误中获取了ID 0x7f030003),并在R.java中进行了查找,以确定缺少了哪些对象.

Today I received an error from a user with a resource not found exception. I thought i may have forgotten some drawable. From the error i got the object ID (I took ID 0x7f030003 from the error) and looked for it in R.java to determine what object was missing.

令我惊讶的是,我发现ID来自我的主要活动,所以我确定我没有忘记这一点!

To my surprise I found that the IDis from my Main Activity, so I'm sure I've not forgotten this!

我的应用程序从main开始,并从中调用所有其他活动/片段.回去时,我只是完成打开的活动,然后回到Main.因此,我的代码中没有对Main的显式调用,因此我不知道是什么原因引起的. 我不能复制它,只能从用户那里得到报告.

My app starts with main and all other activities/fragments are called from it. When going back I just finish opened activities and go back to Main. So there is no explicit call to Main from my code so I'm lost about what cause this. I can not reproduce it and only have the report from the user.

我在寻找资源时是否犯了一些错误?可能会发生什么?这是我通过控制台收到的错误

Did i do some mistake looking for the resource? what may be happening? heres is the error that I receive through the console

java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.myapp/com.myapp.MainActivity}:
> android.content.res.Resources$NotFoundException: Resource ID
> #0x7f030003 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
> at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
> at android.app.ActivityThread.access$2300(ActivityThread.java:125) at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
> at android.os.Handler.dispatchMessage(Handler.java:99) at
> android.os.Looper.loop(Looper.java:123) at
> android.app.ActivityThread.main(ActivityThread.java:4627) at
> java.lang.reflect.Method.invokeNative(Native Method) at
> java.lang.reflect.Method.invoke(Method.java:521) at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) at
> dalvik.system.NativeStart.main(Native Method) Caused by:
> android.content.res.Resources$NotFoundException: Resource ID
> #0x7f030003 at android.content.res.Resources.getValue(Resources.java:892) at
> android.content.res.Resources.loadXmlResourceParser(Resources.java:1869)
> at android.content.res.Resources.getLayout(Resources.java:731) at
> android.view.LayoutInflater.inflate(LayoutInflater.java:318) at
> android.view.LayoutInflater.inflate(LayoutInflater.java:276) at
> com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
> at android.app.Activity.setContentView(Activity.java:1647) at
> com.myapp.MainActivity.onCreate(MainActivity.java:48) at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
> at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
> ... 11 more

这是我主要的oncreate().

This is my main oncreate().

基本上,我有一个用作启动屏幕的布局.计时器触发了另一个线程,因此我可以在启动屏幕中更新状态栏时加载基本内容. 完成后,启动画面将设置为消失,并且可以看到主菜单. 如果MyApp被操作系统销毁,则布尔变量"inicializado"为null,然后我必须重新加载我的东西.这就是为什么我用它显示或不显示启动画面

Basically I have a layout that i use as splash screen. The timer triggers another thread so i can load basic stuff while i'm updating a status bar in splash screen. once finished the splash is set to gone and the main menu is visible. If MyApp is destroyed by the OS my Boolean variable "inicializado" is null and then i've to reload my things.That's why i use it to show or not the splash

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        splashProgress = (ProgressBar) findViewById(R.id.mainSplash_pb_progressBar);
        splashDescProgress = (TextView) findViewById(R.id.mainSplash_tv_descProgreso);

        PACKAGE_NAME = MyApp.getContext().getPackageName();
        media_btnClick = MediaPlayer.create(this, R.raw.btn_click);

        if (savedInstanceState == null) {
            TextView mi_textView = (TextView) findViewById(R.id.main_tv_Version);
            PackageInfo mi_packageInfo = null;
            try {
                mi_packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                mi_textView.setText("v" + mi_packageInfo.versionName);
                PACKAGE_CODE = mi_packageInfo.versionCode;
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
            }
            savedInstanceStateNull = true;

        } else {
            savedInstanceStateNull = false;
        }
        if (!MyApp.Inicializado) {
            cargarDatosSplash();

            Timer timer = new Timer();
            timer.schedule(new LanzarInicio(), 10);
        } else {
            LinearLayout layoutSplash = (LinearLayout) findViewById(R.id.main_splash);
            LinearLayout layoutMain = (LinearLayout) findViewById(R.id.main_menu);
            layoutSplash.setVisibility(View.GONE);
            layoutMain.setVisibility(View.VISIBLE);
        }
    }

class LanzarInicio extends TimerTask {
    public void run() {
        MainActivity.this.runOnUiThread(new Runnable() {
            public void run() {
                new cargarObjetosTask().execute();
            }
        });

    }
}

推荐答案

如果您的活动被轮流锁定,请将其添加到清单中:

If your activity is locked in rotation, add this to the manifest:

<activity 
    android:name=".MyActivity"
    android:screenOrientation="landscape" (or "portrait")
    android:configChanges="orientation"
/>

此问题的答案相同的解决方案.

Same solution as the answer of this question.

我在寻找资源时是否犯了一些错误?可能会发生什么?

Did i do some mistake looking for the resource? what may be happening?

在另一个奇怪的情况下,我在同一个地方遇到了您的问题setContentView(R.layout.activity_main);

I had your problem in another weird situation, in the same place setContentView(R.layout.activity_main);

我的应用被锁定为横向.第一次调用OnCreate一切都很好;第二次(例如,在按下按钮以关闭屏幕后立即发生),设备读取了方向状态,并且似乎在寻找我没有的肖像模式下的资源(因为我没有)不需要它).我得出这个结论是因为其他解决方案是将相关的布局添加到布局"页面中. (我仅使用"layout-land"目录)资源目录.

My app is locked in landscape orientation. The first time OnCreate is called everything is fine; the second time (it happen just after pressing the button to turn off the screen, for example), the device reads the orientation state, and seems that it looks for a resource in portrait mode that I don't have (because I don't need it). I came to this conclusion because other solution is to add the related layout to the "layout" (i was using only the "layout-land" directory) resources directory.

这可能是与特定(也许是旧)设备有关的问题.

It could be a problem related to specific (and perhaps old) devices.

这篇关于无法启动活动Resources $ NotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆