问题
I have created a Thread in Android IDK why it says invalid return type!
All I want is to display the json
I get from Profile
I want to change the text in my fragment
Thread thread= new Thread(){
if (getActivity()!=null)
{
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Profile profile = service.getProfile(text);
Gson gson = new Gson();
String json = gson.toJson(profile);
output.setText(json.toString());
}
});
}
};
thread.start();
回答1:
Try this
new AsyncTask<Void, Void, Void> (){
private String json;
protected Void doInBackground(Void... voids) {
Profile profile = service.getProfile(text);
Gson gson = new Gson();
json = gson.toJson(profile);
return null;
}
protected void onPostExecute(Void result) {
output.setText(json);
}
}.execute();
来源:https://stackoverflow.com/questions/49987736/invalid-return-type-fragment-thread