Я разработчик .net, и я работаю в Visual Studio в течение последних 3-4 лет, но теперь мой босс попросил меня создать какое-то приложение для Android, поэтому я должен вернуться в свое время в колледже и практиковать свои навыки Java (не так хорошо). Теперь приложение простое: загрузите изображение на сервер, просмотрите это изображение из веб-приложения и т. Д.Тип Может только перебирать массив или экземпляр java.lang.Iterable, загрузить изображение android
Теперь мой вопрос: я читал много о том, как это сделать, и стараюсь много учебников, и Наконец-то я нашел хороший. Он имеет класс загрузки я модифицированный, но я получаю эту ошибку:
#Description Resource Path Location Type Can only iterate over an array or an instance of java.lang.Iterable#
Я не имею абсолютно никакого понятия о том, что нужно сделать, чтобы быть честными; У меня есть поиск по этому вопросу и найдено несколько сообщений, но никто из них не помогает мне решить эту проблему. Исключение появляется в этой строке: for (String sdPath : path)
. Вот код:
public class HttpUploader extends AsyncTask<String, Void, String> {
protected String doInBackground(String path) {
String outPut = null;
for (String sdPath : path) {
Bitmap bitmapOrg = BitmapFactory.decodeFile(sdPath);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
//Resize the image
double width = bitmapOrg.getWidth();
double height = bitmapOrg.getHeight();
double ratio = 400/width;
int newheight = (int)(ratio*height);
System.out.println("———-width" + width);
System.out.println("———-height" + height);
bitmapOrg = Bitmap.createScaledBitmap(bitmapOrg, 400, newheight, true);
//Here you can define .PNG as well
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 95, bao);
byte[] ba = bao.toByteArray();
int lol=0;
String ba1 = Base64.encodeToString(ba,lol);
System.out.println("uploading image now " + ba1);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image", ba1));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://path to the image upload .php file/api.upload.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
// print responce
outPut = EntityUtils.toString(entity);
Log.i("GET RESPONSE—-", outPut);
//is = entity.getContent();
Log.e("log_tag ******", "good connection");
bitmapOrg.recycle();
}
catch (Exception e) {
Log.e("log_tag ******", "Error in http connection " + e.toString());
}
}
return outPut;
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
return null;
}
}
ли мой ответ решить проблему? У вас есть еще вопросы по этой проблеме? –