Я пытаюсь получить информацию о твитах из поискового запроса в приложение для Android. Я могу указать имя пользователя и тему в списке, но у меня проблемы с захватом фотографии. Вот мой метод GetView от моего адаптераHttpConnection failing on .connect() для URL изображения
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.listitem, null);
}
UserRecord user = users.get(position);
if (user != null) {
TextView username = (TextView) v.findViewById(R.id.username);
TextView subject = (TextView) v.findViewById(R.id.subject);
// Bitmap bitmap = DownloadImage(user.imageURL);
ImageView img = (ImageView) v.findViewById(R.id.avatar);
if (username != null) {
username.setText(user.username);
}
if(subject != null) {
subject.setText(user.subject);
}
if (img != null){
try {
URL myURL = new URL(user.imageURL);
HttpURLConnection conn = (HttpURLConnection) myURL.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
img.setImageBitmap(BitmapFactory.decodeStream(is));
} catch (Exception e) {
e.printStackTrace();
}
}
}
return v;
}
Я проследил через мой код и он терпит неудачу на conn.connect() и переходит к утверждению улова. Кто-нибудь знает, почему это происходит? У меня есть подключение к Интернету в моем mainfest. Благодаря!