【发布时间】: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时,savedInstanceState是null,但是在尝试执行“setContentView”时出现错误。
如果我在AndroidManifest.xml 中定义了我的activity_movimiento.xml,为什么会这样?
我的activity_movimiento.xml 是RelativeLayout,带有一些按钮,当它被触摸时会发出声音。没什么特别的。
编辑:
这是我的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