2014-07-04 2 views
1

나는이 버튼이 눌려 졌을 때 버튼이 b1이고, 입력에서 숫자를 취하고 textfield에서 문자열 텍스트를 토스트하는 토스트가 호출되는 앱을 만들고자한다. 나는 logcat 아래에 약간의 오류가있다.왜 앱을 실행하는 중에 치명적인 오류가 발생합니까?

MainActivity.java

package com.x.losey;  
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 

import java.net.NetworkInterface; 

public class MainActivity extends Activity { 

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

    @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); 
     final Button b = (Button) (findViewById(R.id.Button2)); 
     final Button b1 = (Button) (findViewById(R.id.button)); 
     final EditText txt = (EditText) (findViewById(R.id.editText)); 
     final EditText num = (EditText) (findViewById(R.id.editText2)); 
     b.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       boolean a1 ; 
       Intent first = new Intent(MainActivity.this,second.class); 
       Toast.makeText(MainActivity.this, "OK" , Toast.LENGTH_SHORT).show(); 
       startActivity(first); 
      } 

     }); 
     b1.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       int i; 
       int n; 
       n = Integer.parseInt(String.valueOf(num)); 

       while(n!=0) { 
        String ab = txt.getText().toString(); 
        Toast.makeText(MainActivity.this, ab, Toast.LENGTH_SHORT).show(); 
        n--; 
       } 
       } 
      }); 
      return true; 
    } 

} 

activity_main.xml

버튼 = B1이 난 후, N을 대신 제거 할 때 난 토스트를 얻을 만 4 또는 2 번 클릭
<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:gravity="right" 
    android:orientation="vertical" 
    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=".MainActivity" > 

    <!--<TextView--> 
     <!--android:id="@+id/txtview1"--> 
     <!--android:layout_width="wrap_content"--> 
     <!--android:layout_height="wrap_content"--> 
     <!--android:layout_centerHorizontal="true"--> 
     <!--android:layout_gravity="top"--> 
     <!--android:text="@string/LoseY"--> 
     <!--android:textSize="25sp"--> 
     <!--android:textStyle="bold" />--> 

    <Button 
     android:id="@+id/Button2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/desbtn" 
     android:onClick="" 
     android:text="@string/btn1" 
     android:textColor="#FFFF" 
     android:textSize="50sp" 
     android:typeface="monospace" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/> 
    <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/editText" 

      android:layout_gravity="top" 
      android:hint="@string/enter" android:layout_alignRight="@+id/button" 
      android:layout_alignEnd="@+id/button" android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" android:height="50dp" android:textSize="28sp"/> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/Button2" 
     android:layout_alignLeft="@+id/Button2" 
     android:layout_alignParentEnd="true" 
     android:layout_marginBottom="40dp" 
     android:background="@drawable/desbtn" 
     android:fontFamily="@string/btn1" 
     android:gravity="center" 
     android:height="79dp" 
     android:text="@string/showMe" 
     android:textColor="#ffff9b80" 
     android:textSize="35sp" 
     android:textStyle="bold" /> 
    <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      android:ems="10" 
      android:hint="@string/input" 
      android:id="@+id/editText2" android:layout_below="@+id/editText" android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" android:layout_marginTop="46dp" 
      android:layout_alignRight="@+id/editText" android:layout_alignEnd="@+id/editText" 
      /> 

</RelativeLayout> 

값을 더한 다음 적절한 출력을 얻습니다.

그리고이 로그캣 오류 란 무엇입니까?

