بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
مشکل در ارسال پارامتر در پروژه اندروید مارکت
سلام دوستان وقت بخیر . کدها رو کپی میکنم و خطا ها رو مشخص میکنم. ممنون میشم کمک کنید.
public static void populateFromServer() {
String url = "http://android1-apps.esy.es/service.php";
Map<String,String> params = new HashMap<>();
params.put("action", "read");
params.put("filter", lastFilter);
params.put("sort", lastSort);
WebService webService=new WebService();
String result= webService.execute(params); error: incompatible types: AsyncTask<Map<String,String>,Void,String> cannot be converted to String
if (result != null) {
try {
applications.clear();
JSONArray apps = new JSONArray(result);
for (int i = 0; i < apps.length(); i++) {
JSONObject object = apps.getJSONObject(i);
StructApplication application = new StructApplication();
application.name = object.getString("name");
application.price = object.getInt("price");
application.logoUrl = object.getString("logoUrl");
application.ratingValue = (float) object.getDouble("ratingValue");
application.author = object.getString("author");
application.votes = object.getInt("votes");
application.file = object.getString("file");
application.fileSize = object.getLong("fileSize");
application.versionName = object.getString("versionName");
application.installs = object.getInt("installs");
application.description = object.getString("description");
application.phoneNumber = object.getString("phoneNumber");
application.email = object.getString("email");
applications.add(application);
}
adapter.notifyDataSetChanged();
}
catch (JSONException e) {
e.printStackTrace();
}
}
}
private static class WebService extends AsyncTask<Map<String,String>,Void,String> {
@Override
protected String doInBackground(Map<String,String>... params) {
String encodedStr = getEncodedData(params); error: incompatible types: Map<String,String>[] cannot be converted to Map<String,String>
BufferedReader reader = null;
try {
URL url = new URL("http://android1-apps.esy.es/service.php");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
writer.write(encodedStr);
writer.flush();
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
line = sb.toString();
return line;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
}
private String getEncodedData(Map<String,String> data) {
StringBuilder sb = new StringBuilder();
for(String key : data.keySet()) {
String value = null;
try {
value = URLEncoder.encode(data.get(key),"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if(sb.length()>0)
sb.append("&");
sb.append(key + "=" + value);
}
return sb.toString();
}
}
برای این سوال پاسخی وجود ندارد.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .