Answer the question
In order to leave comments, you need to log in
The variable does not save the value, I feel that I am stupid and it should not work, poke your nose why?
I learned the basics for a long time, now I'm trying to go back and write something, a lot has been forgotten and I don't understand why it doesn't work.
pseudo code:
.....
private class ParseTask extends AsyncTask<Context, Void, String>
{ ......
String resJson = "";
.......
boolean doSomethingAndExtractTo(String jsonAsString) // try to open a conn.
{
....
jsonAsString = mutableString.toString();
.....
}
@Override
protected String doInBackground(Context... params)
{ .....
doSomethingAndExtractTo(resJson);
.....
}
}
Answer the question
In order to leave comments, you need to log in
In Java, all objects are references passed as values. jsonAsString = mutableString.toString();
will make the local jsonAsString variable refer to the new string. Nothing will happen to the original string.
Let the method return a value
String doSomethingAndExtractTo(String jsonAsString){
return mutableString.toString();
}
public static void main(String[] args){
resJson = "TextGoesHere";
resJson = doSomethingAndExtractTo(resJson);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question