无法启动活动组件信息java.lang.RuntimeException:

时间:2018-11-13 14:01:21

标签: android android-studio

我正在尝试开发一个Android应用程序。具有java.lang.RuntimeException。我已经在描述和XML文件中创建了Java类代码。我已将活动设置为在运行中显示,但显示为不幸的是,App已关闭。这可能是什么问题?

我的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"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/welcome">

    <ImageView
        android:id="@+id/app_logo"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="60dp"
        android:src="@drawable/ntuuma_logo"
        android:contentDescription="@string/todo" />

    <TextView
        android:id="@+id/app_slogan"
        android:layout_width="220dp"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginEnd="88dp"
        android:layout_marginTop="140dp"
        android:text="@string/find_discover_products_a_z"
        android:textAlignment="center"
        android:textColor="@color/colorPrimary"
        android:textSize="22sp"
        android:textStyle="bold|italic"
        />
    <Button
        android:id="@+id/main_login_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@drawable/buttons"
        android:padding="20dp"
        android:textAllCaps="false"
        android:textSize="18sp"
        android:text="@string/already_have_an_account_login"
        android:textColor="@android:color/white"/>
    <Button
        android:id="@+id/main_join_now_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/main_login_btn"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@drawable/input_design"
        android:padding="20dp"
        android:textAllCaps="false"
        android:textSize="18sp"
        android:text="@string/join_now"
        android:textColor="@android:color/white"/>
</RelativeLayout>

我的Java文件

import android.app.Activity;
import android.os.Bundle;

   public class second_Activity extends Activity {
      @Override
     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
           setContentView(R.layout.register_activity);
   }
}

我的LogCat

11-13 17:15:59.329 15336-15336/com.ntuumadistributors.ntuuma E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ntuumadistributors.ntuuma, PID: 15336
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ntuumadistributors.ntuuma/com.ntuumadistributors.ntuuma.second_Activity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
    at android.app.Activity.setContentView(Activity.java:2166)
    at com.ntuumadistributors.ntuuma.second_Activity.onCreate(second_Activity.java:10)
    at android.app.Activity.performCreate(Activity.java:6237)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
    at android.view.LayoutInflater.createView(LayoutInflater.java:645)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
    at android.app.Activity.setContentView(Activity.java:2166) 
    at com.ntuumadistributors.ntuuma.second_Activity.onCreate(second_Activity.java:10) 
    at android.app.Activity.performCreate(Activity.java:6237) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance(Native Method)
    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
    at android.app.Activity.setContentView(Activity.java:2166) 
    at com.ntuumadistributors.ntuuma.second_Activity.onCreate(second_Activity.java:10) 
    at android.app.Activity.performCreate(Activity.java:6237) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
 Caused by: android.content.res.Resources$NotFoundException: Resource "com.ntuumadistributors.ntuuma:drawable/welcome" (7f0700b4) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0700b4 a=-1 r=0x7f0700b4}
    at android.content.res.Resources.loadDrawableForCookie(Resources.java:2602)
    at android.content.res.Resources.loadDrawable(Resources.java:2540)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
    at android.view.View.<init>(View.java:3948)
    at android.view.ViewGroup.<init>(ViewGroup.java:573)
    at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
    at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
    at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
    at java.lang.reflect.Constructor.newInstance(Native Method) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
    at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
    at android.app.Activity.setContentView(Activity.java:2166) 
    at com.ntuumadistributors.ntuuma.second_Activity.onCreate(second_Activity.java:10) 
    at android.app.Activity.performCreate(Activity.java:6237) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

2 个答案:

答案 0 :(得分:0)

将可绘制图像放在错误的文件夹中时,会发生此问题。例如在drawable-v24中,因此它在API <21上崩溃。

检查welcome图像是否存在于可绘制文件夹中,而不包含任何图像(v-24或v-26)

您可以将welcome粘贴到drawable中,而无需使用任何api版本来解决该问题。

右键单击welcome,然后单击“在文件夹中显示”(在Linux中为文件),然后将其复制并转到上一个文件夹并找到drawable并将其粘贴。

答案 1 :(得分:0)

logcat上有一条有趣的行

Caused by: android.content.res.Resources$NotFoundException: Resource "com.ntuumadistributors.ntuuma:drawable/welcome" (7f0700b4) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0700b4 a=-1 r=0x7f0700b4}

因此@drawable/welcome可能不是可绘制资源,或者根本不存在或类似资源。

如果您确信这不是您的错,请从菜单(File->Invalidate Caches / Restart)中执行使缓存无效并重新启动