我正在使用 android studio 来开发我的应用程序;准确地说是 AndroidX。我收到由 diskcachestategy
引起的错误。请帮我解决这个问题
private Context context;
private List<MenuCategoryObject> categoryObject;
public CategoryAdapter(Context context, List<MenuCategoryObject> categoryObject) {
this.context = context;
this.categoryObject = categoryObject;
}
@Override
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_category_list, parent, false);
return new CategoryViewHolder(layoutView);
}
@Override
public void onBindViewHolder(CategoryViewHolder holder, int position) {
final MenuCategoryObject catObject = categoryObject.get(position);
final int id = catObject.getMenu_id();
holder.categoryName.setText(catObject.getMenu_name());
// use Glide to download and display the category image.
String serverImagePath = Helper.PUBLIC_FOLDER + catObject.getMenu_image();
Glide.with(context).load(serverImagePath).diskCacheStrategy(DiskCacheStrategy.ALL).fitCenter().override(300, 300).into(holder.categoryImage);
holder.categoryImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent categoryIntent = new Intent(context, SingleMenuCategoryActivity.class);
categoryIntent.putExtra("CATEGORY_NAME", catObject.getMenu_name());
categoryIntent.putExtra("CATEGORY_ID", id);
context.startActivity(categoryIntent);
}
});
}
@Override
public int getItemCount() {
return categoryObject.size();
}
public static int getResourseId(Context context, String pVariableName, String pResourcename, String pPackageName) throws RuntimeException {
try {
return context.getResources().getIdentifier(pVariableName, pResourcename, pPackageName);
} catch (Exception e) {
throw new RuntimeException("Error getting Resource ID.", e);
}
}
}
我收到一条错误消息:
error: cannot find symbol method diskCacheStrategy(DiskCacheStrategy)
如何修复它?
最佳答案
添加com.bumptech.glide.load.engine。 DiskCacheStrategy
到 java 文件开头的导入 block 中。
关于java - 我的 Android Studio 应用程序可能出现什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60633345/