'Image not showing up in launch screen Android Studio
I have a project to do that involves downloading images from the internet with asyncTask with a progressbar at the bottom of the image and an infinite loop so it continues to through the images. When I run my code it says it was successful but the images are not showing up in the Android Emulator. If anyone could help that would great, thank you. This is the code for mainActivity.java:
public class MainActivity extends AppCompatActivity {
String url = "https://cataas.com/cat";
private static XmlPullParser xpp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ProgressBar progressBar = findViewById(R.id.progress_bar);
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(0);
}
ImageView imageView;
public void Loading (View view) {
CatImages catImages = new CatImages();
imageView = findViewById(R.id.imgView);
try {
Bitmap bitmap = catImages.execute(url).get();
bitmap = catImages.execute(url).get();
imageView.setImageBitmap(bitmap);
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
class CatImages extends AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... strings) {
Bitmap bitmap = null;
URL url;
HttpURLConnection httpURLConnection;
InputStream in;
try {
url = new URL(strings[0]);
httpURLConnection = (HttpURLConnection)
url.openConnection();
in = httpURLConnection.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
while (true) { }
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
}
}
enter code here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
