I used Picasso Get() method to lad a png file from URL. But the app crashes and does nothing.
I searched in Internet and community and tried the suggestions and recommendations I found. But alas the problem not solved. Please help me. This the code.
package com.example.imageapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.Toast;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import static android.widget.Toast.LENGTH_SHORT;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String MY_URL_STRING ="http://www.geocities.ws/mariyanaatham/2019/may/1.png";
ImageView iv = (ImageView) findViewById(R.id.iv);
Picasso.get()
.load(MY_URL_STRING)
.into(iv, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
e.printStackTrace();
String msg =e.getMessage();
Toast.makeText(getApplicationContext(),msg, LENGTH_SHORT).show();
}
});
}
}
The intention of the code is to display / load 1.png from the URL. If failed toast the error message.