Error initiating activity on Api 17

0

I have a code that is working perfectly in api 25, but when I squeeze it in api 17 it gives this error below:

03-25 13:26:59.750 1895-1895/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.demmy.demet.gerador/br.com.demmy.demet.gerador.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class ImageView
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:511)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                 at dalvik.system.NativeStart.main(Native Method)
                                              Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class ImageView
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                 at br.com.demmy.demet.gerador.MainActivity.onCreate(MainActivity.java:25)
                                                 at android.app.Activity.performCreate(Activity.java:5104)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                 at android.os.Looper.loop(Looper.java:137) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041) 
                                                 at java.lang.reflect.Method.invokeNative(Native Method) 
                                                 at java.lang.reflect.Method.invoke(Method.java:511) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                                                 at dalvik.system.NativeStart.main(Native Method) 
                                              Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020062
                                                 at android.content.res.Resources.getValue(Resources.java:1014)
                                                 at android.support.v7.widget.ResourcesWrapper.getValue(ResourcesWrapper.java:204)
                                                 at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:332)
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
                                                 at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
                                                 at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
                                                 at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)
                                                 at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:66)
                                                 at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
                                                 at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                 at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                 at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 
                                                 at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830) 
                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:736) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                 at br.com.demmy.demet.gerador.MainActivity.onCreate(MainActivity.java:25) 
                                                 at android.app.Activity.performCreate(Activity.java:5104) 
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                                                 at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                                                 at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                 at android.os.Looper.loop(Looper.java:137) 
                                                 at android.app.ActivityThread.main(ActivityThread.java:5041) 
                                                 at java.lang.reflect.Method.invokeNative(Native Method) 
                                                 at java.lang.reflect.Method.invoke(Method.java:511) 
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                                                 at dalvik.system.NativeStart.main(Native Method) 

MainActivity.java

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    toggle.syncState();

    //coloca a tela principal dentro do fragment em tempo de execução
    FragmentTransaction ft2 = getSupportFragmentManager().beginTransaction();
    ft2.replace(R.id.frame_layout, new PrimeiroFragment()).commit();
    //--------------------------------------------------------------------------//

    final ArrayList<ItensDrawer> lista_menu = new ArrayList<>();
    lista_menu.add(new ItensDrawer("Início",R.drawable.ic_menu_send));
    lista_menu.add(new ItensDrawer("Notificações periódicas",R.drawable.ic_menu_gallery));
    lista_menu.add(new ItensDrawer("Visualizar notificações",R.drawable.ic_menu_camera));
    lista_menu.add(new ItensDrawer("Sair",R.drawable.ic_menu_manage));

    ItensAdapter itens_adapter = new ItensAdapter(this, lista_menu);
    ListView lista_drawer = (ListView)findViewById(R.id.left_drawer);
    lista_drawer.setAdapter(itens_adapter);
    lista_drawer.setOnItemClickListener(new AdapterView.OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            if (position == 0){
                ft.replace(R.id.frame_layout, new PrimeiroFragment()).commit();
            }else if(position == 1){
                ft.replace(R.id.frame_layout, new SegundoFragment()).commit();
            }else if(position == 2){
                ft.replace(R.id.frame_layout, new TerceiroFragment()).commit();
            }else if(position == 3) {
                finish();
            }
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            drawer.closeDrawer(GravityCompat.START);
        }
    });
}

ItemsAdapter.java

public class ItensAdapter extends ArrayAdapter<ItensDrawer> {

private int mColorResourceId;

public ItensAdapter(Activity context, ArrayList<ItensDrawer> iten_drawer) {
    // Here, we initialize the ArrayAdapter's internal storage for the context and the list.
    // the second argument is used when the ArrayAdapter is populating a single TextView.
    // Because this is a custom adapter for two TextViews and an ImageView, the adapter is not
    // going to use this second argument, so it can be any value. Here, we used 0.
    super(context,0, iten_drawer);
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Check if the existing view is being reused, otherwise inflate the view
    View listItemView = convertView;
    if(listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(
                R.layout.list_item, parent, false);
    }

    ItensDrawer itens_adapter = getItem(position);

    ImageView imagem_drawer = (ImageView) listItemView.findViewById(R.id.imageView);
    imagem_drawer.setImageResource(itens_adapter.getId_imagem());

    TextView numberTextView = (TextView) listItemView.findViewById(R.id.textView);
    numberTextView.setText(itens_adapter.getTitulo());

    return listItemView;
}

}

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout        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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#ffffff"
android:dividerHeight="2dp"
android:background="#000000"/>


</android.support.v4.widget.DrawerLayout>

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
tools:context="br.com.demmy.demet.gerador.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="25dp">
            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="wrap_content"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"
                android:contentDescription="Logo"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/logo"
                tools:ignore="ContentDescription" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

Content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/frame_layout"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="br.com.demmy.demet.gerador.MainActivity"
tools:showIn="@layout/app_bar_main">
</FrameLayout>
    
asked by anonymous 25.03.2017 / 14:39

0 answers