안드로이드 질문!(간단한 편)

안드로이드 질문!(간단한 편)

작성일 2024.03.25댓글 1건
    게시물 수정 , 삭제는 로그인 필요

왜 오류가 계속 뜨는지 모르겠습니다... 분명히 책에는 이렇게 된다고 했는데, 오류만 떠서 질문합니다!


package com.cookandroid.my325;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

EditText edit1, edit2;
Button btnAdd, btnSub, btnMul, btnDiv;
TextView textResult;
String num1, num2;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.u);
setTitle("초간단 계산기");

edit1 = (EditText) findViewById(R.id.Edit1);
edit2 = (EditText) findViewById(R.id.Edit2);

btnAdd = (Button) findViewById(R.id.BtnAdd);
btnSub = (Button) findViewById(R.id.BtnSub);
btnMul = (Button) findViewById(R.id.BtnMul);
btnDiv = (Button) findViewById(R.id.BtnDiv);

textResult = (TextView) findViewById(R.id.TextResult);

btnAdd.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
num1 = edit1.getText().toString();
num2 = edit2.getText().toString();
RESULT_OK = Integer.parseInt(num1) + Integer.parseInt(num2);
textResult.setText("계산 결과 : " + RESULT_OK.toString());
return false;
}
});

btnSub.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
num1 = edit1.getText().toString();
num2 = edit2.getText().toString();
result = Integer.parseInt(num1) - Integer.parseInt(num2);
textResult.setText("계산 결과 : " + result.toString());
return false;
}
});

btnMul.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
num1 = edit1.getText().toString();
num2 = edit2.getText().toString();
result = Integer.parseInt(num1) * Integer.parseInt(num2);
textResult.setText("계산 결과 : " + result.toString());
return false;
}
});

btnDiv.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
num1 = edit1.getText().toString();
num2 = edit2.getText().toString();
result = Integer.parseInt(num1) / Integer.parseInt(num2);
textResult.setText("계산 결과 : " + result.toString());
return false;
}
});
}
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<EditText
android:id="@+id/Edit1"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="숫자1" />

<EditText
android:id="@+id/Edit2"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="숫자2" />

<Button
android:id="@+id/BtnAdd"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="더하기" />

<Button
android:id="@+id/BtnSub"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="빼기" />

<Button
android:id="@+id/BtnMul"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="곱하기" />
<Button
android:id="@+id/BtnDiv"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="나누기" />

<TextView
android:id="@+id/TextResult"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="계산 결과 : "
android:textColor="#FF0000"
android:textSize="30dp" />

</LinearLayout>








profile_image 익명 작성일 -

코드가 중간에 잘리셨네요. 다음 내용을 계속 적어주시면 도와드리겠습니다.

안드로이드 간단한 게임 개발하는데...

안드로이드 프로그래밍은 아예 공부 안된상태이고 자바는 잘 알고있는 전제 에서 네트워크 안쓰는 게임 만드는데 얼마나 걸리나요 안녕하세요. 질문에 답변드리도록...

안드로이드 개발이나 안드로이드...

... 안녕하세요 안드로이드에관련해서 여러가지 질문을 하셨는데요^^ 답변을 드리도록... 자체가 간단한 편이기 때문에 만들기에도 어려운 점은 없다고 생각 하실 수 있습니다...

안드로이드 앱을 개발하고 싶은데요.

... 지식은 안드로이드 스튜디오란 이름밖에 몰라요.... 생각했던 간단한 게임부터 구현해 보시면서 경험을... 일대일 질문, 쪽지, 댓글 등을 이용하시거나 제 지식in 프로필을...

안드로이드 프로그래밍

... 안녕하세요 질문 내용 잘 보았습니다. 안드로이드 분야 관심을 갖고 계시는 군요... 학원에서 배우시면 4~5개월에 간단한 어플개발이 가능한 수준이 되실겁니다. 이렇게...

안드로이드 마켓(빠른답변부탁해요!)

... 같아 간단한 답변 몇글자 적어 봅니다. 1) 안드로이드 마켓에 들어 가면 돈을 내나요?... 질문의 요점이 데이터 사용량 관련한 것으로 보여 그쪽에 초점을 맞춰 설명...