Android Glide library NoClassDefFoundError

2019-05-28 10:19发布

Am i using the Glide library wrongly? what could be the problem?

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

    ImageView iv = (ImageView) findViewById(R.id.imageView1);

    Glide.with(this).load(R.drawable.salads_caesar_salad).into(iv);
}

enter image description here

4条回答
放荡不羁爱自由
2楼-- · 2019-05-28 10:25

If your code compiles fine it's highly likely you have the right dependencies on the compile classpath. If you use Android Studio/Gradle it's possible that ProGuard somehow strips the Glide class for whatever reason, but it really shouldn't because you're actually using it.

The above contradicition and the fact that your LogCat screenshot is either that of Eclipse ADT or Android Device Monitor (monitor.bat) leaves one option: you didn't export your dependency; try the following (see the screenshot in the linked manual):

  1. Right click the Android Application Project
  2. Properties
  3. Java Build Path
  4. Order and Export
  5. make sure glide.jar is ticked

Alternatively consider re-creating your project in Android Studio (official Google product for Android development) or IntelliJ IDEA 14+ and copying your sources over; the IntelliJ Android Plugin has much better support for Android and modern build tools than Eclipse ADT. I was really against the transition myself, but as you see it worked, because now I'm advocating for it. It's worth a day or two effort in the long run.

查看更多
对你真心纯属浪费
3楼-- · 2019-05-28 10:26

You need to add Glide library to your android project.

If you using gradle:

dependencies {
    compile 'com.github.bumptech.glide:glide:3.6.0'
    compile 'com.android.support:support-v4:19.1.0'
}

If you are using maven:

<dependency>
  <groupId>com.github.bumptech.glide</groupId>
  <artifactId>glide</artifactId>
  <version>3.6.0</version>
  <type>aar</type>
</dependency>
<dependency>
  <groupId>com.google.android</groupId>
  <artifactId>support-v4</artifactId>
  <version>r7</version>
</dependency>

You can also add library directly to your project in your Eclipse: right-click on your project's properties then Library section then click Add to add the library.

If you are using Android Studio: http://www.truiton.com/2015/02/android-studio-add-library-project/

查看更多
Summer. ? 凉城
4楼-- · 2019-05-28 10:34

you seem to import the glide library wrongly -

the NoClassDefFoundError results of the fact that the android build does not find your glide library.

In the android studio you can add it in "project structure" via adding the library glide to your dependencies. Check out the general strategy here

查看更多
老娘就宠你
5楼-- · 2019-05-28 10:37

I think you can only load URL's, and you can only use Resources in the .error() and .placeholder() methods according to their documentation. https://github.com/bumptech/glide

And why would you use glide when you can straight set the resource in the imageview like this:

iv.setImageResource(R.drawable.salads_caesar_salad);

I hope it helps!

查看更多
登录 后发表回答