07-04 21:53:56.709 17773-17773/com.x.losey W/ResourceType﹕ No package identifier when getting value for resource number 0x0000005d 
07-04 21:53:56.710 17773-17773/com.x.losey D/AndroidRuntime﹕ Shutting down VM 
07-04 21:53:56.710 17773-17773/com.x.losey W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4165ed40) 
07-04 21:53:56.712 17773-17773/com.x.losey E/AndroidRuntime﹕ FATAL EXCEPTION: main 
Process: com.x.losey, PID: 17773 
android.content.res.Resources$NotFoundException: String resource ID #0x5d 
     at android.content.res.Resources.getText(Resources.java:244) 
     at android.widget.Toast.makeText(Toast.java:268) 
     at com.x.losey.MainActivity$2.onClick(MainActivity.java:65) 
     at android.view.View.performClick(View.java:4456) 
     at android.view.View$PerformClick.run(View.java:18462) 
     at android.os.Handler.handleCallback(Handler.java:733) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5102) 
     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) 
07-04 21:53:58.084 17773-17773/com.x.losey I/Process﹕ Sending signal. PID: 17773 SIG: 9 
07-04 21:53:59.709 18458-18458/com.x.losey I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:385>: EGL 1.4 QUALCOMM build: () 
OpenGL ES Shader Compiler Version: E031.24.00.01 
Build Date: 12/11/13 Wed 
Local Branch: 8226workspace 
Remote Branch: 
Local Patches: 
Reconstruct Branch: 
07-04 21:53:59.735 18458-18458/com.x.losey D/OpenGLRenderer﹕ Enabling debug mode 0 
07-04 21:53:59.844 18458-18458/com.x.losey E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
07-04 21:53:59.844 18458-18458/com.x.losey E/SpannableStringBuilder﹕ SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
07-04 22:00:06.784 18458-18458/com.x.losey W/ResourceType﹕ No package identifier when getting value for resource number 0x0000005d 
07-04 22:00:06.784 18458-18458/com.x.losey D/AndroidRuntime﹕ Shutting down VM 
07-04 22:00:06.784 18458-18458/com.x.losey W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4165ed40) 
07-04 22:00:06.788 18458-18458/com.x.losey E/AndroidRuntime﹕ FATAL EXCEPTION: main 
Process: com.x.losey, PID: 18458 
android.content.res.Resources$NotFoundException: String resource ID #0x5d 
     at android.content.res.Resources.getText(Resources.java:244) 
     at android.widget.Toast.makeText(Toast.java:268) 
     at com.x.losey.MainActivity$2.onClick(MainActivity.java:65) 
     at android.view.View.performClick(View.java:4456) 
     at android.view.View$PerformClick.run(View.java:18462) 
     at android.os.Handler.handleCallback(Handler.java:733) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:136) 
     at android.app.ActivityThread.main(ActivityThread.java:5102) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invo`enter code here`ke(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) 
07-04 22:00:08.438 18458-18458/com.x.losey I/Process﹕ Sending signal. PID: 18458 SIG: 9 
+0

로그 캣이이 활동 확신하는, 주어진 코드를 나누었다 String를 통과 .. 당신이 Toast.maketest하는 정수를 통과 것을 말하고있다 오류가 발생 했습니까? –

+0

예 .. 사용자가 inputText에 입력 한 값을 저장하는 방법을 알려주시겠습니까? – user3805750

+0

상점이란 무엇을 의미합니까? –

답변

-1

변경 MainActivity에에 :

private Button b; 
private Button b1; 
private EditText txt; 
private EditText num; 

public class MainActivity extends Activity { 

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

    b = (Button) findViewById(R.id.Button2); 
    b1 = (Button) findViewById(R.id.button); 
    txt = (EditText) findViewById(R.id.editText); 
    num = (EditText) findViewById(R.id.editText2); 

    b.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      boolean a1 ; 
      Intent first = new Intent(MainActivity.this,second.class); 

      Toast.makeText(MainActivity.this, "OK" , Toast.LENGTH_SHORT).show(); 

      startActivity(first); 

     } 


    }); 
    b1.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      int i; 
      int n; 
      n = Integer.parseInt(String.valueOf(num)); 

      while(n!=0) 
      { 
       String ab = txt.getText().toString(); 

       Toast.makeText(MainActivity.this, ab, Toast.LENGTH_SHORT).show(); 

       n--; 
      } 


      } 

     }); 
} 

@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; 

} 

} 
관련 문제