Stack Exchange
nullpointer exception while starting another activity
When I called another activity using intent it gives a nullpointer exception.
intent
public void ShowEvent(View view){
        Intent intent = new Intent(this, Getclicker.class);
         date = (TextView)findViewById(R.id.textView2);
        String datevalue = date.getText().toString();
        userSelection=(TextView)findViewById(R.id.textView1);
        String Userselectvalue = userSelection.getText().toString();

        intent.putExtra(EXTRA_MESSAGE, datevalue);
        intent.putExtra(EXTRA_MESSAGE1, Userselectvalue);

        startActivity(intent);
    }


Getclicker.java

package example.events1;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.widget.ListView;

public class Getclicker  extends ListActivity {

    classdbOpenHelper eventsData1;
    Cursor cursor1;
     ListView listView ; 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();
        String datevalue = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE);
        String Userselectvalue = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE1);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);                       


         cursor1 = eventsData1.getContact(datevalue,Userselectvalue);
         String[] fromColumns = {classdbOpenHelper.KEY_EVENT};
         int[] toViews = {R.id.event};
         SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.events, cursor1, fromColumns, toViews,0 );
          listView = getListView(); 
         listView.setAdapter(adapter);
        }

    public void onDestroy() {
        eventsData1.close();
      }
}


logcat

08-07 11:52:54.445: E/Trace(2926): error opening trace file: No such file or directory (2)
08-07 11:52:58.564: E/AndroidRuntime(2926): FATAL EXCEPTION: main
08-07 11:52:58.564: E/AndroidRuntime(2926): java.lang.RuntimeException: Unable to start activity ComponentInfo{example.events1/example.events1.Getclicker}: java.lang.NullPointerException
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.os.Looper.loop(Looper.java:137)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at java.lang.reflect.Method.invokeNative(Native Method)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at java.lang.reflect.Method.invoke(Method.java:511)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at dalvik.system.NativeStart.main(Native Method)
08-07 11:52:58.564: E/AndroidRuntime(2926): Caused by: java.lang.NullPointerException
08-07 11:52:58.564: E/AndroidRuntime(2926):     at example.events1.Getclicker.onCreate(Getclicker.java:28)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.Activity.performCreate(Activity.java:5104)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-07 11:52:58.564: E/AndroidRuntime(2926):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-07 11:52:58.564: E/AndroidRuntime(2926):     ... 11 more


possible duplicate of Nullpointer exception when starting another activity

paste your logcat. And "when i called another activity using intent it gives a nullpointer exception." once is enough.

Depends on the LogCat, but you could have not declared the Activity in the Manifest.

i checked that.cleared. but again comes

Your object eventsData1 has never been initialized, so it's null and when you try to use it, it throws an exception.

How are you accessing FirstActivity.EXTRA_MESSAGE? I don't see the import.

use 'getcontext' function to reterive the activity context and use like this 'context.startActivity(intent);'

I don't see where you're initializing eventsData1 and you're using it at:
cursor1 = eventsData1.getContact(datevalue,Userselectvalue);

That can cause a null pointer exception.

you can try this way, because static value should be getting null in Getclicker Activty. So use as a key.
    intent.putExtra("EXTRA_MESSAGE", datevalue);
    intent.putExtra("EXTRA_MESSAGE1", Userselectvalue);

and get the value this way
@Override
    public void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();
        String datevalue = intent.getStringExtra("EXTRA_MESSAGE");
        String Userselectvalue = intent.getStringExtra("EXTRA_MESSAGE1");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);


Firstly you should create the activity layout--
setContentView() first then get the values
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);  
    Intent intent = getIntent();
    String datevalue = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE);
    String Userselectvalue = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE1);

Also initialize eventsData1 in your code, it can have null values.
