안드로이드 개발 질문/답변
(글 수 45,052)
package com.claner;
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.ImageButton;
public class single extends Activity implements View.OnClickListener {
private ImageButton Rock, Paper, Scissors;
private media BGMplay; //BackgroundMusic Value
private int you;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.select_rps);
//BGMplay
BGMplay=new media(this);
BGMplay.PlaySoundTrack(this,0);
//Create ImageButton
Rock=(ImageButton)this.findViewById(R.drawable.rock_small);
Rock.setOnClickListener(this); ///<================이부분에서 에러
/*
Paper=(ImageButton)this.findViewById(R.drawable.paper_small);
Paper.setOnClickListener(this);
Scissors=(ImageButton)this.findViewById(R.drawable.scissors_small);
Scissors.setOnClickListener(this);*/
}
@Override
public void onClick(View v) {
if(v==Rock){
// you = Integer.parseInt(v.getTag().toString()); //you==1
}else if(v==Paper){
// you = Integer.parseInt(v.getTag().toString()); //you==0
}else if(v==Scissors){
// you = Integer.parseInt(v.getTag().toString()); //you==2
}
}//End of onClick
}//End of Class
02-03 10:37:42.767: ERROR/AndroidRuntime(402): FATAL EXCEPTION: main
02-03 10:37:42.767: ERROR/AndroidRuntime(402): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.claner/com.claner.single}: java.lang.NullPointerException
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.os.Looper.loop(Looper.java:123)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.app.ActivityThread.main(ActivityThread.java:3647)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at java.lang.reflect.Method.invoke(Method.java:507)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at dalvik.system.NativeStart.main(Native Method)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): Caused by: java.lang.NullPointerException
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at com.claner.single.onCreate(single.java:25)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
02-03 10:37:42.767: ERROR/AndroidRuntime(402): ... 11 more
A화면 -> B화면 -> C화면 (문제의 화면)
C 의 Activity 돌아가고 Click Listener 를 등록하는 부분에서 에러가 나는데 원인을 모르겠습니다.
this 말고 다른걸 설정해줘야 하나요?




변수 Rock에 이미지 버튼이 만들어지지 않는거 같네요..
Rock가 null인지 아닌지의 여부를 먼저 확인해보셔야 할것 같아요..