1

I'm running my android app and it crashes when i use an image, @drawable/image, (image size is 48kb) but when i use the @mipmap/ic_launcher it runs. I want to be able to use images of my choice when developing.

I have searched for simpler errors here and from other sites but I'm not getting a solid fix.

How do i solve the error.

This is the Error Message

03-15 09:09:08.821 20006-20006/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.lecevaluation, PID: 20006
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lecevaluation/com.example.lecevaluation.MainActivity}: android.view.InflateException: Binary XML file line #35: Error inflating class ImageView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
        at android.app.ActivityThread.access$800(ActivityThread.java:166)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5590)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class ImageView
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:720)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:762)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:771)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.example.lecevaluation.MainActivity.onCreate(MainActivity.java:44)
        at android.app.Activity.performCreate(Activity.java:5447)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
        at android.app.ActivityThread.access$800(ActivityThread.java:166) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5590) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060058 a=-1 r=0x7f060058}
        at android.content.res.Resources.loadDrawable(Resources.java:3425)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:614)
        at android.widget.ImageView.<init>(ImageView.java:134)
        at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
        at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
        at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
        at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
        at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
        at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:762) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:771) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:499) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at com.example.lecevaluation.MainActivity.onCreate(MainActivity.java:44) 
        at android.app.Activity.performCreate(Activity.java:5447) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
        at android.app.ActivityThread.access$800(ActivityThread.java:166) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5590) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1280) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1096) 
        at dalvik.system.NativeStart.main(Native Method) 
03-15 09:09:09.341 620-917/? E/Watchdog: !@Sync 106

This is my MainActivity.java

    package com.example.lecevaluation;

import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "LoginActivity";
    private static final String URL_FOR_LOGIN = "https://XXX.XXX.X.XX/android_login/login.php";
    /**
     * the url is  C:\wamp64\www\android_login\login.php
     */

    ProgressDialog progressDialog;
    private EditText loginInputregNo, loginInputPassword;
    private Button btnlogin;
    private Button btnLinkSignup;
    TextView textView;
    int counter = 3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        loginInputregNo = (EditText) findViewById(R.id.login_input_regNo);
        loginInputPassword = (EditText) findViewById(R.id.login_input_password);
        btnlogin = (Button) findViewById(R.id.btn_login);
        btnLinkSignup = (Button) findViewById(R.id.btn_link_signup);
        textView = (TextView)findViewById(R.id.textView3);
        textView.setVisibility(View.GONE);

        //Progress Dialog
        progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);

        btnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginUser(loginInputregNo.getText().toString(),
                        loginInputPassword.getText().toString());
            }
        });

        btnLinkSignup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
                startActivity(i);
            }
        });
    }

    private void loginUser(final String reg_no, final String password){
        //Tag used to cancel the request
        String cancel_req_tag = "login";
        progressDialog.setMessage("Logging you in ...");
        showDialog();
        StringRequest strReq = new StringRequest(Request.Method.POST,
                URL_FOR_LOGIN, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d(TAG, "Register Response: " + response.toString()
                );
                hideDialog();
                try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");

                    if (!error){
                        String User = jObj.getJSONObject("user").getString("reg_no");

                        /**
                         * Launch User Activity
                         * Reached Here
                         */Intent intent = new Intent(
                                MainActivity.this,
                                UserActivity.class);
                        intent.putExtra("reg_no" //or regNo or username
                                , User);
                        startActivity(intent);
                        finish();
                    } else {

                        String errorMsg = jObj.getString("error_msg");
                        Toast.makeText(getApplicationContext(),
                                errorMsg, Toast.LENGTH_LONG).show();

                        textView.setVisibility(View.VISIBLE);
                        textView.setBackgroundColor(Color.RED);
                        counter--;
                        textView.setText(Integer.toString(counter));

                        if (counter == 0) {
                            btnlogin.setEnabled(false);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Login Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(),
                        error.getMessage(), Toast.LENGTH_LONG).show();
                hideDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                // Posting params to login url
                Map<String, String> params = new HashMap<String, String>();
                params.put("reg_no", reg_no);
                params.put("password", password);
                return params;
            }
        };
        // Adding request to request queue
        AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(strReq,cancel_req_tag);
    }

    private void showDialog() {
        if (!progressDialog.isShowing())
            progressDialog.show();
    }
    private void hideDialog() {
        if (progressDialog.isShowing())
            progressDialog.dismiss();
    }
}

