import com.ave.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class Menu extends Activity{
ImageButton select;
int isClicked = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
select = (ImageButton)findViewById(R.id.select);
select.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isClicked == 0){
select.setImageResource(R.drawable.select_pressed);
isClicked = 1;
}
else{
select.setImageResource(R.drawable.select);
isClicked = 0;
}
}});
}
ImageButton audio;
int isClicked1 = 0;{
audio = (ImageButton)findViewById(R.id.audio);
audio.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (isClicked1 == 0){
audio.setImageResource(R.drawable.audio_pressed);
isClicked1 = 1;
}
else{
audio.setImageResource(R.drawable.audio);
isClicked1 = 0;
}
}
});
}
}
I'm not sure whats going wrong. There are no errors within the xml files or java class, however, when i go to test out the app via my phone or the AVD, after the splash screen it just randomly force closes.
LogCat
E AndroidRuntime: FATAL EXCEPTION: main
07-05 10:47:59.318 9362 9362 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ave/com.ave.Menu}: java.lang.NullPointerException
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1618)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.ActivityThread.access$1500(ActivityThread.java:124)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.os.Looper.loop(Looper.java:123)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:3806)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:507)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: Caused by: java.lang.NullPointerException
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.Activity.findViewById(Activity.java:1693)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at com.ave.Menu.<init>(Menu.java:41)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at java.lang.Class.newInstanceImpl(Native Method)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at java.lang.Class.newInstance(Class.java:1409)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1610)
07-05 10:47:59.318 9362 9362 E AndroidRuntime: ... 11 more
adb logcatprior to post question here.