简体   繁体   中英

My application closes when the phone goes into suspension

I have a problem with an application I am making. When the phone goes into suspension, the application closes and shows a list of errors in the logcat I do not understand. Thank you very much any help or suggestions.

Here 's the code:
layout0.xml --->

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondo" >
<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true">   
    <ImageView
        android:id="@+id/imageView_reto_simple"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_weight="1"
        android:onClick="reto_simple_Click"
        android:src="@drawable/icono_entrenar_normal" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SIMPLE"
        android:layout_gravity="center"
        android:textSize="20dp" 
        android:textStyle="bold"
        android:textColor="#FFFFFF"  />
</LinearLayout>                                     

Layout0Activty.class --->

    package com.example.experiment;
    import android.media.AudioManager;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.View;
    import android.view.Window;
    import android.view.WindowManager;

    public class Layout0Activity extends Activity {
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);       
           requestWindowFeature(Window.FEATURE_NO_TITLE);
           //carregue el layout0
           setContentView(R.layout.layout0);        
           this.setVolumeControlStream(AudioManager.STREAM_MUSIC);  
    }     
    public void reto_simple_Click(View v){ 
        }   
    }

Android Manifest -->

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.example.experiment"
       android:versionCode="1"
       android:versionName="1.0" >
    <uses-sdk
       android:minSdkVersion="11"
       android:targetSdkVersion="11" />
   <application
       android:allowBackup="true"
       android:icon="@drawable/ic_launcher"
       android:label="@string/app_name"  >
    <activity
        android:name="com.example.experiment.Layout0Activity"
        android:screenOrientation="landscape"
        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>

The LogCat -->

    04-13 22:30:29.947: W/ResourceType(13922): Failure getting entry for 0x7f030000 (t=2 e=0) in package 0 (error -75)
    04-13 22:30:29.947: D/AndroidRuntime(13922): Shutting down VM
    04-13 22:30:29.947: W/dalvikvm(13922): threadid=1: thread exiting with uncaught exception (group=0x40c3c1f8)
    04-13 22:30:29.982: E/AndroidRuntime(13922): FATAL EXCEPTION: main
    04-13 22:30:29.982: E/AndroidRuntime(13922): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.experiment/com.example.experiment.Layout0Activity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030000
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3363)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.ActivityThread.access$700(ActivityThread.java:127)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1163)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.os.Handler.dispatchMessage(Handler.java:99)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.os.Looper.loop(Looper.java:137)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.ActivityThread.main(ActivityThread.java:4507)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at java.lang.reflect.Method.invokeNative(Native Method)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at java.lang.reflect.Method.invoke(Method.java:511)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at dalvik.system.NativeStart.main(Native Method)
    04-13 22:30:29.982: E/AndroidRuntime(13922): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030000
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.content.res.Resources.getValue(Resources.java:1019)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.content.res.Resources.getLayout(Resources.java:858)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:271)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.Activity.setContentView(Activity.java:1835)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at com.example.experiment.Layout0Activity.onCreate(Layout0Activity.java:20)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.Activity.performCreate(Activity.java:4465)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
    04-13 22:30:29.982: E/AndroidRuntime(13922):    ... 12 more

尝试重命名没有编号的布局。

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030000.

What resource is assigned that value in your gen/R.java file? I suspect it's R.layout.layout0 as that's the value assigned to the first activity of my projects as well.

I upvoted Allel's answer since that's what I suspected as well. I've had some build warnings in the past about numbers in resource file names.

Also, try doing a "Clean" build. I generally do this from Eclipse (Project-->Clean...), but it's pretty much equivalent to deleting the "gen" and "bin" directories and building again.

The only other thing it could be is your "drawable" (icono_entrenar_normal). Make sure you have a icono_entrenar_normal.png file in your "res/drawable" directory (even if you have a copy in your layout specific drawable-NNN directory).

I have solved the problem. In my project, I have the layout in the layout-land folder in the android manifest, I have the layouts activities associated with the attributes android: screenOrientation = "landscape". I think I had the same thing twice. I renamed the folder layout-land layout ... and the problem disappeared!! ..... Thank you all and I hope that if anyone has the same problem .... this will help .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM