0

My app keeps crushing, please help.

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)

I created a basic activity that had by defect a mail icon in the bottom part of the screen. And since then this happens, please help. I deleted all the xml and java files related to that activity and I still get this error.

PS: The adapter that is referenced in the error has no problems, it was running well before this happened.

Edit:

dimen.xml file

<resources>
<dimen name="fab_margin">16dp</dimen>
</resources>

Adapter file

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);
}
}
TommyTomato
  • 123
  • 2
  • 10
  • Did you clean and rebuild after deleting the resources? – UkFLSUI Jun 21 '18 at 18:53
  • Could you edit your question adding your *layout* and *dimen* xml files? – regmoraes Jun 21 '18 at 18:55
  • I think this is happening because you are trying to load "design_bottom_navigation_height" as a drawable in somewhere. – SafalFrom2050 Jun 21 '18 at 18:58
  • Yep that's the problem I guess but I can't find which file is trying to do so. @regmoraes which layout file do you want? – TommyTomato Jun 21 '18 at 19:06
  • Possible duplicate of [Getting android.content.res.Resources$NotFoundException: exception even when the resource is present in android](https://stackoverflow.com/questions/9161435/getting-android-content-res-resourcesnotfoundexception-exception-even-when-the) – João Carlos Jun 21 '18 at 20:00
  • If it is, then none of the answers from that post worked for me anyway. I can't find the problem, the adapter that the error references doesn't have a problem as far as I can see. (Edit: I also cleaned and rebuilt the project, din't work.) – TommyTomato Jun 21 '18 at 20:09

1 Answers1

0

Creating a new Basic activity that has a bottom navigation menu by default somehow corrupted the list of images I had. I still don't know the reason.

What I did to fix the error was to use List.clear(); in every arraylist I had, and then remake them.

I had to do this because they were saved on gson, so I had to reset them, save them, and then remake the list.

TommyTomato
  • 123
  • 2
  • 10