String json_string;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void getJSON (View view){
new BackgroundTask().execute();
}
class BackgroundTask extends AsyncTask <Void, Void, String>{
String json_url;
@Override
protected void onPreExecute() {
json_url = "http://androidtut.comli.com/json_get_data.php";
}
@Override
protected Void doInBackground(Void... voids) {
try {
URL url = new URL(json_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
while ((json_string = bufferedReader.readLine()) != null) {
stringBuilder.append(json_string + "\n");
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return stringBuilder.toString().trim();
}
catch (MalformedURLException e){
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
TextView textView = (TextView) findViewById(R.id.textJSON);
textView.setText(result);
}
}
Error:(31, 5) error: MainActivity.BackgroundTask is not abstract and does not override abstract method doInBackground(Void...) in AsyncTask
Error:(39, 24) error: doInBackground(Void...) in MainActivity.BackgroundTask cannot override doInBackground(Params...) in AsyncTask return type Void is not compatible with String where Params,Result are type-variables: Params extends Object declared in class AsyncTask Result extends Object declared in class AsyncTask
Error:(38, 9) error: method does not override or implement a method from a supertype
Error:(54, 53) error: incompatible types: String cannot be converted to Void
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.> Compilation failed; see the compiler error output for details.