Java 无法让我的应用程序运行。只是撞车

Java 无法让我的应用程序运行。只是撞车,java,android,Java,Android,我正在努力学习构建Android应用程序。这是我第一次尝试。一切都很好,当我参加这个活动时(有人会选择摇滚),我可以让它显示Hello World。我试图制定输赢规则,但每当我选择摇滚时,我的应用程序就会崩溃。请看一看 package ro.pa.sc; import java.util.Random; import android.annotation.TargetApi; import android.app.Activity; import android.os.Build; impo

我正在努力学习构建Android应用程序。这是我第一次尝试。一切都很好,当我参加这个活动时(有人会选择摇滚),我可以让它显示Hello World。我试图制定输赢规则,但每当我选择摇滚时,我的应用程序就会崩溃。请看一看

package ro.pa.sc;

import java.util.Random;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class Rockvs extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        randombox();
        setContentView(R.layout.activity_rockvs);
        // Show the Up button in the action bar.
        setupActionBar();
    }

    /**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setupActionBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-         vs-back
            //
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public  void randombox()
    {
        Random r = new Random();
        int pickedNumber=r.nextInt(2);

        if (pickedNumber==1) {
            win();
        } else if (pickedNumber==2) {
            lose();
        } else if (pickedNumber==0){
            tie();
        }

    }

    public void win() {
        String message = "Computer picked Scissors! You Won!";

        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);

        setContentView(textView);

    }

    public void lose() {

        String message = "Computer picked Paper! You Lose!";

        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);

        setContentView(textView);
    }

    public void tie() {
        String message = "Computer picked Rock! It's a Tie!";

        TextView textView = new TextView(this);
        textView.setTextSize(40);
        textView.setText(message);

        setContentView(textView);
    }
}
Logcat输出:

05-05 19:22:46.571: D/ActivityThread(15646): setTargetHeapUtilization:0.25
05-05 19:22:46.571: D/ActivityThread(15646): setTargetHeapIdealFree:8388608
05-05 19:22:46.581: D/ActivityThread(15646): setTargetHeapConcurrentStart:2097152
05-05 19:22:46.722: I/Adreno200-EGL(15646): <qeglDrvAPI_eglInitialize:269>: EGL 1.4 QUALCOMM build:  (CL2803123)
05-05 19:22:46.722: I/Adreno200-EGL(15646): Build Date: 11/28/12 Wed
05-05 19:22:46.722: I/Adreno200-EGL(15646): Local Branch: D1L_JB_1736J_Disable_CPUMempool
05-05 19:22:46.722: I/Adreno200-EGL(15646): Remote Branch: 
05-05 19:22:46.722: I/Adreno200-EGL(15646): Local Patches: 
05-05 19:22:46.722: I/Adreno200-EGL(15646): Reconstruct Branch: 
05-05 19:22:48.233: W/dalvikvm(15646): threadid=1: thread exiting with uncaught exception (group=0x4126c438)
05-05 19:22:48.253: E/AndroidRuntime(15646): FATAL EXCEPTION: main
05-05 19:22:48.253: E/AndroidRuntime(15646): java.lang.RuntimeException: Unable to start activity ComponentInfo{ro.pa.sc/ro.pa.sc.Rockvs}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2080)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.ActivityThread.access$600(ActivityThread.java:137)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.os.Looper.loop(Looper.java:137)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.ActivityThread.main(ActivityThread.java:4904)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at dalvik.system.NativeStart.main(Native Method)
05-05 19:22:48.253: E/AndroidRuntime(15646): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:321)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.Activity.setContentView(Activity.java:2087)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at ro.pa.sc.Rockvs.onCreate(Rockvs.java:20)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.Activity.performCreate(Activity.java:5232)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044)
05-05 19:22:48.253: E/AndroidRuntime(15646):    ... 11 more
05-05 19:22:48.253: E/AndroidRuntime(15646): Caused by: java.lang.reflect.InvocationTargetException
05-05 19:22:48.253: E/AndroidRuntime(15646):    at java.lang.reflect.Constructor.constructNative(Native Method)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-05 19:22:48.253: E/AndroidRuntime(15646):    ... 24 more
05-05 19:22:48.253: E/AndroidRuntime(15646): Caused by: android.content.res.Resources$NotFoundException: File You picked Rock! I hope you win! from drawable resource ID #0x7f050009: .xml extension required
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.content.res.Resources.loadColorStateList(Resources.java:2094)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.widget.TextView.<init>(TextView.java:820)
05-05 19:22:48.253: E/AndroidRuntime(15646):    at android.widget.TextView.<init>(TextView.java:489)
05-05 19:22:48.253: E/AndroidRuntime(15646):    ... 27 more
05-05 19:22:46.571:D/ActivityThread(15646):设置目标应用程序利用率:0.25
05-05 19:22:46.571:D/ActivityThread(15646):SetTargetTheApidealFree:8388608
05-05 19:22:46.581:D/ActivityThread(15646):设置目标APCONcurrentStart:2097152
05-05 19:22:46.722:I/Adreno200 EGL(15646)::EGL 1.4高通公司构建:(CL2803123)
05-05 19:22:46.722:I/Adreno200 EGL(15646):建造日期:2012年11月28日星期三
05-05 19:22:46.722:I/Adreno200 EGL(15646):本地分支:D1L_JB_1736; u Disable_CPUMempool
05-05 19:22:46.722:I/Adreno200 EGL(15646):远程分支:
05-05 19:22:46.722:I/Adreno200 EGL(15646):局部斑块:
05-05 19:22:46.722:I/Adreno200 EGL(15646):重建分支:
05-05 19:22:48.233:W/dalvikvm(15646):threadid=1:线程退出时出现未捕获异常(组=0x4126c438)
05-05 19:22:48.253:E/AndroidRuntime(15646):致命异常:主
05-05 19:22:48.253:E/AndroidRuntime(15646):java.lang.RuntimeException:无法启动活动组件信息{ro.pa.sc/ro.pa.sc.Rockvs}:android.view.InflateException:二进制XML文件行#11:膨胀类时出错
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2080)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.app.ActivityThread.access$600(ActivityThread.java:137)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.os.Handler.dispatchMessage(Handler.java:99)上
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.os.Looper.loop(Looper.java:137)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于android.app.ActivityThread.main(ActivityThread.java:4904)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于java.lang.reflect.Method.Invokenactive(本机方法)
05-05 19:22:48.253:E/AndroidRuntime(15646):在java.lang.reflect.Method.invoke(Method.java:511)
05-05 19:22:48.253:E/AndroidRuntime(15646):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
05-05 19:22:48.253:E/AndroidRuntime(15646):在dalvik.system.NativeStart.main(本机方法)
05-05 19:22:48.253:E/AndroidRuntime(15646):由以下原因引起:android.view.InflateException:二进制XML文件行#11:膨胀类时出错
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于com.android.internal.policy.impl.PhoneLayoutFlater.onCreateView(PhoneLayoutFlater.java:56)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:321)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于android.app.Activity.setContentView(Activity.java:2087)
05-05 19:22:48.253:E/AndroidRuntime(15646):在ro.pa.sc.Rockvs.onCreate(Rockvs.java:20)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.app.Activity.performCreate(Activity.java:5232)上
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044)
05-05 19:22:48.253:E/AndroidRuntime(15646):。。。还有11个
05-05 19:22:48.253:E/AndroidRuntime(15646):由以下原因引起:java.lang.reflect.InvocationTargetException
05-05 19:22:48.253:E/AndroidRuntime(15646):位于java.lang.reflect.Constructor.constructNative(本机方法)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-05 19:22:48.253:E/AndroidRuntime(15646):。。。还有24个
05-05 19:22:48.253:E/AndroidRuntime(15646):原因:android.content.res.Resources$NotFoundException:您选择的文件Rock!我希望你赢!来自可提取资源ID#0x7f050009:。需要xml扩展名
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.content.res.Resources.loadColorStateList(Resources.java:2094)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
05-05 19:22:48.253:E/AndroidRuntime(15646):位于android.widget.TextView。(TextView.java:820)
05-05 19:22:48.253:E/AndroidRuntime(15646):在android.widget.TextView。(TextView.java:489)
05-05 19:22:48.253:E/AndroidRuntime(15646):。。。还有27个
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: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=".Rockvs" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/pickedrock"
        android:textColor="@string/pickedrock"
        android:textSize="25sp" />

</RelativeLayout>

在XML中,行:

android:textColor="@string/pickedrock"
不正确-它应该指向颜色资源,而不是字符串

在XML中,行: