不幸的是,应用程序已停止,我该如何解决?

时间:2019-09-15 12:03:46

标签: java android xml android-studio

我正在尝试在手机上运行我的第一个应用程序,但是当该应用程序安装在手机上时,它摇摇欲坠并显示此消息“ Humology has stoped”。

我试图清理并重建项目,但是没有用

这是我的 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:src="@drawable/prothese"
        android:scaleType="centerCrop"

        />

    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/imageView"
        android:layout_alignRight="@id/imageView"
        android:text="It is a part of you!"
        android:paddingRight="70sp"
        android:paddingBottom="30dp"
        android:textSize="35dp"
        android:textStyle="italic"
        android:fontFamily="sans-serif-light"
        android:textColor="#cae7e5"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/txt"

        android:layout_marginBottom="-13dp"
        android:fontFamily="sans-serif-light"
        android:paddingLeft="55sp"
        android:paddingBottom="55dp"
        android:text="HUMOLOGY"
        android:textColor="#fffdf0"
        android:textSize="55dp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/telephone"
        android:layout_below="@id/imageView"
        android:paddingTop="30dp"

        />
    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/fax"
        android:layout_below="@id/imageView2"
        android:paddingTop="30dp"
        />
    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/email"
        android:layout_below="@id/imageView3"
        android:paddingTop="30dp"
        />
    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/adress"
        android:layout_below="@id/imageView4"
        android:paddingTop="30dp"
        />

    <TextView
        android:id="@+id/txt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/txt"
        android:layout_marginTop="@id/imageView2"

        android:layout_marginBottom="-148dp"
        android:fontFamily="sans-serif-light"
        android:paddingLeft="70dp"
        android:text="+91 67 88 99 08 09"
        android:textColor="@android:color/black"
        android:textSize="25dp" />

    <TextView
        android:id="@+id/txt3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/txt"
        android:layout_marginTop="@id/imageView3"


        android:layout_marginBottom="-215dp"
        android:fontFamily="sans-serif-light"
        android:paddingLeft="70dp"
        android:text="+91 67 88 99 08 11"
        android:textColor="@android:color/black"
        android:textSize="25dp" />

    <TextView
        android:id="@+id/txt4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/txt"
        android:layout_marginTop="@id/imageView4"
        android:layout_marginBottom="-289dp"
        android:fontFamily="sans-serif-light"
        android:paddingLeft="70dp"
        android:text="humology@contact.com"
        android:textColor="@android:color/black"
        android:textSize="25dp" />

    <TextView
        android:id="@+id/txt5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/txt"
        android:layout_marginTop="@id/imageView5"


        android:layout_marginBottom="-356dp"
        android:fontFamily="sans-serif-light"
        android:paddingLeft="70dp"
        android:text="45,Marten GERARD street,NY "
        android:textColor="@android:color/black"
        android:textSize="25dp" />
</RelativeLayout>

MainActivity.java

package com.example.android.humology;

import androidx.appcompat.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);
    }
}

AndroidManifest.xml

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

    <dist:module dist:instant="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Logcat

2019-09-15 13:27:12.302 27005-27005/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2019-09-15 13:27:12.303 27005-27005/? E/libpersona: scanKnoxPersonas
2019-09-15 13:27:12.304 27005-27005/? E/libpersona: Couldn't open the File - /data/system/users/0/personalist.xml - No such file or directory
2019-09-15 13:27:13.652 27005-27005/com.example.android.humology E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.android.humology, PID: 27005
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.humology/com.example.android.humology.MainActivity}: android.view.InflateException: Binary XML file line #81: Can't convert value at index 4 to dimension: type=0x12
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2974)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7000)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
     Caused by: android.view.InflateException: Binary XML file line #81: Can't convert value at index 4 to dimension: type=0x12
     Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 4 to dimension: type=0x12
        at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:730)
        at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:8159)
        at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1269)
        at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:1090)
        at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:1088)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.example.android.humology.MainActivity.onCreate(MainActivity.java:12)
        at android.app.Activity.performCreate(Activity.java:7258)
        at android.app.Activity.performCreate(Activity.java:7249)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7000)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

所以我应该怎么做才能解决此错误,请帮忙!

3 个答案:

答案 0 :(得分:2)

android:layout_marginTop="@id/imageView5"替换为android:layout_marginTop="10dp"android:layout_marginBottom="-356dp看起来也很奇怪。

答案 1 :(得分:1)

<TextView>标签内,有一个名为 android:layout_marginTop。您已为View属性分配了layout_marginTop

您可以删除属性或将其替换为数值。我已在下面给出的代码中删除了该属性,该应用程序正在正常运行。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:src="@drawable/ic_launcher_background"
    android:scaleType="centerCrop"

    />

<TextView
    android:id="@+id/txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/imageView"
    android:layout_alignRight="@id/imageView"
    android:text="It is a part of you!"
    android:paddingRight="70sp"
    android:paddingBottom="30dp"
    android:textSize="35dp"
    android:textStyle="italic"
    android:fontFamily="sans-serif-light"
    android:textColor="#cae7e5"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/txt"

    android:layout_marginBottom="-13dp"
    android:fontFamily="sans-serif-light"
    android:paddingLeft="55sp"
    android:paddingBottom="55dp"
    android:text="HUMOLOGY"
    android:textColor="#fffdf0"
    android:textSize="55dp"
    android:textStyle="bold" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/ic_launcher_background"
    android:layout_below="@id/imageView"
    android:paddingTop="30dp"

    />
<ImageView
    android:id="@+id/imageView3"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/ic_launcher_background"
    android:layout_below="@id/imageView2"
    android:paddingTop="30dp"
    />
<ImageView
    android:id="@+id/imageView4"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/ic_launcher_background"
    android:layout_below="@id/imageView3"
    android:paddingTop="30dp"
    />
<ImageView
    android:id="@+id/imageView5"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/ic_launcher_background"
    android:layout_below="@id/imageView4"
    android:paddingTop="30dp"
    />

<TextView
    android:id="@+id/txt2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/txt"


    android:layout_marginBottom="-148dp"
    android:fontFamily="sans-serif-light"
    android:paddingLeft="70dp"
    android:text="+91 67 88 99 08 09"
    android:textColor="@android:color/black"
    android:textSize="25dp" />

<TextView
    android:id="@+id/txt3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/txt"



    android:layout_marginBottom="-215dp"
    android:fontFamily="sans-serif-light"
    android:paddingLeft="70dp"
    android:text="+91 67 88 99 08 11"
    android:textColor="@android:color/black"
    android:textSize="25dp" />

<TextView
    android:id="@+id/txt4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/txt"

    android:layout_marginBottom="-289dp"
    android:fontFamily="sans-serif-light"
    android:paddingLeft="70dp"
    android:text="humology@contact.com"
    android:textColor="@android:color/black"
    android:textSize="25dp" />

<TextView
    android:id="@+id/txt5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@id/txt"



    android:layout_marginBottom="-356dp"
    android:fontFamily="sans-serif-light"
    android:paddingLeft="70dp"
    android:text="45,Marten GERARD street,NY "
    android:textColor="@android:color/black"
    android:textSize="25dp" />
</RelativeLayout>

答案 2 :(得分:0)

<TextView内,您已将 View 分配为android:layout_marginTop的值,这会导致错误并导致应用崩溃。

用任何数值后跟 dp 替换@id/imageView5中的android:layout_marginTop="@id/imageView5"或删除该属性。

例如:android:layout_marginTop="50dp"