不幸的是(AppName)已停止在模拟器

时间:2016-01-28 14:14:44

标签: java android eclipse

我是Android开发的新手。我在这些论坛中搜索了这个问题。我的问题似乎来自不同的原因。

这是Log Cat

01-28 08:44:56.286: D/AndroidRuntime(1316): Shutting down VM
01-28 08:44:56.306: W/dalvikvm(1316): threadid=1: thread exiting with uncaught exception (group=0x41465730)
01-28 08:44:56.335: E/AndroidRuntime(1316): FATAL EXCEPTION: main
01-28 08:44:56.335: E/AndroidRuntime(1316): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.HJ.calculator/com.HJ.calculator.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.os.Looper.loop(Looper.java:137)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.ActivityThread.main(ActivityThread.java:5103)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at java.lang.reflect.Method.invokeNative(Native Method)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at java.lang.reflect.Method.invoke(Method.java:525)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at dalvik.system.NativeStart.main(Native Method)
01-28 08:44:56.335: E/AndroidRuntime(1316): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.Activity.setContentView(Activity.java:1895)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at com.HJ.calculator.MainActivity.onCreate(MainActivity.java:17)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.Activity.performCreate(Activity.java:5133)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-28 08:44:56.335: E/AndroidRuntime(1316):     ... 11 more
01-28 08:44:56.335: E/AndroidRuntime(1316): Caused by: java.lang.reflect.InvocationTargetException
01-28 08:44:56.335: E/AndroidRuntime(1316):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
01-28 08:44:56.335: E/AndroidRuntime(1316):     ... 26 more
01-28 08:44:56.335: E/AndroidRuntime(1316): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0b008c a=-1 r=0x7f0b008c}
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.content.res.Resources.loadDrawable(Resources.java:2068)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.View.<init>(View.java:3364)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.View.<init>(View.java:3293)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.view.ViewGroup.<init>(ViewGroup.java:453)
01-28 08:44:56.335: E/AndroidRuntime(1316):     at android.widget.RelativeLayout.<init>(RelativeLayout.java:242)
01-28 08:44:56.335: E/AndroidRuntime(1316):     ... 29 more

$

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

包的名称是com.HJ.calculator

问题是我尝试在eclipse中更改App主题。它在此之前有效,但在此之后,无论我改变什么主题,它都无法正常工作。我试着换成AppBaseTheme。但它仍然没用。 请帮助。

@Evjin             

中的十六进制代码指的是

public static final int AppTheme=0x7f0b008c;

此行位于我的应用程序中的R.java文件中。 在我的MainActivity.java中,我没有使用R.id在任何地方都可以使用Apptheme。

<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="@style/AppTheme"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.HJ.calculator.MainActivity" >




<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dp"
    android:text="Enter Two Values"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
    android:id="@+id/num1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="34dp"
    android:ems="10"
    android:hint="Enter a number"
    android:inputType="number|numberSigned|numberDecimal" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/add"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/num1"
    android:layout_below="@+id/num1"
    android:layout_marginTop="21dp"
    android:text="+" />

<Button
    android:id="@+id/sub"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/add"
    android:layout_alignBottom="@+id/add"
    android:layout_toRightOf="@+id/add"
    android:text="-" />

<Button
    android:id="@+id/mul"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/sub"
    android:layout_alignBottom="@+id/sub"
    android:layout_toRightOf="@+id/sub"
    android:text="X" />

<Button
    android:id="@+id/div"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/mul"
    android:layout_alignBottom="@+id/mul"
    android:layout_toRightOf="@+id/mul"
    android:text="/" />

<EditText
    android:id="@+id/num2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/sub"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:ems="10"
    android:hint="Enter Another Number"
    android:inputType="number|numberSigned|numberDecimal" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/num2"
    android:layout_marginTop="72dp"
    android:layout_toLeftOf="@+id/num2"
    android:text="Ans:"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
    android:id="@+id/dis"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2"
    android:layout_alignBottom="@+id/textView2"
    android:layout_alignLeft="@+id/textView1"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/mul"
    android:layout_below="@+id/dis"
    android:layout_marginTop="30dp"
    android:text="By:Harsha"
    android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

这是xml文件。

这是MainActivity.java

package com.HJ.calculator;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.*;



public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button add=(Button)findViewById(R.id.add);
    Button subtract=(Button)findViewById(R.id.sub);
    Button multiply=(Button)findViewById(R.id.mul);
    Button divide=(Button)findViewById(R.id.div);

    add.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            EditText num1=(EditText)findViewById(R.id.num1);
            EditText num2=(EditText)findViewById(R.id.num2);
            TextView ans=(TextView)findViewById(R.id.dis);
            String s1=(num1.getText()).toString();
            String s2=(num2.getText()).toString();
            if(s1.compareTo("")==0||s2.compareTo("")==0)
            {
                ans.setText("Enter Everything!");
            }
            else
            {
                double n1=Double.parseDouble(s1);
                double n2=Double.parseDouble(s2);
                double n3=n1+n2;
                ans.setText(n3+"");

            }
        }
    });
    subtract.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            EditText num1=(EditText)findViewById(R.id.num1);
            EditText num2=(EditText)findViewById(R.id.num2);
            TextView ans=(TextView)findViewById(R.id.dis);
            String s1=(num1.getText()).toString();
            String s2=(num2.getText()).toString();
            if(s1.compareTo("")==0||s2.compareTo("")==0)
            {
                ans.setText("Enter Everything!");
            }
            else
            {
                double n1=Double.parseDouble(s1);
                double n2=Double.parseDouble(s2);
                double n3=n1-n2;
                ans.setText(n3+"");

            }
        }
    });
    multiply.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            EditText num1=(EditText)findViewById(R.id.num1);
            EditText num2=(EditText)findViewById(R.id.num2);
            TextView ans=(TextView)findViewById(R.id.dis);
            String s1=(num1.getText()).toString();
            String s2=(num2.getText()).toString();
            if(s1.compareTo("")==0||s2.compareTo("")==0)
            {
                ans.setText("Enter Everything!");
            }
            else
            {
                double n1=Double.parseDouble(s1);
                double n2=Double.parseDouble(s2);
                double n3=n1*n2;
                ans.setText(n3+"");

            }
        }
    });
    divide.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            EditText num1=(EditText)findViewById(R.id.num1);
            EditText num2=(EditText)findViewById(R.id.num2);
            TextView ans=(TextView)findViewById(R.id.dis);
            String s1=(num1.getText()).toString();
            String s2=(num2.getText()).toString();
            if(s1.compareTo("")==0||s2.compareTo("")==0)
            {
                ans.setText("Enter Everything!");
            }
            else
            {
                double n1=Double.parseDouble(s1);
                double n2=Double.parseDouble(s2);
                if(n2==0.0)
                {
                    ans.setText("Divide By Zero!");
                }
                else
                {
                    double n3=n1/n2;
                    ans.setText(n3+"");
                }
            }
        }
    });
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, 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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

1 个答案:

答案 0 :(得分:0)

Exception

android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0b008c a=-1 r=0x7f0b008c}

通常在尝试通过其R.id设置某些内容时触发,但是您要发送另一个未绑定到资源的整数。

修改

正如@kha在评论中提到的,属性android:background期望integer id绑定到可绘制颜色资源,而不是主题。

例如,如果要将其设置为黑色,则可以添加此项:

android:background="@android:color/black"