Issue
How do I get the doInBackground() method to be implemented as an abstract method ? The IDE also says I require 3 arguments instead of just 1 for AsyncTask<...>
package com.example.a_phi.nowswap;
import android.os.AsyncTask;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class EstablishConnection extends AsyncTask<String>{
StringBuilder sb = new StringBuilder();
public String doInBackground(String id) {
String link = "http://213.251.43.215/addContact.php";
try {
URL url = new URL(link);
String data = URLEncoder.encode("id", "UTF-8")
+ "=" + URLEncoder.encode(id, "UTF-8");
URLConnection conn = url.openConnection();
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
String line;
// Read Server Response
while((line = reader.readLine()) != null) {
sb.append(line);
break;
}
}catch(MalformedURLException e) {
System.out.print("MalformedURLException" + e.getMessage());
e.printStackTrace();
}
catch(IOException e){
System.out.print("IOException"+e.getMessage());
e.printStackTrace();
}
return sb.toString();
}
}
How do I get the doInBackground() method to be implemented as an abstract method ? The IDE also says I require 3 arguments instead of just 1 for AsyncTask<...>
Solution
I changed doInBackground(String id)
to doInBackground(String... id)
.
I also changed AsyncTask<String>
to AsyncTask<String, String, String>
, then it worked.
Answered By - Hazed 2.0
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.