Hi I'm trying to start a new activity by setting up a ontouchlistener on the whole screen. However, when I click on the screen in the android emulator I get an instantiation problem with with the ComponentInfo specifically a nullpointerexception. Could my problem be that I removed the saveinstantstate==null from my second class
public class LoadScreen extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_screen);
View view=(FrameLayout) findViewById(R.id.container);
view.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
startActivity(new Intent(v.getContext(),SignUp.class));
return true;
}
});
}
}
public class SignUp extends Activity {
public Button signup=(Button) findViewById(R.id.CompleteRegistration);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
signup.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(v.getContext(),MainActivity.class));
}
});
}
}
07-23 01:42:26.200: E/AndroidRuntime(1138): FATAL EXCEPTION: main
07-23 01:42:26.200: E/AndroidRuntime(1138): Process: com.example.demoww, PID: 1138
07-23 01:42:26.200: E/AndroidRuntime(1138): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.demoww/com.example.demoww.SignUp}: java.lang.NullPointerException
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.os.Handler.dispatchMessage(Handler.java:102)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.os.Looper.loop(Looper.java:136)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-23 01:42:26.200: E/AndroidRuntime(1138): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 01:42:26.200: E/AndroidRuntime(1138): at java.lang.reflect.Method.invoke(Method.java:515)
07-23 01:42:26.200: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-23 01:42:26.200: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-23 01:42:26.200: E/AndroidRuntime(1138): at dalvik.system.NativeStart.main(Native Method)
07-23 01:42:26.200: E/AndroidRuntime(1138): Caused by: java.lang.NullPointerException
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.Activity.findViewById(Activity.java:1884)
07-23 01:42:26.200: E/AndroidRuntime(1138): at com.example.demoww.SignUp.<init>(SignUp.java:15)
07-23 01:42:26.200: E/AndroidRuntime(1138): at java.lang.Class.newInstanceImpl(Native Method)
07-23 01:42:26.200: E/AndroidRuntime(1138): at java.lang.Class.newInstance(Class.java:1208)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
07-23 01:42:26.200: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
07-23 01:42:26.200: E/AndroidRuntime(1138): ... 11 more
You should move this code
Button signup=(Button) findViewById(R.id.CompleteRegistration);
under onCreate(..)
after setContentView(R.layout.activity_sign_up);
in your SignUp Activity
public class SignUp extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
Button signup=(Button) findViewById(R.id.CompleteRegistration);
signup.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
startActivity(new Intent(v.getContext(),MainActivity.class));
}
});
}
}