마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 EditText에서 정수 넘겨받는거 질문드립니다. [closed]

0 추천

package com.example.practice;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	int number, rn_number=0;
	EditText edit_text;
	TextView result;
	Button button;
	String text_1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		rn_number=1+(int)(Math.random()*100);	//랜덤변수 생성
		edit_text = (EditText)findViewById(R.id.input_text);
		result = (TextView)findViewById(R.id.result_text);

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		findViewById(R.id.button).setOnClickListener(myButtonClick);
	}
	
	Button.OnClickListener myButtonClick = new Button.OnClickListener(){
		public void onClick(View v){
			text_1 = edit_text.getText().toString();
			number = Integer.parseInt(text_1);
			
			if(number == rn_number){
				result.setText("SUCCESS");
			}
			else
				result.setText("FAIL");
		}
	};
}
<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"
    tools:context="com.example.practice.MainActivity">

     <ImageView
         android:id="@+id/image"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_centerHorizontal="true"
         android:layout_centerVertical="true"
         android:src="@drawable/image" />

     <TextView
         android:id="@+id/text_1"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_above="@+id/image"
         android:layout_alignParentLeft="true"
         android:layout_marginBottom="17dp"
         android:gravity="center_horizontal"
         android:text="HIGH LOW"
         android:textSize="40sp" />

     <EditText
         android:id="@+id/input_text"
         android:layout_width="400px"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:layout_marginBottom="12dp"
         android:layout_marginLeft="41dp"
         android:ems="10"
         android:inputType="number" />


     <TextView
         android:id="@+id/result_text"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_below="@+id/image"
         android:layout_marginTop="7dp"
         android:ems="10"
         android:textSize="20sp" />


     <Button
         android:id="@+id/button"
         android:layout_width="400px"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_alignParentRight="true"
         android:layout_marginRight="40dp"
         android:text="Insert!" />

</RelativeLayout>

 

현제 하이로우 게임을 만들어 보고 있는데 EditText부분에서 정수를 입력하고

버튼을 눌러서 값을 받아오려고 하는데 계속 text_1 = edit_text.getText().toString();

이 부분에서 에러가 납니다;;

저로선 도저히 뭐가 에러인지 잘 모르겠습니다;;

어디서 잘못된걸까요??

질문을 종료한 이유: 해결되어서 종료를 합니다 ^_^
공대학개론 (200 포인트) 님이 2014년 10월 25일 질문
공대학개론님이 2014년 10월 25일 closed
...