• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
All of the following truths are shameless lies. But what about this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic