我想在我的项目中添加Picasso库,但我的项目会出错。 Iusing 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;
}
的build.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')
}
答案 0 :(得分:14)
替换
行compile files('libs/picasso-2.1.1.jar')
带
compile 'com.squareup.picasso:picasso:2.1.1'
这样您就不必将Picasso .jar添加到libs文件夹中。相反,它将直接从Maven Central中提取库。
答案 1 :(得分:3)
'Build-> Rebuild'选项对我有帮助