问题
Here is the onCreate of myActivity thats gonna use picasso:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "http://s3.amazonaws.com/snappie.watermarks/crssd.png";
sticker = (ImageView)findViewById(R.id.sticker);
Picasso.with(getApplicationContext()).setLoggingEnabled(true);
FrameLayout camera_layout =(FrameLayout)findViewById(R.id.fragment_container);
previewWidth = camera_layout.getWidth();
Log.d("width","width is"+previewWidth);
Picasso.with(this).load(url).into(sticker,new Callback() {
@Override
public void onSuccess() {
myBitmap = ((BitmapDrawable) sticker.getDrawable()).getBitmap();
int width = (myBitmap.getWidth() * previewWidth) / 1080;
int height = (myBitmap.getHeight() * previewWidth) / 1080;
scaledBitmap = Bitmap.createScaledBitmap(myBitmap, width, height, false);
sticker.setImageBitmap(scaledBitmap);
//saveBitmap(myBitmap);
}
@Override
public void onError() {
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.balloons);
sticker.setImageBitmap(bm);
}
});
}
It pretty much always defaults to the balloons (from onError).
Here is the log:
05-31 12:04:22.705 6610-6610/com.snappiesticker.cwac4 D/Picasso﹕ Main created [R0] Request{http://s3.amazonaws.com/snappie.watermarks/crssd.png}
05-31 12:04:22.709 6610-6629/com.snappiesticker.cwac4 D/Picasso﹕ Dispatcher enqueued [R0]+4ms
05-31 12:04:22.714 6610-6631/com.snappiesticker.cwac4 D/Picasso﹕ Hunter executing [R0]+10ms
05-31 12:04:22.732 6610-6629/com.snappiesticker.cwac4 D/Picasso﹕ Dispatcher batched [R0]+28ms for error
05-31 12:04:22.815 6610-6653/com.snappiesticker.cwac4 D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-31 12:04:22.822 6610-6610/com.snappiesticker.cwac4 D/Atlas﹕ Validating map...
05-31 12:04:22.856 6610-6653/com.snappiesticker.cwac4 I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/14/15, ab0075f, Id3510ff6dc
05-31 12:04:22.857 6610-6653/com.snappiesticker.cwac4 I/OpenGLRenderer﹕ Initialized EGL, version 1.4
05-31 12:04:22.879 6610-6653/com.snappiesticker.cwac4 D/OpenGLRenderer﹕ Enabling debug mode 0
05-31 12:04:22.966 6610-6629/com.snappiesticker.cwac4 D/Picasso﹕ Dispatcher delivered [R0]+261ms
05-31 12:04:22.977 6610-6610/com.snappiesticker.cwac4 D/Picasso﹕ Main errored [R0]+272ms
If you try the url manually you can tell that it is real and exists. So what is going on here?
回答1:
it looks good, you probably missed the internet use-permission. Add
<uses-permission android:name="android.permission.INTERNET" />
to your AndroidManifest.xml
来源:https://stackoverflow.com/questions/30561742/why-cant-picasso-load-my-url-always-defaulting-to-onerror