【问题标题】:Unable to start activity componentinfo (error en setContentView)无法启动活动组件信息(错误 en setContentView)
【发布时间】:2016-05-17 22:49:54
【问题描述】:

我知道这是一个重点话题,但我找不到我的错误......

我的.MainActivity 中有这个:

public class MainActivity extends Activity{

...

    public void abrirAppMovimiento(View view) {
        Intent mov = new Intent(this, Movimiento.class);
        startActivity(mov);
    }

...

}

这是我的AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.emiliomorillanieto.practica3" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Movimiento"
            android:parentActivityName=".MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
    </application>

</manifest>

这是.Movimiento的课程:

public class Movimiento extends Activity implements SensorEventListener {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_movimiento);
      }
 }

我正在调试应用程序,当应用程序进入.Movimiento时,savedInstanceStatenull,但是在尝试执行“setContentView”时出现错误。

如果我在AndroidManifest.xml 中定义了我的activity_movimiento.xml,为什么会这样?

我的activity_movimiento.xmlRelativeLayout,带有一些按钮,当它被触摸时会发出声音。没什么特别的。

编辑: 这是我的activity_movimiento.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="@color/gris_oscuro"
    android:orientation="vertical">

    <Button
        android:id="@+id/volver"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="volverAtras"
        android:text="Volver" />

    <TextView
        android:id="@+id/tv_resultado"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="56dp"
        android:text="@string/resultado"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <ImageView
        android:id="@+id/image_chew"
        android:layout_width="150px"
        android:layout_height="150px"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="63dp"
        android:src="@raw/chew_picture" />

    <ImageView
        android:id="@+id/image_laser"
        android:layout_width="150px"
        android:layout_height="150px"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@raw/laser_picture" />

    <ImageView
        android:id="@+id/image_darth"
        android:layout_width="150px"
        android:layout_height="150px"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/image_laser"
        android:src="@raw/darth_picture" />

    <ImageView
        android:id="@+id/image_luke"
        android:layout_width="150px"
        android:layout_height="150px"
        android:layout_above="@+id/tv_resultado"

        android:layout_alignLeft="@+id/image_chew"
        android:layout_alignStart="@+id/image_chew"
        android:src="@raw/luke_picture" />

</RelativeLayout>

还有错误:

02-08 11:12:29.126    9112-9112/com.example.emiliomorillanieto.practica3 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.emiliomorillanieto.practica3/com.example.emiliomorillanieto.practica3.Movimiento}: android.view.InflateException: Binary XML file line #39: Error inflating class <unknown>
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
        at android.app.ActivityThread.access$900(ActivityThread.java:161)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5356)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class <unknown>
 …
 Caused by: java.lang.reflect.InvocationTargetException
 …
 Caused by: java.lang.OutOfMemoryError
 …

【问题讨论】:

  • 问题出在您的布局 xml 文件中
  • 请也发布完整的 logcat 错误跟踪和布局activity_movimiento
  • 完成了。我无法复制更多错误代码而不会出现问题。让我知道这对你来说是否足够。否则,我会尝试复制剩余的错误代码!
  • @user3529582: As in Log :Caused by: java.lang.OutOfMemoryError 表示其中一个 ImageView src 图像大小非常大
  • 最大的大约296kb。对 Android 来说太大了吗?

标签: android xml android-layout android-studio android-activity


【解决方案1】:

inflate 异常 在这里不是问题,但这来自您的布局中的另一个问题,即内存不足异常

当您尝试为加载可绘制资源的图像视图充气时,一个常见问题是内存不足异常。如果其中一个资源具有高像素分辨率,则会占用大量内存,从而导致 inflate 异常。

因此,请确认您的可绘制图像中的像素分辨率是您布局所需的最低要求。

结帐out of memory issue 并有很好的解释。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 2014-04-29
    相关资源
    最近更新 更多