You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MultiSelectListPreference时遇类找不到异常求助

Hey there, sorry to hear you hit this roadblock with your Udacity Google Scholarship project—let’s figure out how to fix that ClassNotFoundException for android.support.v7.preference.MultiSelectListPreference!

This error almost always ties back to issues with the preference support library setup. Here are the most common fixes to try, in order of likelihood:

1. Verify the correct dependency is in your build.gradle

The MultiSelectListPreference from the support v7 library isn’t included by default in every project. Head to your app-level build.gradle file (inside the app folder) and check if you have this line in the dependencies block:

implementation 'com.android.support:preference-v7:28.0.0'

If it’s missing, add it. If your project uses AndroidX (the modern replacement for support libraries), use this instead:

implementation 'androidx.preference:preference:1.2.0'

After updating or adding the dependency, don’t just hit "Run"—do a full clean and rebuild:

  • Go to Build > Clean Project in Android Studio
  • Then run Build > Rebuild Project to ensure the new dependency is properly pulled in.

2. Double-check the XML namespace in pref_visualizer.xml

A wrong namespace in your preference XML can cause the app to look for the wrong class. Open pref_visualizer.xml and make sure the root PreferenceScreen tag uses the correct namespaces:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

For your MultiSelectListPreference, use the android: prefix for standard attributes like key, title, entries, and entryValues—the support/AndroidX library will resolve the correct class once the dependency is set up.

3. Fix AndroidX/Support Library mismatches

If your project was migrated to AndroidX but old support library references are still present, this can trigger class not found errors. Use Android Studio’s migration tool to clean this up:

  • Go to Refactor > Migrate to AndroidX
  • Follow the prompts to update all dependencies and code references to AndroidX. This will switch your preference imports to androidx.preference.* instead of the old android.support.v7.preference.* ones.

4. Clear Android Studio’s cache

Sometimes corrupted IDE cache causes weird class resolution issues. To fix this:

  • Go to File > Invalidate Caches...
  • Check "Invalidate and Restart" and confirm. This clears the cache and restarts the IDE, often resolving odd dependency-related bugs.

Since you only modified arrays.xml and pref_visualizer.xml, the first two fixes are the most likely to solve your problem. Start with verifying the build.gradle dependency, then check the XML namespace, and do a clean rebuild—you should be back up and running in no time!

内容的提问来源于stack exchange,提问作者Sebastian W.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:23:34