简体   繁体   English

是什么导致我的应用在按下按钮时崩溃?

[英]What is causing my app to crash on button press?

My manifest: 我的清单:

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

On the Launch screen (FirstScreen): 在启动屏幕(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: 我的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();
        }
    });
}

}

When I tap the ImageButton ( btn_start ) It crashes and says "Unfortunately, Video Game Historium has stopped" It doesn't seem to want to load the next screen. 当我点击ImageButtonbtn_start )时,它崩溃并显示“不幸的是,Video Game Historium已停止”,它似乎不想加载下一个屏幕。 I looked in Logcat (which keeps going and going and never stopping) it's spitting out a few red errors: 我看着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 }

just to name a few. 仅举几个。 Any ideas? 有任何想法吗? It was working until I took the screen from one project and imported it into this one. 直到我从一个项目中获取屏幕并将其导入到这个项目中之前,它一直在工作。 I imported the xml, java and drawables. 我导入了xml,java和drawables。

Edit: Added Crash Report: 编辑:添加了崩溃报告:

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

This is the important part here. 这是这里的重要部分。 So, check your themes.xml and set ` 因此,检查您的themes.xml并设置`

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

Alternatively, you should be able to use as parent 或者,您应该可以作为parent使用

parent="Theme.AppCompat.Light.NoActionBar"

and it should work. 它应该工作。

Solved my issue. 解决了我的问题。 I had to change the order of my themes.xml around a little and add 我不得不稍微更改一下themes.xml的顺序并添加

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

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

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