我使用asynctask从json中捕获一个字符串。我想将catched string发送到另一个类来插入数据库。
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();
}
}
我创建了一个新类来保存字符串。但我失败了
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;
}
}
我用这段代码调用字符串
String translatedWord = trWord.getTrWord();
我在哪里做错了?
答案 0 :(得分:0)
public class TranslatedWord {
private static String trWord;
public String getTrWord() {
return trWord;
}
public void setTrWord(String trWord) {
this.trWord = trWord;
}
}
我刚做了变量static。它的运行。