• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using putstring extra in card view and get string extra in intent  RSS feed

 
Adejumo Tobi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been having this problem for 3 weeks now concerning this app. Let me be as brief as possible.
I have 5 activities, ActivityA, ActivityB, ActivityC, ActivityD and ActivityE.
ActivityA contains my `CardView`s (5 cards), I put a String extra in ActivityA. Below is a snippet of my code on how my String extra for each cards in ActivityA should behave when they are called. I have initially set a final integer(querystring) in ActivityA in my `onBindViewHolder` to enable me call each cards;

TheViewHolder.imagee.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (queryString == R.drawable.cardviewone) {
Intent intenting = new Intent(getApplicationContext(), ActivityB.class);
String one = "yesone";
intenting.putExtra("Fiveold", one);
startActivity(intenting);
} else if (queryString == R.drawable.cardviewtwo) {
Intent intenting = new Intent(getApplicationContext(), ActivityB.class);
String two = "yestwo";
intenting.putExtra("Fivenew", two);
startActivity(intenting);
} else if (queryString == R.drawable.cardviewdthree) {
Intent intenting = new Intent(getApplicationContext(), ActivityB.class);
String three = "yesthree";
intenting.putExtra("Seven", three);
startActivity(intenting);
} else if (queryString == R.drawable.cardviewfour) {
Intent intenting = new Intent(getApplicationContext(), ActivityB.class);
String four = "yesfour";
intenting.putExtra("Seven", four);
startActivity(intenting);
} else if (queryString == R.drawable.cardviewfive) {
Intent intenting = new Intent(getApplicationContext(), ActivityB.class);
String five = "yesfive";
intenting.putExtra("America", five);
startActivity(intenting);
} else {
Toast.makeText(getBaseContext(), "Application Runtime", Toast.LENGTH_SHORT).show();
}
}
});

The code above is working well. Now to ActivityB

ActivityB is made up of 2 `TextView`s and a `Button`.
below is my snippet
In my `onCreate` method here

Intent intent = getIntent();
String sms = intent.getStringExtra("Fiveold").toString();
String smss =intent.getStringExtra("Fivenew").toString();

Though both are field variables in my full code. Now to the `setOnClickListener` of the `Button`.


if (sms.equals("yesone")) {
Log.d("Readme", "Your message is " + sms);
if (typedText.getText().equals("Talk")) {
Intent intent = new Intent(ActivityB.this, ActivityC.class);
startActivity(intent);
} else if (typedText.getText().equals("Write")) {
Intent intent = new Intent(ActivityB.this, ActivityD.class);
startActivity(intent)
}
}
else if (smss.equals("yestwo")) {
Intent intent = new Intent(ActivityB.this, ActivityE.class);
startActivity(intent);
}

Sorry this is taking too long, Now this code works well without the

String smss =intent.getStringExtra("Fivenew").toString();

When I insert the String smss in the else if statement, the code fails and points to that line! I tried changing my `getApplicationContext()` in ActivityA to ActivityA.this but it was showing an error so I couldn't proceed with getting the Strings from the other cards in ActivityA!
WOULD BE GLAD IF YOU CAN HELP.


This is my logcat
My logcat talks about a null point exception error at the point I earlier discussed
 
Tim Moores
Saloon Keeper
Posts: 3958
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're setting either "Fiveold" or "Fivenew", but the code assumes that both are set. You need to check for null before invoking the toString method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!