Bubino
Bubino

Reputation: 317

android.content.res.Resources$NotFoundException: Resource ID #0x7f070016 type #0x3 is not valid

When I click on "trovamico" cardview to be able to go to that activity, it crashes and I get this error. Below I put the code of the Home and trovamicoActivity of my app.I tried to see on the site but could not find anything that helped me.If you need my github project let me know

Error

android.content.res.Resources$NotFoundException: Resource ID #0x7f070016 type #0x3 is not valid
    at android.content.res.Resources.getDimensionPixelSize(Resources.java:827)
    at com.google.maps.api.android.lib6.impl.ax.d(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (150700-0):5)
    at com.google.maps.api.android.lib6.impl.fe.<init>(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (150700-0):6)
    at com.google.maps.api.android.lib6.impl.bj.aA(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (150700-0):14)
    at com.google.maps.api.android.lib6.impl.cn.o(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (150700-0):2)
    at com.google.android.gms.maps.internal.o.aY(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (150700-0):26)
    at ej.onTransact(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (150700-0):4)
    at android.os.Binder.transact(Binder.java:1043)
    at com.google.android.gms.internal.maps.zza.zzH(com.google.android.gms:play-services-maps@@18.0.0:2)
    at com.google.android.gms.maps.internal.zzk.onCreateView(com.google.android.gms:play-services-maps@@18.0.0:5)
    at com.google.android.gms.maps.zzau.onCreateView(com.google.android.gms:play-services-maps@@18.0.0:7)
    at com.google.android.gms.dynamic.zad.zab(com.google.android.gms:play-services-base@@18.0.1:2)
    at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaf(com.google.android.gms:play-services-base@@18.0.1:1)
    at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreateView(com.google.android.gms:play-services-base@@18.0.1:2)
    at com.google.android.gms.maps.SupportMapFragment.onCreateView(com.google.android.gms:play-services-maps@@18.0.0:1)
    at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2995)
    at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:523)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
    at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113)
    at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1374)
    at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2841)
    at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2784)
    at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:262)
    at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:478)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1435)
    at android.app.Activity.performStart(Activity.java:8024)
    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3475)
    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    

Home XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="7"
    android:background="#fafafa"
    tools:context="com.example.chatapp.Fragments.HomeFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        android:gravity="bottom"
        android:background="@drawable/header_bg"
        android:padding="12dp"
        >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Home"
            android:textColor="#fafafa"
            android:textSize="30sp"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Benvenuto"
            android:textColor="#fafafa"
            android:textSize="25sp"
            />

    </LinearLayout>


    <!--Creating the menu grid button-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="6"
        android:orientation="vertical"
        android:weightSum="2"
        android:padding="16dp"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:weightSum="2"
            android:padding="16dp"
            >
            <androidx.cardview.widget.CardView
                android:id="@+id/trovamico"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                app:cardElevation="2dp"
                app:cardCornerRadius="8dp"
                android:layout_margin="12dp"
                android:background="#fff"
                android:clickable="true"
                android:focusable="true">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:gravity="center"
                    >
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_baseline_plus_one_24"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="  Trova un amico   "
                        android:textAlignment="center"
                        />
                </LinearLayout>

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:id="@+id/cercaincontro"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                app:cardElevation="2dp"
                app:cardCornerRadius="8dp"
                android:layout_margin="12dp"
                android:background="#fff"
                android:clickable="true"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:gravity="center"
                    >
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_baseline_plus_one_24"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Cerca un incontro"
                        android:textAlignment="center"
                        />
                </LinearLayout>

            </androidx.cardview.widget.CardView>


        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:weightSum="2"
            android:padding="16dp"
            >

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="1"
                app:cardElevation="2dp"
                app:cardCornerRadius="8dp"
                android:layout_margin="12dp"
                android:background="#fff"
                android:clickable="true"
                >

                <LinearLayout
                    android:layout_width="335dp"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="vertical">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_baseline_plus_one_24" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Organizza un incontro"
                        android:textAlignment="center" />
                </LinearLayout>

            </androidx.cardview.widget.CardView>

        </LinearLayout>

    </LinearLayout>

TrovamicoActivity

public static final String TAG = "addreess";

//private GoogleMap mMap;
private FragmentsTrovamicoBinding binding;
LatLng latLng;


private DatabaseReference reference;
private FirebaseUser firebaseUser;

List<String> addresses, genders;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    binding = FragmentsTrovamicoBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    Log.d(TAG, "String addreess: " + addresses);
    addresses = new ArrayList<>();
    genders = new ArrayList<>();

    firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());

  

    ValueEventListener eventListener = new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {
            for (DataSnapshot dataSnapshot: snapshot.getChildren()) {
                reference.child("address").get().addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
                        String address = task.getResult().getValue().toString();
                        addresses.add(address);
                    }
                });
                Log.d(TAG, "String addreess: " + addresses);
                reference.child("gender").get().addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
                        String gender = task.getResult().getValue().toString();
                        genders.add(gender);
                    }
                });
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError error) {

        }
    };

    reference.addListenerForSingleValueEvent(eventListener);

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {

    for (int i = 0; i < addresses.size(); i++) {
        String user_address = addresses.get(i);
        if (!user_address.equals("To be added")) {
            Log.d(TAG, "String addreess: " + addresses);
            String user_gender = genders.get(i);
            latLng = getLocationFromAddress(user_address);
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.title("You");
            Log.d(TAG, "String addreess: " + addresses);
            markerOptions.icon(BitmapFromVector(getApplicationContext(), (user_gender.equals("Male")) ? R.drawable.male : R.drawable.female));
            googleMap.clear();
            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 5));
            googleMap.addMarker(markerOptions);
        }
    }
}

public LatLng getLocationFromAddress(String strAddress) {

    Geocoder coder = new Geocoder(this);
    List<Address> address;
    LatLng p1;

    try {
        address = coder.getFromLocationName(strAddress, 5);
        if (address == null) {
            return null;
        }
        Address location = address.get(0);
        p1 = new LatLng(location.getLatitude(), location.getLongitude());

        return p1;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

Upvotes: 7

Views: 5489

Answers (3)

Marawan Mamdouh
Marawan Mamdouh

Reputation: 1015

In my case, I clear the cache on my emulator and re-run the app

enter image description here

Upvotes: 13

alperk01
alperk01

Reputation: 343

I have solved this problem by copying the missing file into the drawable folder.

First you have to find the name of the missing resource. In the project window, open the generated apk file by double clicking which exists in the app/release folder. Click resources.arsc file and find the file with ID = 0x7f070016. So you will see the name of the resource file as abc_cab_background_top_material.xml

https://android.googlesource.com/platform/frameworks/support/+/b19cba1/v7/appcompat/res/drawable/abc_cab_background_top_material.xml

Copy this file content and put under drawable folder. Then your app will find the needed resource file and does not crash.

Upvotes: 6

Hamid-Ghasemi
Hamid-Ghasemi

Reputation: 294

You have a resource problem. An image may not be found in the drawable folder.

Copy xhdpi and other folders resources into default drawable folder.

Copy all the files that are in the drawable-...... folders to the drawble folder

Upvotes: 0

Related Questions