0

There are two intents on the receiver side which are called from the same activity and are sending data to different activities. The second intent is not working. First one does. I cannot figure out why. All the activities and the manifest seems to be correct.

//second intent on senders side    
        public void onItemSelected(AdapterView<?> arg0, View users, int i,
                        long l) {
                    FILENAME = (adapter.getItem(i)).toString();

            Bundle viewBag2 = new Bundle();
                        viewBag2.putString("profile_name", FILENAME);
                        Intent b = new Intent(OptionsMenu.this, CoreActivity.class);
                        b.putExtras(viewBag2);  
                        startActivity(b);
              }


    //second intent on receiver side

        private void Data_transfer() {
        Bundle gotbasket2 = getIntent().getExtras();
                profileName = gotbasket2.getString("profile_name");
        }

    //first (working intent) on senders side
        public void onClick(View v) {
                    Bundle viewBag = new Bundle();
                    viewBag.putString("spinner_result", s);
    a.putExtras(viewBag);
    }



    //first (working intent) on receiver side
        private void Data_transfer() {
            // TODO Auto-generated method stub
            Bundle gotbasket = getIntent().getExtras();
            x = gotbasket.getString("spinner_result");
    }

Below is the logcat attached.

 06-26 20:22:09.787: D/AndroidRuntime(1802): Shutting down VM
    06-26 20:22:09.787: W/dalvikvm(1802): threadid=1: thread exiting with uncaught exception (group=0x40015560)
    06-26 20:22:09.847: E/AndroidRuntime(1802): FATAL EXCEPTION: main
    06-26 20:22:09.847: E/AndroidRuntime(1802): java.lang.RuntimeException: Unable to start activity ComponentInfo{mioc.diver/mioc.diver.CoreActivity}: java.lang.NullPointerException
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.os.Handler.dispatchMessage(Handler.java:99)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.os.Looper.loop(Looper.java:123)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.app.ActivityThread.main(ActivityThread.java:3683)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at java.lang.reflect.Method.invokeNative(Native Method)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at java.lang.reflect.Method.invoke(Method.java:507)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at dalvik.system.NativeStart.main(Native Method)
    06-26 20:22:09.847: E/AndroidRuntime(1802): Caused by: java.lang.NullPointerException
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at mioc.diver.CoreActivity.Data_transfer(CoreActivity.java:189)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at mioc.diver.CoreActivity.onCreate(CoreActivity.java:88)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    06-26 20:22:09.847: E/AndroidRuntime(1802):     ... 11 more
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1480742
  • 145
  • 12
  • 2
    Hi, and welcome to SO. Please always describe the problem and, if it's a crash, include the stack trace. "Not working" tells us nothing. – Simon Jun 26 '12 at 20:01
  • Tnx, i'm also new in eclipse...can you tell me where to see(open) stack trace – user1480742 Jun 26 '12 at 20:19
  • @user1480742: follow this question to get your logcat and post it here for us to debug your code. http://stackoverflow.com/questions/3280051/how-to-enable-logcat-console-in-eclipse-for-android – gsb Jun 26 '12 at 21:01
  • Check line numbers 189 and 88 in your CoreActivity.java file. There is a null pointer exception generating from either of these 2 lines. – gsb Jun 26 '12 at 21:33

1 Answers1

1

First of all, you don't need to create a new bundle every time you want to put an extra into the intent. You can just do:

Intent b = new Intent(OptionsMenu.this, CoreActivity.class);
b.putExtra(key, value);

Secondly, you shouldn't start method name with an upper-case letter, as mentioned in the Google Java Style Guide.

Finally, it seems you're getting a NullPointerException in Data_transfer() which means that you have a null variable at line 189 of your Activity (probably FILENAME).

Mark Nemec
  • 119
  • 1
  • 2
  • 12