0

In my activity I have sharedReview.setPhoneNumberofUserFromDB(obj.getString("username"));

It sets the value to a string from my DB and then I get that value in my adapter for use in my recyclerView, which is working ok.

In my activity how can I convert sharedReview.setPhoneNumberofUserFromDB(obj.getString("username")); to a string?

I've tried the below but it doesn't work:

String userNameAsString= String.valueOf(sharedReview.setPhoneNumberofUserFromDB(obj.getString("username")));

and

String phoneNoonPhone = (sharedReview.setPhoneNumberofUserFromDB(obj.getString("username")).toString());

It tells me the method toString can't be resolved and Cannot resolve method valueOf(void);

CHarris
  • 2,693
  • 8
  • 45
  • 71
  • 1
    Whats the return type of `sharedReview.setPhoneNumberofUserFromDB()` ? If it returns void, which would make sense for setter method, than I do not see what is the endgame here... Even if you could find a way to achieve that you'll always get the same value... – Gotiasits May 05 '18 at 10:03
  • The end game is I have another setter, `sharedReview.setNameFromPhone()`, which is a name in phone contacts. I have all `names` and `numbers` in phone contacts as a `json array` So if the phone number in contacts equals `sharedReview.setPhoneNumberofUserFromDB()` then I want to grab the matching name and set it to `sharedReview.setNameFromPhone()` which will come up in my recyclerView. – CHarris May 05 '18 at 10:20

1 Answers1

3

A long shot:

String phoneNoonPhone = obj.getString("username");
sharedReview.setPhoneNumberofUserFromDB(phoneNoonPhone);

In general setters return void (nothing), so you don't actually get something to assign to a variable from the return. Getters do return something. Generally for every void setFoo(Type t) there would be a Type getFoo(). In your case I'd expect a String getPhoneNumberofUserFromDB().

M. le Rutte
  • 3,525
  • 3
  • 18
  • 31