资源未发现异常时,设备的电源按钮为pressed [英] Resource Not Found Exception when device's power button is pressed

查看:122
本文介绍了资源未发现异常时,设备的电源按钮为pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写这工作正常的应用程序。有很多的活动。每个活动在横向模式下运行。现在假设用户是看到一个活动,他presses设备的电源按钮,目前设备处于睡眠模式。

I am writing an app which works fine. There are a lot of activities. Every activity runs in landscape mode. Now suppose that user is seeing an activity and he presses device's power button, now the device is in sleep mode.

但是,当他再次presses电源按钮的设备醒来,现在我的应用程序应该继续从用户离开,但我的应用刚刚倒闭,甚至没有一个强制关闭的消息,这意味着用户突然来到主屏幕。

But when he again presses the power button the device wakes up, now my app should continue from where user left it but my app just closes down without even a force close message, means user suddenly comes to Home Screen.

在logcat中它显示了以下错误 -

In logcat it shows the following error -

01-31 12:22:40.010: E/AndroidRuntime(10591): FATAL EXCEPTION: main
01-31 12:22:40.010: E/AndroidRuntime(10591): java.lang.RuntimeException: Unable to start         activity ComponentInfo{com.example.reflexapp/com.example.reflexapp.Login}:     android.content.res.Resources$NotFoundException: Resource ID #0x7f030023
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.ActivityThread.access$700(ActivityThread.java:150)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.os.Looper.loop(Looper.java:137)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.ActivityThread.main(ActivityThread.java:5283)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at java.lang.reflect.Method.invokeNative(Native Method)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at java.lang.reflect.Method.invoke(Method.java:511)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at dalvik.system.NativeStart.main(Native Method)
01-31 12:22:40.010: E/AndroidRuntime(10591): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030023
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.content.res.Resources.getValue(Resources.java:1883)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:3028)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.content.res.Resources.getLayout(Resources.java:1722)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:364)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.Activity.setContentView(Activity.java:1930)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at com.example.reflexapp.Login.onCreate(Login.java:18)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.Activity.performCreate(Activity.java:5283)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
01-31 12:22:40.010: E/AndroidRuntime(10591):    at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
01-31 12:22:40.010: E/AndroidRuntime(10591):    ... 11 more

我不明白我在做什么错在这里。在每个活动我做这样的 -

I don't understand what I am doing wrong here. In each activity I am doing like this -

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.userlogin);
    init();
}

请帮助我。先谢谢了。

推荐答案

我解决我的问题。我犯了一个错误,因为我的应用程序是指只在横向模式我把我所有的布局的XML文件中的布局土地文件夹的工作。中没有任何的布局文件夹中。

I solved my problem. I was making a mistake, as my app was meant to work only in landscape mode I was putting all my layout xml files in layout-land folder. There was nothing in layout folder.

但事实证明,当设备处于睡眠状态android系统试图把在纵向模式下的一切,所以它看起来肖像XML的中的布局文件夹,但没有得到。因此,它提供了资源未发现异常和应用程序退出。

But it turned out when device is put to sleep android system tries to bring everything in portrait mode, so it looks for portrait xmls in layout folder but gets nothing. Hence it gives Resource not found exception and app exits.

于是心里记下,即使你的应用程序将只显示景观布局,您必须在布局文件夹提供肖像XML的。 : - )

So mental note, even though your app will show only landscape layouts , you must provide portrait xmls in the layout folder. :-)

这篇关于资源未发现异常时,设备的电源按钮为pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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