0

I am getting this error when i am inflating another activity on button click of first activity.I am also Passing the data between the activities.when the data is not being passed then it works fine and am able to view the second activity.the data i am passing is the content of text box from the first activity of integer type.Kindly lemme know where am i going wrong.

code for Activity1.class

public void onClick(View v)

    {

        try
        {
    Log.i("MyActivity", "Entered OnClick()");
    //Toast.makeText(getBaseContext(), "Entered", Toast.LENGTH_SHORT).show();
    int value;
    value=Integer.parseInt(range.getText().toString());
    Bundle bundle= new Bundle();
    bundle.putInt("param1",value);
//  Toast.makeText(getBaseContext(), "Wait", Toast.LENGTH_SHORT).show();
    Intent myIntent = new Intent(v.getContext(), RoutePath.class);
    myIntent.putExtras(bundle);
     startActivity(myIntent);
        }
         catch(Exception e)
            {e.printStackTrace();}
    }

and Activity2.class

public class RoutePath extends MapActivity {

GeoPoint gp1;

GeoPoint gp2;

GeoPoint srcGeoPoint;

GeoPoint destGeoPoint;

double distance;

int value=0;

public void onCreate(Bundle savedInstanceState)

{   



    super.onCreate(savedInstanceState);

    Bundle bundle = getIntent().getExtras();

    value = bundle.getInt("param1",0);

    setContentView(R.layout.main);

    MapView mapView = (MapView) findViewById(R.id.myMapView1);

    mapView.setBuiltInZoomControls(true);

//and then the other code.......

}

and the stack trace

03-21 15:44:39.276: WARN/System.err(3337): java.lang.NullPointerException
03-21 15:44:39.286: WARN/System.err(3337):     at com.nautilus.RoutePath.Welcome.onClick(Welcome.java:50)
03-21 15:44:39.306: WARN/System.err(3337):     at android.view.View.performClick(View.java:2364)
03-21 15:44:39.331: WARN/System.err(3337):     at android.view.View.onTouchEvent(View.java:4179)
03-21 15:44:39.335: WARN/System.err(3337):     at android.widget.TextView.onTouchEvent(TextView.java:6540)
03-21 15:44:39.348: WARN/System.err(3337):     at android.view.View.dispatchTouchEvent(View.java:3709)
03-21 15:44:39.355: WARN/System.err(3337):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-21 15:44:39.355: WARN/System.err(3337):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-21 15:44:39.385: WARN/System.err(3337):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-21 15:44:39.385: WARN/System.err(3337):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-21 15:44:39.385: WARN/System.err(3337):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
03-21 15:44:39.385: WARN/System.err(3337):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
03-21 15:44:39.385: WARN/System.err(3337):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
03-21 15:44:39.385: WARN/System.err(3337):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
03-21 15:44:39.385: WARN/System.err(3337):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
03-21 15:44:39.385: WARN/System.err(3337):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 15:44:39.385: WARN/System.err(3337):     at android.os.Looper.loop(Looper.java:123)
03-21 15:44:39.385: WARN/System.err(3337):     at android.app.ActivityThread.main(ActivityThread.java:4363)
03-21 15:44:39.385: WARN/System.err(3337):     at java.lang.reflect.Method.invokeNative(Native Method)
03-21 15:44:39.396: WARN/System.err(3337):     at java.lang.reflect.Method.invoke(Method.java:521)
4
  • On what line do you get an Exception? Or is it in platform code? Commented Mar 21, 2011 at 9:31
  • Ok for the stack trace, you need to show us the code inside RoutePath.Welcome Commented Mar 21, 2011 at 10:31
  • Just click on the line 2 of your stacktrace in LogCat and you'll find the error line in your code. Probably, it's value=Integer.parseInt(range.getText().toString()); where range is null? :) I wonder Commented Mar 21, 2011 at 10:40
  • see the update in my response Commented Mar 21, 2011 at 11:07

3 Answers 3

1

Some advices :

  • Read and provide a stack trace inside your question, it will be very helpfull.
  • Use this instead of v.getContext() in your Intent constructor
  • Integer.parseInt() will throw NumberFormatException if your variable range (which is an EditText I assume) returns a empty string, so maybe you should test the result of range.getText().toString().

EDIT :

  • Do you affect a value to the range variable ? Something like
    range = (EditText) findViewById(R.id.range)
Sign up to request clarification or add additional context in comments.

2 Comments

i did all the possible modifications that u suggested but it is nt wrkng...i am able to enter the onClick method ..it seems there is an error in the oncREATE METHOD OF SECOND ACTIVITY.
all ? So where is the stack trace ? :)
0

Maybe there's no view with id R.id.myMapView1 on R.layout.main layout. But what about providing a stack trace?

Comments

0

Instead of

int value;
value=Integer.parseInt(range.getText().toString());
Bundle bundle= new Bundle();
bundle.putInt("param1",value);
Intent myIntent = new Intent(v.getContext(), RoutePath.class);
myIntent.putExtras(bundle);

Try

int value;
value=Integer.parseInt(range.getText().toString());
Intent myIntent = new Intent(this, RoutePath.class);
myIntent.putExtra("param1",value);

3 Comments

Then you should provide a stack trace of the Exception you are getting.
its on the line whwre i retreive the value of editText n convert it into int value=Integer.parseInt(range.getText().toString());
Then put a breakpoint on that line, and see that range is null. So it must not be initialized properly ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.