I have 2 activity screens. The 1st one has 2 buttons. Button1 processes the data based from the user inputs while Button2 leads the user to the next activity screen based from the result of the process.
Whenever I click Button1, nothing happens, and
when i click Button2, the app stops working and gives the "Unfortunately..." message. At first, everything is going well but then I added a few codes then the app won't run.
MainActivity
public class MainActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    //for the header
        View title = getWindow().findViewById(android.R.id.title);
        if (title != null)
        { 
            ViewParent titleBar = title.getParent();
            if (titleBar != null && (titleBar instanceof View))
            { 
                View parentView = (View)titleBar; 
                parentView.setBackgroundColor(Color.RED); 
            }
        }
    //for button2
        Button next = (Button) findViewById(R.id.DGButton);
        next.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view)
            {
                Intent myIntent = new Intent(view.getContext(), Activity2.class);
                startActivityForResult(myIntent, 0);
            }
        });
    } 
    public void calculateClickHandler(View view)
    {
        //handle the click of button1
        if (view.getId() == R.id.CalculateButton)
        {
         //some codes
    //the next activity screen uses the calculated value for some outputs
         Intent intent1 = new Intent(MainActivity.this, Activity2.class);
        Bundle b = new Bundle();
        b.putDouble("key", bmiValue);
        intent1.putExtras(b);
        startActivityForResult(intent1,0);
    }
    }
Activity2:
public class Activity2 extends Activity
{ 
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Button next = (Button) findViewById(R.id.BackToBMI);
        next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            }
        });
//some codes
        Bundle b = getIntent().getExtras(); //the nullpointerexception is here
        double bmival = b.getDouble("key");
}
}
Logcat:
12-27 05:15:03.263: E/AndroidRuntime(1091): FATAL EXCEPTION: main
12-27 05:15:03.263: E/AndroidRuntime(1091): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bmicaldg/com.example.bmicaldg.Activity2}: java.lang.NullPointerException
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.os.Looper.loop(Looper.java:137)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.ActivityThread.main(ActivityThread.java:5039)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at java.lang.reflect.Method.invokeNative(Native Method)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at java.lang.reflect.Method.invoke(Method.java:511)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at dalvik.system.NativeStart.main(Native Method)
12-27 05:15:03.263: E/AndroidRuntime(1091): Caused by: java.lang.NullPointerException
12-27 05:15:03.263: E/AndroidRuntime(1091):     at com.example.bmicaldg.Activity2.onCreate(Activity2.java:33)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.Activity.performCreate(Activity.java:5104)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-27 05:15:03.263: E/AndroidRuntime(1091):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-27 05:15:03.263: E/AndroidRuntime(1091):     ... 11 more
And also this is the XML file for the MainActivity:
Button1:
<Button
        android:id="@+id/CalculateButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView4"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="14dp"
        android:background="#FF0000"
        android:minHeight="30dip"
        android:minWidth="65dip"
        android:onClick="calculateClickHandler"
        android:text="@string/CalculateButton"
        android:textColor="#FFFFFF"
        android:textSize="14sp" />
Button2:
<Button
        android:id="@+id/DGButton"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="#FF0000"
        android:minHeight="30dip"
        android:onClick="calculateClickHandler"
        android:text="@string/DGButton"
        android:textColor="#FFFFFF" />
I'm a beginner in Android Mobile programming so any help would be appreciated.
 
     
     
     
     
     
     
    