Beginner- Please help! getting an error!

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Beginner- Please help! getting an error!

Postby baumel7 » Mon Jul 25, 2011 9:22 pm

I am getting this error when trying to start my app in the emulator: Unable to start activity ComponentInfo{com.android.callonme/com.android.callonme.MainActivity}: java.lang.NullPointerException

This is my MainActivity.java class code:
package com.android.callonme;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


public class MainActivity extends Activity {
Button next;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button next = (Button) findViewById(R.id.contacts);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Contacts.class);
startActivityForResult(myIntent, 0);
}
});

}
}
Any help would be appreciated. I am obviously very new to this and kind of threw myself into it but am not great when it comes to problem solving this stuff. Thanks
baumel7
Freshman
Freshman
 
Posts: 5
Joined: Mon Jul 25, 2011 6:38 pm

Top

Re: Beginner- Please help! getting an error!

Postby techkanika » Mon Aug 08, 2011 3:11 pm

hi,

can you please share the exact error you are getting in logcat.. I want to the line number for exception.

kanika
Thanks
Kanika Rakheja
User avatar
techkanika
Experienced Developer
Experienced Developer
 
Posts: 83
Joined: Fri May 28, 2010 7:49 am

Re: Beginner- Please help! getting an error!

Postby eoJ » Tue Aug 09, 2011 11:41 am

A null pointer exception is where you are trying to use a variable or object, but it is null. We do need the line number really. Just from looking at your code it might be something to do with these lines, but I can't be sure.

setContentView(R.layout.main);

Button next = (Button) findViewById(R.id.contacts);
eoJ
Freshman
Freshman
 
Posts: 3
Joined: Thu Jul 28, 2011 9:45 am

Re: Beginner- Please help! getting an error!

Postby raj_J2ME » Tue Aug 16, 2011 12:28 pm

I suspect that view.getContext() is throwing the exception, you can put the Log or use the println statement or even you can check the logcat and check that on which line exactly the exception is occurring?
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 6 guests