不幸的是app停止了 - 模拟器

时间:2015-03-12 17:54:09

标签: android

我对Android很新,并开始制作我自己的应用程序。我已经搜索过,但我还没有找到解决方案,所以我来到这里。我猜它的二进制XML文件行#17:错误膨胀类android.widget.Button错误。

我没有编译时错误。

主要

package com.example.sensational.timetopress;

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


public class Main_Screen extends ActionBarActivity {

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

    public void startTheGame(View view){
    Intent intent = new Intent(this, press_screen.class);
    startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main__screen, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

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=".Main_Screen"
    android:background="@drawable/background">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/time_to_press"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/start_button"
        android:layout_marginBottom="62dp"
        android:background="@drawable/start_button_code"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:onClick="startTheGame"/>

</RelativeLayout>

日志

3-12 12:59:29.742    1853-1853/com.example.sensational.timetopress I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-12 12:59:29.742    1853-1853/com.example.sensational.timetopress W/dalvikvm﹕ VFY: unable to resolve virtual method 387: Landroid/content/res/TypedArray;.getType (I)I
03-12 12:59:29.742    1853-1853/com.example.sensational.timetopress D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-12 12:59:29.754    1853-1853/com.example.sensational.timetopress D/dalvikvm﹕ GC_FOR_ALLOC freed 145K, 6% free 3686K/3904K, paused 3ms, total 3ms
03-12 12:59:29.770    1853-1853/com.example.sensational.timetopress I/dalvikvm-heap﹕ Grow heap (frag case) to 20.869MB for 18035652-byte allocation
03-12 12:59:29.774    1853-1862/com.example.sensational.timetopress D/dalvikvm﹕ GC_FOR_ALLOC freed 23K, 2% free 21275K/21520K, paused 3ms, total 3ms
03-12 12:59:29.878    1853-1853/com.example.sensational.timetopress I/dalvikvm﹕ threadid=1: stack overflow on call to Landroid/graphics/drawable/Drawable$ConstantState;.<init>:V
03-12 12:59:29.878    1853-1853/com.example.sensational.timetopress I/dalvikvm﹕ method requires 4+20+4=28 bytes, fp is 0x9ed65318 (24 left)
03-12 12:59:29.878    1853-1853/com.example.sensational.timetopress I/dalvikvm﹕ expanding stack end (0x9ed65300 to 0x9ed65000)
03-12 12:59:29.878    1853-1853/com.example.sensational.timetopress I/dalvikvm﹕ Shrank stack (to 0x9ed65300, curFrame is 0x9ed6a9f0)
03-12 12:59:29.878    1853-1853/com.example.sensational.timetopress D/AndroidRuntime﹕ Shutting down VM
03-12 12:59:29.878    1853-1853/com.example.sensational.timetopress W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4cd1b20)
03-12 12:59:29.882    1853-1853/com.example.sensational.timetopress E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.sensational.timetopress, PID: 1853
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sensational.timetopress/com.example.sensational.timetopress.Main_Screen}: android.view.InflateException: Binary XML file line #17: Error inflating class android.widget.Button
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.widget.Button
            at android.view.LayoutInflater.createView(LayoutInflater.java:620)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.example.sensational.timetopress.Main_Screen.onCreate(Main_Screen.java:16)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at com.example.sensational.timetopress.Main_Screen.onCreate(Main_Screen.java:16)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.StackOverflowError
            at android.graphics.drawable.DrawableContainer$DrawableContainerState.<init>(DrawableContainer.java:511)
            at android.graphics.drawable.StateListDrawable$StateListState.<init>(StateListDrawable.java:281)
            at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:327)
            at android.graphics.drawable.StateListDrawable.<init>(StateListDrawable.java:75)
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:898)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
            at android.content.res.Resources.loadDrawable(Resources.java:2092)
            at android.content.res.Resources.getDrawable(Resources.java:700)
            at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:176)
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
            at android.content.res.Resources.loadDrawable(Resources.java:2092)
            at android.content.res.Resources.getDrawable(Resources.java:700)
            at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:176)
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
            at android.content.res.Resources.loadDrawable(Resources.java:2092)
            at android.content.res.Resources.getDrawable(Resources.java:700)
            at android.graphics.drawable.StateListDrawable.inflate(StateList

start_button_code

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

    <item
    android:state_enabled="false"
    android:drawable="@drawable/start_button" />
    <item
        android:state_pressed="true"
        android:state_enabled="true"
        android:drawable="@drawable/start_button" />
    <item
        android:state_focused="true"
        android:state_enabled="true"
        android:drawable="@drawable/start_button" />
    <item
        android:state_enabled="true"
        android:drawable="@drawable/start_button" />

</selector>

1 个答案:

答案 0 :(得分:0)

<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" 
    android:background="@drawable/background"
tools:context=".Main_Screen">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/time_to_press"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/start_button"
        android:layout_marginBottom="62dp"
        android:layout_below="@id/imageView"
        android:text="My Button"

        android:layout_centerHorizontal="true"
        android:onClick="startTheGame"/>

</RelativeLayout>

将其粘贴到xml中然后尝试。让我知道你得到同样的错误。在运行之前再次检查您的drawable。确保它们是正确的。