I am trying to transfer data from one page to another, but some problem below is the code. I am trying to pass the value of a variable using a bundle from the first activity to the second, but something is wrong, please tell me what is going wrong.
below is the first activity: -
public class login extends Activity { /** Called when the activity is first created. */ Context mCtx; final static int START =0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mCtx = this; Button btn = (Button)findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener(){ // @Override public void onClick(View v) { String fromLat = new String(); String fromLong = new String(); String toLat = new String(); String toLong = new String(); fromLat = ((EditText)findViewById(R.id.FromLatitude)).getText().toString(); fromLong = ((EditText)findViewById(R.id.FromLongitude)).getText().toString(); toLat = ((EditText)findViewById(R.id.ToLatitude)).getText().toString(); toLong = ((EditText)findViewById(R.id.ToLongitude)).getText().toString(); Intent intent = new Intent(mCtx, MapRouteActivity.class); /*Sending some arguments*/ Bundle bundle = new Bundle(4); bundle.putString("fromLat",fromLat ); bundle.putString("fromLong",fromLong ); bundle.putString("toLat",toLat ); bundle.putString("toLong",toLong ); intent.putExtras(bundle); /*Start Activity*/ mCtx.startActivity(intent); /*Start ActivityForResult*/ ((Activity)mCtx).startActivityForResult(intent, 2); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(requestCode == START) { Toast.makeText(mCtx, Integer.toString(resultCode), Toast.LENGTH_SHORT).show(); } } @Override public void onDestroy(){ super.onDestroy(); finish(); } }
The second action is shown below: -
public class MapRouteActivity extends MapActivity { LinearLayout linearLayout; MapView mapView; private Road mRoad; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.routeplanning); mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Bundle extras = this.getIntent().getExtras(); String fLat=extras.getString("fromLat"); String fLong=extras.getString("fromLong"); String tLat=extras.getString("toLat"); String tLong=extras.getString("toLong"); final double fromLat=Double.parseDouble(fLat); final double fromLon=Double.parseDouble(fLong); final double toLat=Double.parseDouble(tLat); final double toLon=Double.parseDouble(tLong); new Thread() { @Override public void run() {
When the button is pressed, the application is forcibly closed.
The following are LogCat data for forcibly closing an application
02-02 15:32:31.837: ERROR/AndroidRuntime(199): Uncaught handler: thread main exiting due to uncaught exception 02-02 15:32:31.857: ERROR/AndroidRuntime(199): java.lang.NullPointerException 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at route.planning.login$1.onClick(login.java:49) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.View.performClick(View.java:2344) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.View.onTouchEvent(View.java:4133) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.widget.TextView.onTouchEvent(TextView.java:6504) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.View.dispatchTouchEvent(View.java:3672) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.app.Activity.dispatchTouchEvent(Activity.java:1987) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.os.Handler.dispatchMessage(Handler.java:99) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.os.Looper.loop(Looper.java:123) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at android.app.ActivityThread.main(ActivityThread.java:4203) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at java.lang.reflect.Method.invokeNative(Native Method) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at java.lang.reflect.Method.invoke(Method.java:521) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 02-02 15:32:31.857: ERROR/AndroidRuntime(199): at dalvik.system.NativeStart.main(Native Method)
android
Prachur
source share