Why can't picasso load my url? Always defaulting to onError.

旧城冷巷雨未停 提交于 2019-12-20 07:30:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!