Picasso不会在Android中加载

问题描述 投票:1回答:4

我将.jar文件放在/ libs文件夹中并将其添加为库,现在我的build.gradle文件具有以下依赖项:

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':SmoothProgressBar')
compile 'com.squareup.picasso:picasso:2.5.0'

我的清单是这样的

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.prova" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

但是,当我需要加载图像时,它不会做任何事情,并且没有错误来自logcat。这是我的代码:

public class MainActivity extends ActionBarActivity {

private ImageView img;

private String image = "http://i.stack.imgur.com/LOb1t.png";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    img = (ImageView) findViewById(R.id.image);

    Picasso.with(this).setLoggingEnabled(true);
    Picasso.with(this).load(Uri.parse(image)).into(img);
    }

}

我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />

</RelativeLayout>

在Eclipse中工作正常没有任何问题。提前致谢。

编辑:这是我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.enrico.prova"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.squareup.picasso:picasso:2.5.0'
}

EDIT2:Logcat:

02-23 16:41:36.857  28865-28865/com.example.enrico.prova D/Picasso﹕ Main        created      [R1] Request{http://www.online-image-editor.com//styles/2014/images/example_image.png}
02-23 16:41:36.858  28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher  enqueued     [R1]+0ms
02-23 16:41:36.876  28865-29238/com.example.enrico.prova D/Picasso﹕ Hunter      executing    [R1]+16ms
02-23 16:41:36.883  28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher  batched      [R1]+25ms for error
02-23 16:41:37.112  28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher  delivered    [R1]+254ms
02-23 16:41:37.112  28865-28865/com.example.enrico.prova D/Picasso﹕ Main        errored      [R1]+255ms
android picasso
4个回答
3
投票

您在<application>中拥有自己的权限。他们应该进入<manifest>外面的<application>


1
投票

为什么不尝试使用Maven Central而不是jar,

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':SmoothProgressBar')
compile 'com.squareup.picasso:picasso:2.5.0'

而可能是getApplicationContext(),你应该只使用this


1
投票

你好,请尝试,因为你必须通过一个uri到毕加索负荷

load(Uri.parse(image))

你可以发布更新代码..与Uri.parse ..因为你可以看到它在我的项目中工作


0
投票

好吧,这听起来非常明显但是我的问题......你的手机有互联网吗?它连接了吗?只测试是否所有其他方法都失败了,因为有时这是我们忽略的简单事情。

© www.soinside.com 2019 - 2024. All rights reserved.