0

I am getting java.lang.runtimeexception and java.lang.nullpointexception .Please help me with this piece of code.

package co.sds.iitr.bullsandcows;

import android.app.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

TextView P1Num;
EditText np1;
Button btok;
String n;
int Num;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    P1Num = (TextView) findViewById(R.id.tvNum1);
    np1 = (EditText) findViewById(R.id.etNum);
    btok = (Button) findViewById(R.id.btNext);


    btok.setOnClickListener(this);

}

@Override
public void onClick(View v) 
{
    // TODO Auto-generated method stub
    n = np1.getText().toString();
    Num = Integer.valueOf(n);


    Intent in = new Intent("co.sds.iitr.GUESSACTIVITY");
    in.putExtra("Num", Num);
    startActivity(in);

}

Log cat for this code http://imgur.com/CgMrFdC&JmHj5fk&iervlj8

6
  • 1
    did you add your GuessActivity to your Android Manifest? Commented Oct 12, 2013 at 8:43
  • Post your entire logerrors. Commented Oct 12, 2013 at 8:43
  • post GuessActivity onCreate code Commented Oct 12, 2013 at 8:44
  • Attaching your logcat as text inside your question will make it easier for other users to help you. Commented Oct 12, 2013 at 8:49
  • On what line are you getting the error? The stack trace will tell you this. Commented Oct 12, 2013 at 8:52

3 Answers 3

1

First of all, check whether your package name is co.sds.iitr.bullsandcows or co.sds.iitr

If your package name is co.sds.iitr.bullsandcows then change the following line

Intent in = new Intent("co.sds.iitr.GUESSACTIVITY");

to

Intent in = new Intent(this,co.sds.iitr.bullsandcows.GUESSACTIVITY.class);

else,

change the following line

Intent in = new Intent("co.sds.iitr.GUESSACTIVITY");

to

Intent in = new Intent(this,co.sds.iitr.GUESSACTIVITY.class);

in your code.

And also check whether you have declared your GUESSACTIVITY in your manifest.

And finally don't hardcode your class name in intent.

Sign up to request clarification or add additional context in comments.

Comments

0

You might forget to register your co.sds.iitr.GuessActivity in your manifest file and also make sure while starting activity directly explicitly specifying the name make sure for the case sensitivity of the activity name.

Comments

0

The problem seems to be inside GuessActivity code, which you need to post in your question. Anyway, you should consider starting a new intent like this.-

Intent in = new Intent(this, GuessActivity.class);

Hardcoding strings is always a source of errors.

Comments

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.