我正在使用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文件开头的导入块中。
首先检查是否已在build.gradel中添加此依赖项:-
implementation 'com.github.bumptech.glide:glide:4.9.0'
如果是,则将此行粘贴到该类的导入语句中:-
com.bumptech.glide.load.engine. DiskCacheStrategy