2013-05-05 1 views
0

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); 
    } 
} 

로그 캣 출력 : XML 파일

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 

: 당신의 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> 
+3

어디에서 충돌이 발생합니까? logcat을 게시하십시오. –

+0

방금 ​​게시 한 logcat을 추가했습니다. 게시하는 더 좋은 방법을 알지 못했습니다. – Urbanderivative

+0

XML 파일을 게시 할 수 있습니까? 뭔가 잘못된 것처럼 보입니다. 스택의 일부분은 '.xml extension required' –

답변

3

라인 :

android:textColor="@string/pickedrock" 

이 올바르지 않습니다 - 그것은 가리켜 야합니다 색상이 아닌 문자열.

+0

나는 색깔이 어떻게 거기에 있는지 알지 못한다. 고마워. – Urbanderivative

관련 문제