什么导致我的应用程序按下按钮时崩溃?

时间:2014-11-18 16:15:00

标签: android

我的清单:

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

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.rufflez.pagertabstriplistview.pagertabstriplistview.FirstScreen"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.Base">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

在“启动”屏幕(FirstScreen)上:

<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:background="@drawable/bg">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img_logo"
    android:src="@drawable/logo2"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<ImageView
    android:visibility="invisible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img_title"
    android:layout_centerVertical="false"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="230dp"
    />

<TextView
    android:visibility="visible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/desc"
    android:id="@+id/description"
    android:textColor="#ffffffff"
    android:textSize="24dp"
    android:typeface="sans"
    android:gravity="center"
    android:layout_marginTop="375dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:textStyle="italic" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btn_start"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/start"
    android:background="@null"
    android:layout_marginBottom="16dp" />


</RelativeLayout>

My FirstScreen.java:

package com.rufflez.pagertabstriplistview.pagertabstriplistview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;


public class FirstScreen extends Activity {

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

}
private void setupMessageButton() {
    //1. Get reference to button
    ImageButton messageButton = (ImageButton) findViewById(R.id.btn_start);

    //2. Set the click listener to run code.
    messageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("DemoButtonApp", "Clicked Begin");
            startActivity(new Intent(FirstScreen.this, MainActivity.class));
            finish();
        }
    });
}

}

当我点按ImageButtonbtn_start)它崩溃并说“不幸的是,Video Game Historium已停止”它似乎不想加载下一个屏幕。我查看了Logcat(它继续前进并且永不停止)它正在吐出一些红色错误:

EnterpriseContainerManager﹕ ContainerPolicy Service is not yet ready!!!
E/SMD﹕ DCD ON  
CameraController﹕ handleMessage signal: 0  
CameraController﹕ handleMessage(0) before let go!{ when=-506ms what=0 target=com.sec.android.smartface.CameraController$EventHandler }

仅举几例。有任何想法吗?它一直在工作,直到我从一个项目中取出屏幕并将其导入到这个项目中。我导入了xml,java和drawables。

编辑:添加了崩溃报告:

11-18 10:04:47.683    9690-9690/com.rufflez.pagertabstriplistview.pagertabstriplistview
E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.rufflez.pagertabstriplistview.pagertabstriplistview, PID: 9690
java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.rufflez.pagertabstriplistview.pagertabstriplistview/com.rufflez.pagertabstriplistview.pagertabstriplistview.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.

2 个答案:

答案 0 :(得分:1)

This Activity already has an action bar supplied by the window decor. 
Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme 
to use a Toolbar instead

这是这里的重要部分。所以,检查你的themes.xml并设置`

<item name="windowActionBar">false</item>

或者,您应该可以使用parent

parent="Theme.AppCompat.Light.NoActionBar"

它应该有用。

答案 1 :(得分:0)

解决了我的问题。我不得不稍微改变我的themes.xml的顺序并添加

<item name="windowActionBar">false</item>