Android Glide library NoClassDefFoundError

不想你离开。 提交于 2020-01-13 19:45:30

问题


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);
}


回答1:


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.




回答2:


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/




回答3:


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




回答4:


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!



来源:https://stackoverflow.com/questions/31397975/android-glide-library-noclassdeffounderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!