我的应用不断崩溃,请提供帮助。
06-21 18:46:01.110 4932-4932/creator.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: creator.app, PID: 4932
android.content.res.Resources$NotFoundException: Drawable creator.app:dimen/design_bottom_navigation_height with resource ID #0x7f060054
Caused by: android.content.res.Resources$NotFoundException: Resource "creator.app:dimen/design_bottom_navigation_height" (7f060054) is not a Drawable (color or path): TypedValue{t=0x5/d=0x3801 a=2 r=0x7f060054}
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:687)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
at android.content.res.Resources.getDrawable(Resources.java:767)
at android.content.Context.getDrawable(Context.java:525)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:358)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:85)
at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:93)
at creator.app.DicesElementAdapter.onBindViewHolder(DicesElementAdapter.java:59)
at creator.app.DicesElementAdapter.onBindViewHolder(DicesElementAdapter.java:19)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:556)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java:1858)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:724)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2342)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2069)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
我创建了一个基本活动,该活动的缺陷是屏幕底部有一个邮件图标。从此以后,请提供帮助。我删除了与该活动相关的所有xml和java文件,但仍然收到此错误。
PS:错误中引用的适配器没有问题,在此发生之前运行良好。
编辑:
dimen.xml文件
<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>
适配器文件
package creator.app;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.google.gson.Gson;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
public class DicesElementAdapter extends RecyclerView.Adapter<DicesElementAdapter.ViewHolder>{
private Context context;
private ImageView Result;
private List<LogClass> LogsList;
private List<DiceClass> DicesList;
private Gson logsgson;
private Gson dicegson;
private GsonLogClass gsonLogClass;
private GsonDiceClass gsonDiceClass;
private String currentDateTimeString;
public DicesElementAdapter(Context context, ImageView result, List<LogClass> logsList, List<DiceClass> dicesList, Gson logsgson, Gson dicegson, GsonLogClass gsonLogClass, GsonDiceClass gsonDiceClass) {
this.context = context;
Result = result;
LogsList = logsList;
DicesList = dicesList;
this.logsgson = logsgson;
this.dicegson = dicegson;
this.gsonLogClass = gsonLogClass;
this.gsonDiceClass = gsonDiceClass;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (DicesList == null){
DicesList = new ArrayList<>();
saveDicesGson(DicesList);
}
if (LogsList == null){
LogsList = new ArrayList<>();
}
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.dices_layout, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
holder.Dice.setImageResource(DicesList.get(position).getDiceIcon());
holder.Dice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//This generates a random number
int random = new Random().nextInt(DicesList.get(position).getDiceFaces().size());
//This sets the Result image to the result of the random number generator (depends on the dice you clicked)
Result.setImageResource(DicesList.get(position).getDiceFaces().get(random));
Result.setVisibility(View.VISIBLE);
//This adds the log and saves it to gson
currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
LogsList.add(new LogClass(DicesList.get(position).getDiceFaces().get(random), currentDateTimeString));
saveLogsGson(LogsList);
}
});
}
@Override
public int getItemCount() {
return DicesList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
ImageView Dice;
public ViewHolder(View itemView) {
super(itemView);
Dice = itemView.findViewById(R.id.Dices_view);
}
}
public void saveLogsGson(List<LogClass> logsList) {
//convert ArrayList object to String by Gson
String jsonLogs = logsgson.toJson(logsList);
// save to shared preference
gsonLogClass.saveLogs(jsonLogs);
}
public void saveDicesGson(List<DiceClass> dicesList) {
//Convert ArrayList object to String by Gson
String jsonDices = dicegson.toJson(dicesList);
//Save to shared preference
gsonDiceClass.saveDices(jsonDices);
}
}
答案 0 :(得分:0)
创建一个新的基本活动,该活动默认情况下具有底部导航菜单,从而以某种方式破坏了我的图像列表。我仍然不知道原因。
我要解决的错误是使用List.clear();。在我拥有的每个数组列表中,然后重新制作它们。
我必须这样做,因为它们已保存在gson上,所以我必须重置它们,保存它们,然后重新制作列表。