android - picasso 无法在 Android 中加载

标签 android picasso

我将 .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'

我的 list 是这样的

<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'
}

编辑2: 日志:

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

最佳答案

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

关于android - picasso 无法在 Android 中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28672629/

相关文章:

java - 如何检查拖动 View 的位置是否覆盖另一个 View

picasso 产生OutOfMemoryError

java - Android picasso : Method call should happen from the main thread

android - 查询有关使用互联网连接的应用程序

java - 来自 Android 子类的 textView 上的 setText()

java - 以编程方式设置 ListView 高度

android - 在 Picasso 设置的 ImageView 上画一条线

java - Android - 迭代列表时的空对象引用

android - Picasso 的 fit()、resize() 和 transform() 会在下载前缩小图像尺寸吗?

android - picasso 图像使用自签名证书加载 https