Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

android - Resource Not Found Exception when device's power button is pressed

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.

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.

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();
}

Please help me out. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...