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

时间:2018-02-17 21:40:33

标签: android

我制作一个应用程序“生日卡片”,其中包含图像视图和两个文本视图,我在Genymotion模拟器上运行此消息并显示消息

  

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

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

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

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

1 个答案:

答案 0 :(得分:-1)

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

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