简体   繁体   English

Android无法启动活动组件

[英]Android Unable to start activity Component

First time posting here, just made an account to do so after using Stackoverflow for over a year. 第一次在这里发布,是在使用Stackoverflow一年以上之后才做的。 I've been trying to get my simple app to work for over an hour now. 我一直在尝试让我的简单应用程序运行一个多小时。 I see no errors in the java on either activity and have no idea what to look for in the log. 我在这两个活动中的Java中均未看到任何错误,也不知道在日志中查找什么。 I've run out of options and thought I would try here before rewriting it so if it happens in the future, I'll be able to fix it. 我已经用完所有选项,并认为我会在重写它之前先在这里进行尝试,因此,如果将来发生这种情况,我将可以对其进行修复。

The log is this 日志是这个

11-02 21:03:37.535  19010-19010/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: net.androidbootcamp.celticsongsapp, PID: 19010
    java.lang.RuntimeException: Unable to start activity ComponentInfo{net.androidbootcamp.celticsongsapp/net.androidbootcamp.celticsongsapp.SplashActivity}: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
            at android.app.ActivityThread.access$800(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5431)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
     Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
            at android.view.LayoutInflater.createView(LayoutInflater.java:633)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3743)
            at com.android.internal.policy.impl.PhoneWindowEx.generateLayout(PhoneWindowEx.java:22)
            at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3815)
            at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1996)
            at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
            at net.androidbootcamp.celticsongsapp.SplashActivity.onCreate(SplashActivity.java:16)
            at android.app.Activity.performCreate(Activity.java:6056)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
            at android.app.ActivityThread.access$800(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5431)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3743)
            at com.android.internal.policy.impl.PhoneWindowEx.generateLayout(PhoneWindowEx.java:22)
            at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3815)
            at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1996)
            at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
            at net.androidbootcamp.celticsongsapp.SplashActivity.onCreate(SplashActivity.java:16)
            at android.app.Activity.performCreate(Activity.java:6056)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
            at android.app.ActivityThread.access$800(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5431)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
     Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 13
            at android.content.res.TypedArray.getDrawable(TypedArray.java:747)
            at android.view.View.<init>(View.java:3748)
            at android.view.ViewGroup.<init>(ViewGroup.java:498)
            at android.widget.FrameLayout.<init>(FrameLayout.java:115)
            at android.widget.FrameLayout.<init>(FrameLayout.java:111)
            at android.widget.FrameLayout.<init>(FrameLayout.java:107)
            at com.android.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:60)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
            at android.view.LayoutInflater.createView(LayoutInflater.java:607)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3743)
            at com.android.internal.policy.impl.PhoneWindowEx.generateLayout(PhoneWindowEx.java:22)
            at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3815)
            at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1996)
            at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
            at net.androidbootcamp.celticsongsapp.SplashActivity.onCreate(SplashActivity.java:16)
            at android.app.Activity.performCreate(Activity.java:6056)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
            at android.app.ActivityThread.access$800(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5431)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)

I hope I'm not doing this wrong, but I really am kind of frustrated 我希望我没有做错这个,但是我真的很沮丧

Asked to include .xml and .class files 要求包含.xml和.class文件

The class for the SplashActivity SplashActivity的类

package net.androidbootcamp.celticsongsapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                finish();
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
            }
        };
        Timer opening = new Timer( );
        opening.schedule(task,4000);
    }
}

And this is the XML 这是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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".SplashActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/txtCeltic"
        android:id="@+id/txtTitle"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/celtic"
        android:textSize="26sp"
        android:gravity="center|bottom"
        android:textColor="#000000"
        android:textStyle="bold" />
</RelativeLayout>

This is happening while trying to inflate an ActionBarContainer to your activity. 尝试在您的活动中添加ActionBarContainer时发生这种情况。
Because it's a splash, I don't think you want an action bar. 因为这是飞溅,所以我认为您不需要操作栏。 The solution below assumes that. 下面的解决方案假定。


Without looking at your layout XML, mainly because it's a Splash activity and it should be trivial, I think your problem occurs because of the theme you applied to the activity . 在不查看布局XML的情况下,主要是因为它是一个Splash活动,并且它应该是微不足道的,我认为您的问题是由于您应用于该活动主题而发生

To fix it, add a specific theme for the Splash activity in your manifest . 要解决此问题,请在清单中为Splash活动添加特定的主题。

<activity
    android:name=".view.ActivitySplash"
    android:label="@string/app_name"
    android:theme="@style/MyTheme" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

And, create a theme (in this example, called MyTheme in your styles.xml . 然后,创建一个主题(在本示例中,在您的styles.xml中称为MyTheme

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar" />

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

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