Issue
I catch a string from json with asynctask. I would like send catched string to another class to insert database.
TranslatedWord trWord=new TranslatedWord();
@Override
protected void onPostExecute(JSONObject json) {
try {
JSONArray result = json.getJSONArray(TAG_RESULTS);
String text = result.getString(0); //Catched string here
trWord.setTranslatedWord(text);
} catch (JSONException e) {
e.printStackTrace();
}
}
I created a new class to keep string. But I failed
public class TranslatedWord {
private String trWord;
public void setTranslatedWord(String trWord) {
this.trWord = trWord;
}
public String getTrWord() {
return trWord;
}
public void setTrWord(String trWord) {
this.trWord = trWord;
}
}
I call string with this code
String translatedWord = trWord.getTrWord();
Where am I doing wrong?
Solution
public class TranslatedWord {
private static String trWord;
public String getTrWord() {
return trWord;
}
public void setTrWord(String trWord) {
this.trWord = trWord;
}
}
I just made variable static. Its run.
Answered By - Erman Elmalı
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.