Jordan Iatro
Jordan Iatro

Reputation: 297

Using Intent.putextra

String sRow = SignIn.getRow(email);             
Intent intent = new Intent(SignIn.this,HomePage.class);
                intent.putExtra("rowID", sRow);
                startActivity(intent);

This code is in my SignIn activity and I want to pass the String value sRow to the HomePage class.

Bundle extras = getIntent().getExtras();
    String rowID = extras.getString("rowID");

from my HomePage class, I use this to call the value of sRow and assign it to rowID. Am I doing it correctly? Because I received and error which calling to HomePage.class;

Logcat:

10-27 02:55:19.040: D/dalvikvm(1722): Not late-enabling CheckJNI (already on)

10-27 02:55:19.380: D/(1722): HostConnection::get() New Host Connection established 0xb96340e0, tid 1722

10-27 02:55:19.650: W/EGL_emulation(1722): eglSurfaceAttrib not implemented

10-27 02:55:19.780: D/OpenGLRenderer(1722): Enabling debug mode 0

10-27 02:55:19.800: D/dalvikvm(1722): GC_CONCURRENT freed 131K, 8% free 3092K/3348K, paused 1ms+1ms, total 4ms

10-27 02:55:52.960: W/EGL_emulation(1722): eglSurfaceAttrib not implemented

10-27 02:56:00.141: W/EGL_emulation(1722): eglSurfaceAttrib not implemented

10-27 02:56:00.181: D/AndroidRuntime(1722): Shutting down VM

10-27 02:56:00.181: W/dalvikvm(1722): threadid=1: thread exiting with uncaught exception (group=0xb0cacb20)

10-27 02:56:00.181: E/AndroidRuntime(1722): FATAL EXCEPTION: main

10-27 02:56:00.181: E/AndroidRuntime(1722): Process: com.example.packageit, PID: 1722

10-27 02:56:00.181: E/AndroidRuntime(1722): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.packageit/com.example.packageit.HomePage}: java.lang.NullPointerException

10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)

10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.os.Handler.dispatchMessage(Handler.java:102)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.os.Looper.loop(Looper.java:136)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.app.ActivityThread.main(ActivityThread.java:5017)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at java.lang.reflect.Method.invokeNative(Native Method)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at java.lang.reflect.Method.invoke(Method.java:515)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at dalvik.system.NativeStart.main(Native Method)
10-27 02:56:00.181: E/AndroidRuntime(1722): Caused by: java.lang.NullPointerException
10-27 02:56:00.181: E/AndroidRuntime(1722):     at com.example.packageit.HomePage.<init>(HomePage.java:14)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at java.lang.Class.newInstanceImpl(Native Method)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at java.lang.Class.newInstance(Class.java:1208)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-27 02:56:00.181: E/AndroidRuntime(1722):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
10-27 02:56:00.181: E/AndroidRuntime(1722):     ... 11 more

Upvotes: 0

Views: 156

Answers (3)

Aparupa Ghoshal
Aparupa Ghoshal

Reputation: 309

While obtaining the rowID in HomePage class , do as follows :

Intent intent = getIntent();
String rowID = intent.getStringExtra("rowID");

Hope this would work absolutely fine.

Also do check the manifest to confirm whether HomePage.class has been registered.

Upvotes: 0

Biraj Zalavadia
Biraj Zalavadia

Reputation: 28484

You did a very small mistake.

you put string extra to intent directly not in bundle. And while you retrieving you use Bundle.

So simply write this way.

String rowID = getIntent().getStringExtra("rowID");

Upvotes: 1

PLP
PLP

Reputation: 714

Try this help you

HomePage class:

Intent intent = getIntent();
Bundle extras = intent.getExtras();
String rowID = extras.getString("rowID");

Upvotes: 0

Related Questions