This is the my activity_main

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
    android:gravity="center"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:layout_marginTop="20dp"
    tools:context=".MainActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:text = "@string/Lec"
        android:id = "@+id/textView1"
        android:layout_alignParentTop = "true"
        android:layout_centerHorizontal = "true"
        android:textColor = "#ff7aff24"
        android:textSize = "35sp" />

    <TextView
        android:text = "@string/Login"
        android:layout_width="wrap_content"
        android:layout_height = "wrap_content"
        android:id = "@+id/textView"
        android:textSize = "35sp"
        android:layout_marginTop="10dp"
        android:layout_below = "@+id/textView1"
        android:layout_centerHorizontal = "true" />

    <ImageView
        android:layout_width="350dp"
        android:layout_height="300dp"
        android:id="@+id/imageView"
        android:src="@drawable/kenya"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:id = "@+id/login_input_regNo"
        android:hint=   "@string/hint_regNo"
        android:focusable = "true"
        android:textColorHighlight = "#ff7eff15"
        android:textColorHint = "#ffff25e6"
        android:layout_marginTop = "30dp"
        android:layout_below = "@+id/imageView"
        android:layout_alignParentLeft = "true"
        android:layout_alignParentStart = "true"
        android:layout_alignParentRight = "true"
        android:layout_alignParentEnd = "true" />


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/login_input_password"
        android:layout_below="@+id/login_input_regNo"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/login_input_regNo"
        android:layout_alignEnd="@+id/login_input_regNo"
        android:textColorHint="#ffff299f"
        android:hint="@string/hint_password" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/attempts"
        android:id="@+id/textView2"
        android:layout_below="@+id/login_input_password"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textSize="25sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textView3"
        android:layout_alignTop="@+id/textView2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignBottom="@+id/textView2"
        android:layout_toEndOf="@+id/textView2"
        android:textSize="25sp"
        android:layout_toRightOf="@+id/textView2"
        android:layout_marginStart="50dp"
        android:layout_marginLeft="50dp"/>


    <Button android:id="@+id/btn_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_login"
        android:layout_marginTop="30dp"
        android:layout_below="@+id/textView2"
        android:textColor="@android:color/black"
        android:layout_marginStart="50dp"
        android:layout_marginLeft="50dp"/>

    <Button android:id="@+id/btn_link_signup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_sign_up"
        android:textColor="@android:color/black"
        android:layout_toRightOf="@+id/textView2"
        android:layout_toEndOf="@+id/textView2"
        android:layout_below="@id/textView3"
        android:layout_marginTop="30dp"
        android:layout_marginStart="70dp"
        android:layout_marginLeft="50dp"/>
</RelativeLayout>

</ScrollView>
kihiuFrank
  • 69
  • 1
  • 10

3 Answers3

2

If you see your log clearly then you will find the exception:

Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path)

That means the image you are providing may be in different drawble folder for ex drawable-v24(only for api>=24, but not for api<24) that's why your app is unable to find that image, so you need to copy that image to your drawable folder, to do this first you have to open project view structure then go through:

Project->app->src->main->res-> here you will see different drawable folder

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
0
  <ImageView
    android:layout_width="350dp"
    android:layout_height="300dp"
    android:id="@+id/imageView"
    android:src="@drawable/kenya"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true" />

In this code block, please check kenya is in drawable folders. Because in stacktrace that Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060058 a=-1 r=0x7f060058}

-1

You need to change android:src to app:srcCompat. Also take a look to this question: Android: What is the difference between app:srcCompat=" " and android:src=" "?

Fely
  • 38
  • 8