2

我想在我的项目中添加毕加索库,但我的项目出错。使用 jdk 7 和 android studio 0.2.11

这是我的错误。我尝试了 8 个小时,但又一次又一次地出错

请帮忙

抱歉英语不好。

10-05 21:02:45.891  32262-32262/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.squareup.picasso.Picasso
            at com.medyasef.androidfirsttime.MainActivity.onCreate(MainActivity.java:20)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

这是 MainActivity.java

package com.medyasef.androidfirsttime;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

public class MainActivity extends Activity {

    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView = (ImageView) findViewById(R.id.imageView);
        Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(imageView);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

构建.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 16
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.0'
    compile files('libs/picasso-2.1.1.jar')
}
4

2 回答 2

14

换行

compile files('libs/picasso-2.1.1.jar')

compile 'com.squareup.picasso:picasso:2.1.1'

这样您就不必将 Picasso .jar 添加到您的 libs 文件夹中。相反,它将直接从 Maven Central 中提取库。

于 2013-10-05T18:53:46.950 回答
3

Android Studio 中的“Build->Rebuild”选项对我有帮助

于 2013-11-04T16:51:53.597 回答