evertime i use this code it says theres a nullpointer exception
public boolean onTouchEvent(MotionEvent event)
{
if(event.getAction()==MotionEvent.ACTION_UP)
{
gotoWeb interwebs=new gotoWeb();
interwebs.go();
}
return true;
}
public class gotoWeb extends Activity
{
public void go()
{
Intent ins = new Intent(Intent.ACTION_VIEW);
ins.setData(Uri.parse("http://www.google.com"));
startActivity(ins);
}
}
I cant seem to figure out what i havent assigned im almost done with my project and this seems to be holding me back
You can’t just extend
Activity, construct it and then use it. Read up on the activity lifecycle to see how to properly create one. The reason you’re getting an NPE is that your Activity — which derives from Context — is calling startActivity() which is a Context method within a Context that hasn’t been initialized since you haven’t used the appropriate mechanism for creating your Activity.That said, I’m not sure why you’re trying to construct an Activity just to start another activity that launches the web browser. Why not create the Intent and start it from within your onTouchEvent()? I assume that touch handler exists within an Activity or something with a Context available.