简体   繁体   English

应用程序因简单的 XML 布局而崩溃

[英]App crashing with simple XML layout

I Make An App "Birthday card" That Contains a Image View and two Text Views And I Run this on Genymotion Emulator And The Message Appear我制作了一个应用程序“生日贺卡”,其中包含一个图像视图和两个文本视图,然后在 Genymotion 模拟器上运行它,消息出现

"Unfortunately,Happy Birthday has stopped." “很遗憾,生日快乐已经停止了。”

1-ActivityMain.xml 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>

2- MainActivity.java 2- MainActivity.java

package com.example.android.happybirthday;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

} }

3- logcat 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

Might be many things, for example: you forgot to add your activity to the manifest.可能有很多事情,例如:您忘记将您的活动添加到清单中。 But I am going to go ahead and guess that you dont have a root layout which should be something like this:但是我将继续猜测您没有根布局应该是这样的:

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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