-3

i am sending the values to pag2.java as follows

Intent myIntent = new Intent(getApplicationContext(), page2.class);
        intent.putExtra("pos", list1);
        intent.putExtra("back1", "back");
        startActivity(myIntent);

And recieving in page2 as

Intent intent = getIntent();
        pos = intent.getStringExtra("pos");

I am getting the following error:

FATAL EXCEPTION: main
Process: com.example.namrathasrinivas.karnatakatemples, PID: 4410
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.namrathasrinivas.karnatakatemples/com.example.namrathasrinivas.karnatakatemples.page2}: java.lang.NullPointerException: println needs a message
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException: println needs a message
        at android.util.Log.println_native(Native Method)
        at android.util.Log.d(Log.java:139)
        at com.example.namrathasrinivas.karnatakatemples.page2.onCreate(page2.java:41)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)

      
daemmie
  • 6,361
  • 3
  • 29
  • 45
namratha
  • 652
  • 2
  • 13
  • 29

2 Answers2

0

Use this:

Bundle bundle = getIntent().getExtras();
    String str =  bundle.getString("pos");
Gaurav
  • 3,615
  • 2
  • 27
  • 50
0

First of all, try this way because you might have error in transferring the data between activities (it has something to do with savedInstanceState)

Bundle extras = getIntent().getExtras();
if (extras != null) String pos = extras.getString("pos");

If this still does not work ok, then you might have problems with your manifest. Have you declared your receiving activity in the proper way?

cvetanov
  • 363
  • 1
  • 3
  • 12