我的数据库(MySQL)图像路径中的记录数据也在另一个表中
我在android中请求了图像路径,我可以获取我的图像,但问题出现在logcat中 enter image description here
像这样....private void showRankingByMedal() {
class RankingPHPRequest extends AsyncTask<String, Void, String> {
private URL url;
public RankingPHPRequest(String url) throws MalformedURLException {
this.url=new URL(url);
}
private String readStream(InputStream in) throws IOException {
StringBuilder jsonHtml = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line = null;
while((line = reader.readLine()) != null)
jsonHtml.append(line);
reader.close();
//System.out.println(jsonHtml.toString()+"READING");
return jsonHtml.toString();
}
@Override
protected String doInBackground(String... params) {
try {
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestMethod("POST");
conn.setConnectTimeout(5000);
conn.setDoOutput(true);
conn.setDoInput(true);
String result = readStream(conn.getInputStream());
conn.disconnect();
return result;
}
catch (Exception e) {
Log.i("PHPRequest", "request was failed.");
return null;
}
}
@Override
protected void onPostExecute(String s) {
Bitmap bitmap;
listView1 = (ListView) view.findViewById (R.id.ranking_medal_listview);
adapter = new RankingAdapter(getActivity().getBaseContext(), 3);
Resources res = getResources();
listView1.setAdapter(adapter);
super.onPostExecute(s);
try {
JSONObject jObject = new JSONObject(s);
JSONArray results = jObject.getJSONArray("result");
System.out.println(results.toString());
username = new String[results.length()];
goldMedal = new String[results.length()];
silverMedal = new String[results.length()];
bronzeMedal = new String[results.length()];
imagepath = new String[results.length()];
for ( int i = 0; i < results.length(); ++i ) {
JSONObject temp = results.getJSONObject(i);
username[i] = temp.getString("name");
goldMedal[i] = temp.getString("gold");
silverMedal[i] = temp.getString("silver");
bronzeMedal[i] = temp.getString("bronze");
imagepath[i] = temp.getString("imagepath");
}
for(int i=0; i<results.length(); ++i) {
try {
URL url = new URL(imagepath[i]);
System.out.println(imagepath[i]+"%%%%%%%%%%%%%%%%");
URLConnection conn = url.openConnection();
conn.connect();
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
bitmap = BitmapFactory.decodeStream(bis);
bis.close();
String totalMedal = goldMedal[i]+ " "+ silverMedal[i] + " " + bronzeMedal[i];
System.out.println("@@@@@@@@@@@@@@@@@"+username[i]);
System.out.println(totalMedal);
adapter.addItem(new RankingObject(bitmap, String.valueOf(i+1), username[i], totalMedal));
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
RankingObject curItem = (RankingObject) adapter.getItem(position);
String[] curData = curItem.getData();
}
});
}
}
RankingPHPRequest rankingPHPRequest = null;
try {
rankingPHPRequest = new RankingPHPRequest("http://117.17.158.242/ranking/getRankingByMedal.php");
rankingPHPRequest.execute();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
由于图像路径,我必须使用其他网络请求 我是否必须制作双AsyncTask(AsyncTask中的AsyncTask)? 请帮我解决几乎一周未解决的问题