Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 应用程序崩溃与简单的XML布局_Android - Fatal编程技术网

Android 应用程序崩溃与简单的XML布局

Android 应用程序崩溃与简单的XML布局,android,Android,我制作了一个应用程序“生日卡”,其中包含一个图像视图和两个文本视图,我在Genymotion Emulator上运行它,消息就会出现 “不幸的是,生日快乐已经停止。” 1-ActivityMain.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_wid

我制作了一个应用程序“生日卡”,其中包含一个图像视图和两个文本视图,我在Genymotion Emulator上运行它,消息就会出现

“不幸的是,生日快乐已经停止。”

1-ActivityMain.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/androidparty" />


    <TextView
        android:text="Happy Birthday Mohamed"
        android:layout_width="wrap_content"
        android:textSize="36sp"
        android:fontFamily="sans-serif-light"
        android:textColor="@android:color/white"
        android:layout_height="wrap_content"
        android:id="@+id/textView2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="24dp"
        android:layout_marginEnd="13dp"
        android:layout_marginRight="13dp"
        android:text="From,Abo Elmagd"
        android:textSize="36sp"
        android:textColor="@android:color/white"
        android:id="@+id/textView" />

</RelativeLayout>
}

3-logcat

02-17 21:31:57.757 1658-1658/? D/dalvikvm: Late-enabling CheckJNI
02-17 21:31:57.869 1658-1658/? I/dalvikvm: Could not find method 
android.view.Window$Callback.onPointerCaptureChanged, referenced from method 
android.support.v7.view.WindowCallbackWrapper.onPointerCaptureChanged
02-17 21:31:57.869 1658-1658/? W/dalvikvm: VFY: unable to resolve interface 
method 15988: Landroid/view/Window$Callback;.onPointerCaptureChanged (Z)V
02-17 21:31:57.869 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x72 at 
0x0002
02-17 21:31:57.869 1658-1658/? I/dalvikvm: Could not find method 
android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from 
method 
android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
02-17 21:31:57.869 1658-1658/? W/dalvikvm: VFY: unable to resolve interface 
method 15990: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts 
(Ljava/util/List;Landroid/view/Menu;I)V
02-17 21:31:57.873 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x72 at 
0x0002
02-17 21:31:57.873 1658-1658/? W/dalvikvm: VFY: unable to find class 
referenced in signature (Landroid/view/SearchEvent;)
02-17 21:31:57.873 1658-1658/? I/dalvikvm: Could not find method 
android.view.Window$Callback.onSearchRequested, referenced from method 
android.support.v7.view.WindowCallbackWrapper.onSearchRequested
02-17 21:31:57.873 1658-1658/? W/dalvikvm: VFY: unable to resolve interface 
method 15992: Landroid/view/Window$Callback;.onSearchRequested 
(Landroid/view/SearchEvent;)Z
02-17 21:31:57.873 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x72 at 
0x0002
02-17 21:31:57.877 1658-1658/? I/dalvikvm: Could not find method 
android.view.Window$Callback.onWindowStartingActionMode, referenced from 
method 
android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
02-17 21:31:57.877 1658-1658/? W/dalvikvm: VFY: unable to resolve interface 
method 15996: Landroid/view/Window$Callback;.onWindowStartingActionMode 
(Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
02-17 21:31:57.877 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x72 at 
0x0002
02-17 21:31:57.877 1658-1658/? I/dalvikvm: Could not find method 
android.content.res.TypedArray.getChangingConfigurations, referenced from 
method android.support.v7.widget.TintTypedArray.getChangingConfigurations
02-17 21:31:57.889 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 704: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
02-17 21:31:57.889 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0002
02-17 21:31:57.889 1658-1658/? I/dalvikvm: Could not find method 
android.content.res.TypedArray.getType, referenced from method 
android.support.v7.widget.TintTypedArray.getType
02-17 21:31:57.889 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 726: Landroid/content/res/TypedArray;.getType (I)I
02-17 21:31:57.889 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0008
02-17 21:31:57.889 1658-1658/? I/dalvikvm: Could not find method 
android.content.Context.createDeviceProtectedStorageContext, referenced from 
method 
android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext
02-17 21:31:57.889 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 485: Landroid/content/Context;.createDeviceProtectedStorageContext 
()Landroid/content/Context;
02-17 21:31:57.889 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0006
02-17 21:31:57.889 1658-1658/? I/dalvikvm: Could not find method 
android.content.Context.getCodeCacheDir, referenced from method 
android.support.v4.content.ContextCompat.getCodeCacheDir
02-17 21:31:57.889 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 491: Landroid/content/Context;.getCodeCacheDir ()Ljava/io/File;
02-17 21:31:57.889 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0006
02-17 21:31:57.889 1658-1658/? I/dalvikvm: Could not find method 
android.content.Context.getColor, referenced from method 
android.support.v4.content.ContextCompat.getColor
02-17 21:31:57.893 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 492: Landroid/content/Context;.getColor (I)I
02-17 21:31:57.893 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0006
02-17 21:31:57.893 1658-1658/? I/dalvikvm: Could not find method 
android.content.Context.getColorStateList, referenced from method 
android.support.v4.content.ContextCompat.getColorStateList
02-17 21:31:57.893 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 493: Landroid/content/Context;.getColorStateList 
(I)Landroid/content/res/ColorStateList;
02-17 21:31:57.893 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0006
02-17 21:31:57.893 1658-1658/? I/dalvikvm: Could not find method 
android.content.Context.getDataDir, referenced from method 
android.support.v4.content.ContextCompat.getDataDir
02-17 21:31:57.893 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 495: Landroid/content/Context;.getDataDir ()Ljava/io/File;
02-17 21:31:57.893 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0006
02-17 21:31:57.893 1658-1658/? I/dalvikvm: Could not find method 
android.content.Context.getDrawable, referenced from method 
android.support.v4.content.ContextCompat.getDrawable
02-17 21:31:57.893 1658-1658/? W/dalvikvm: VFY: unable to resolve virtual 
method 496: Landroid/content/Context;.getDrawable 
(I)Landroid/graphics/drawable/Drawable;
02-17 21:31:57.893 1658-1658/? D/dalvikvm: VFY: replacing opcode 0x6e at 
0x0006

可能有很多事情,例如:您忘记将活动添加到清单中。 但是我会继续猜测,你没有一个根布局,应该是这样的:

<?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"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="@drawable/androidparty" />


<TextView
android:text="Happy Birthday Mohamed"
android:layout_width="wrap_content"
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:id="@+id/textView2" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:layout_marginEnd="13dp"
android:layout_marginRight="13dp"
android:text="From,Abo Elmagd"
android:textSize="36sp"
android:textColor="@android:color/white"
android:id="@+id/textView" />
</RelativeLayout>


编辑您的问题以包括logcat。请参阅:该logcat与异常无关。试着找出由引起的单词
,抱歉,我不明白我应该做什么请任何人帮助我:(请不要猜测糟糕问题的答案。等待那些如何评论的人来询问正确的信息。问题有错误的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"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="@drawable/androidparty" />


<TextView
android:text="Happy Birthday Mohamed"
android:layout_width="wrap_content"
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:id="@+id/textView2" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:layout_marginEnd="13dp"
android:layout_marginRight="13dp"
android:text="From,Abo Elmagd"
android:textSize="36sp"
android:textColor="@android:color/white"
android:id="@+id/textView" />
</RelativeLayout>