problem with vectors in android studio

Asked

Viewed 259 times

4

I’m having trouble inserting vectors in android studio

my project was created in api21 (5.0), I am testing on a 7.0 device and this is all ok , working perfectly, but an error occurred when running the app on a 5.1 and 6.0 device


       --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.john.oftalmovet, PID: 6802
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.john.oftalmovet/com.example.john.oftalmovet.Login.Inicio_Login}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5443)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
                      at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103)
                   Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                      at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
                      at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:337)
                      at android.view.LayoutInflater.inflate()
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at com.example.john.oftalmovet.Login.Fragmentos.Fragment_Login.onCreateView(Fragment_Login.java:45)
                      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
                      at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
                      at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
                      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
                      at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
                      at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
                      at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
                      at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560)
                      at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1260)
                      at android.app.Activity.performStart(Activity.java:6261)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5443) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
                      at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103) 
                   Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                      at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method) 
                      at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:337) 
                      at android.view.LayoutInflater.inflate() 
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                      at com.example.john.oftalmovet.Login.Fragmentos.Fragment_Login.onCreateView(Fragment_Login.java:45) 
                      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354) 
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419) 
                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740) 
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809) 
                      at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799) 
                      at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580) 
                      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367) 
                      at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322) 
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229) 
                      at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221) 
                      at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171) 
                      at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192) 
                      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560) 
                      at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177) 
                      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1260) 
                      at android.app.Activity.performStart(Activity.java:6261) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5443) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
                      at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103) 
                   Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.john.oftalmovet:drawable/ico_email" (7f07007d) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f07007d a=2 r=0x7f07007d}
                      at android.content.res.Resources.loadDrawableForCookie(Resources.java:2605)
                    at android.content.res.Resources.loadDrawable(Resources.
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'

when I remove this xml vector, the app works perfectly , but when adding it , the error comes back to appear, I’ve been looking at the documentation but nothing solved my problem

this image is linked to a Fragment

As requested, the fragment_login code


public class Fragment_Login extends Fragment {

    private EditText Usuario;
    private EditText Senha;
    private Button btn_logar;
    private Context context;
    private int pagina = 2;

    private ProgressDialog progressDialog;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.login_fragmento_login, container, false);

        initVars(view);
        initActions();

        return view;
    }


    private void initVars(View view) {
        Usuario = view.findViewById(R.id.login_frag_login_et_usuario);
        Senha = (EditText) view.findViewById(R.id.login_frag_login_et_senha);
        btn_logar = (Button) view.findViewById(R.id.login_frag_login_btn_login);

        context = getActivity();
    }

    private void initActions() {

        btn_logar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                boolean conn = ToolBox.ChecaConexao(getContext()); // função para checar a conexao antes
                if (conn == true) {

                    String senhaSha1 = null;
                    try {
                        senhaSha1 = ToolBox.Convert_To_SHA1(Senha.getText().toString().trim());
                    } catch (NoSuchAlgorithmException e) {
                        e.printStackTrace();
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }

                    final String usuario = Usuario.getText().toString().trim();
                    final String senha = senhaSha1;

                    String Dados_Para_URL_GET = null;
                    Map Dados_Para_Parametros = new HashMap();

                    Dados_Para_URL_GET = "";
                    Dados_Para_Parametros = null;

                    Log.w("Dados Do Usuario", usuario + " : " + Senha.getText().toString().trim());

                    SharedPreferences prefs = context.getSharedPreferences("Tmp_ID", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putString("User", usuario);
                    editor.putString("Senha", senha);
                    editor.commit();

                    Dados_Ws(pagina, Dados_Para_URL_GET, Dados_Para_Parametros, context);


                } else {
                    ToolBox.ExibeMSG(getResources().getString(R.string.global_toast_sem_conexao), context);

                }





//                ToolBox.ExibeMSG(senha,context);
//                ToolBox.ExibeMSG(usuario + " " + senha,context);
//                Intent pagina_usuario = new Intent(context, Pagina_Usuario.class);
//                context.startActivity(pagina_usuario);
//                getActivity().finish();

            }
        });

    }


}

login_activity_login.xml

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <ImageView android:id="@+id/imgvw" android:layout_width="150dp" android:layout_height="150dp" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:src="@drawable/logo" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/imgvw" android:layout_marginBottom="15dp" android:gravity="top|center" android:text="@string/app_name" android:textColor="@color/Preto" android:textSize="30dp" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="40dp" android:layout_height="30dp" android:layout_gravity="center" android:layout_marginRight="5dp" android:src="@drawable/ico_email" /> <EditText android:id="@+id/login_frag_login_et_usuario" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/tela_login_fragmento_login_et_email" android:inputType="text"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="40dp" android:layout_height="30dp" android:layout_gravity="center" android:layout_marginRight="5dp" android:src="@drawable/ico_pass" /> <EditText android:id="@+id/login_frag_login_et_senha" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/tela_login_fragmento_login_et_pass" android:imeActionId="6" android:imeActionLabel="@string/tela_login_fragmento_login_et_pass" android:imeOptions="actionUnspecified" android:inputType="textPassword" android:maxLines="1" android:singleLine="true" android:text="123" /> </LinearLayout> <Button android:id="@+id/login_frag_login_btn_login" style="?android:textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="@string/tela_login_fragmento_login_btn_login" android:textStyle="bold" />

  • 1

    We need the Fragment code.

  • 1

    Put the code of the Fragment "Fragment_login", the problem is in it

  • @Wotonsampaio code added

  • @itscorey code added

1 answer

0

I have no points to comment on

If your app targets only SDK 21+, make sure to put your vectors inside the folder drawable or drawable-v21. I suspect that the vector xml is in a folder for another version, for example drawable-v24.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.