Soru & Cevap

Android Studio android.view.InflateException

17.11.2014 - 03:06

Merhaba ;

Navigation draver kullanarak bir uygulama geliştirmek istiyorum ancak şöyle bir hata alıyorum.

11-17 11:57:20.689      860-860/com.readknit E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.readknit/com.readknit.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class android.widget.ListView
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            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:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.widget.ListView
            at android.view.LayoutInflater.createView(LayoutInflater.java:613)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            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 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
            at android.app.Activity.setContentView(Activity.java:1867)
            at com.readknit.MainActivity.onCreate(MainActivity.java:51)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            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:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            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 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
            at android.app.Activity.setContentView(Activity.java:1867)
            at com.readknit.MainActivity.onCreate(MainActivity.java:51)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            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:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            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=0x7f070033 a=-1 r=0x7f070033}
            at android.content.res.Resources.loadDrawable(Resources.java:1892)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
            at android.view.View.<init>(View.java:3336)
            at android.view.ViewGroup.<init>(ViewGroup.java:427)
            at android.widget.AdapterView.<init>(AdapterView.java:235)
            at android.widget.AbsListView.<init>(AbsListView.java:758)
            at android.widget.ListView.<init>(ListView.java:141)
            at android.widget.ListView.<init>(ListView.java:137)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            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 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
            at android.app.Activity.setContentView(Activity.java:1867)
            at com.readknit.MainActivity.onCreate(MainActivity.java:51)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            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:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
11-17 12:02:20.838      860-860/com.readknit I/Process﹕ Sending signal. PID: 860 SIG: 9

Main Activity Class' ım;

package com.readknit;

import java.util.ArrayList;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.SearchManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SearchView;

import com.readknit.com.readknit.navigation.NavDrawerItem;
import com.readknit.com.readknit.navigation.NavDrawerListAdapter;

public class MainActivity extends Activity implements ActionBar.OnNavigationListener {
    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;
    static int mesaj_sayisi=5;//menüde gösterilecek olan mesaj sayısı
    static int bildirim_sayisi=7;//menüde gösterilecek olan bildirim sayısı
    private ActionBar actionBar;

    // navigasyon menü başlık
    private CharSequence mDrawerTitle;

    private CharSequence mTitle;

    // slide menu items
    private String[] menuList;
    private TypedArray menuIconList;
    private ArrayList<NavDrawerItem> menuItems;
    private NavDrawerListAdapter adapter;

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

        mTitle = mDrawerTitle = getTitle();//uygulama adı

        // slider menüitemlerini yüklüyoruz.
        menuList = getResources().getStringArray(R.array.menuList);

        //slider menü iconlarını arrayden çekiyoruz
        menuIconList = getResources().obtainTypedArray(R.array.menuIconList);


        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

        menuItems = new ArrayList<NavDrawerItem>();

        // arraylerden aldığımız değerleri NavDrawerItem e ekliyoruz
        // Anasayfa
        menuItems.add(new NavDrawerItem(menuList[0], menuIconList.getResourceId(0, -1)));
        // Profil
        menuItems.add(new NavDrawerItem(menuList[1], menuIconList.getResourceId(1, -1)));
        // Mesajlar
        menuItems.add(new NavDrawerItem(menuList[2], menuIconList.getResourceId(2, -1), true, ""+mesaj_sayisi));
        // Bildirimler
        menuItems.add(new NavDrawerItem(menuList[3], menuIconList.getResourceId(3, -1), true, ""+bildirim_sayisi));
        // Ayarlar
        menuItems.add(new NavDrawerItem(menuList[4], menuIconList.getResourceId(4, -1)));
        // çıkış
        menuItems.add(new NavDrawerItem(menuList[5], menuIconList.getResourceId(5, -1)));

        //menuList[x] menü adı
        //menuIconList.getResourceId(4, -1) //menü iconu
        //true counter yani mesaj bildirim saysının gösterip gösterilmeyeceği
        //mesaj sayisi veya bildirim sayısı


        mDrawerList.setOnItemClickListener(new SlideMenuClickListener());//menu Liste  Click listener ekliyoruz

        // setting the nav drawer list adapter
        adapter = new NavDrawerListAdapter(getApplicationContext(),menuItems);//adapter oluşturuyoruz

        mDrawerList.setAdapter(adapter); //adapteri set ediyoruz


       /* actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);*/

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_launcher,R.string.app_name, R.string.app_name)
        {//menü aılıp kapandığında action bar title değişimi
            public void onDrawerClosed(View view) { //acıkken uygulama adı gözükecek
                getActionBar().setTitle(mTitle);
                // calling onPrepareOptionsMenu() to show action bar icons
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {//kapalkıyken menü adı
                getActionBar().setTitle(mDrawerTitle);
                // calling onPrepareOptionsMenu() to hide action bar icons
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        if (savedInstanceState == null) {
            displayView(0); //ilk açılışta 0.menü seçile gelecek
        }

    }


    /**
     * Slide menu item click listener
     * */
    private class SlideMenuClickListener implements
            ListView.OnItemClickListener { //menü elemanlarına tıklanınca
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                                long id) {

            displayView(position); //diplayView methodu çağırılıyor
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // toggle nav drawer on selecting action bar app icon/title
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle action bar actions click
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }


    private void displayView(int position) { //gelen positiona göre ilgili fragmentı çağırıyor

        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = new Anasayfa();
                break;
            case 1:
                fragment = new Profil();
                break;
            case 2:
                fragment = new Mesajlar();
                break;
            case 3:
                fragment = new Bildirimler();
                break;
            case 4:

                fragment = new Ayarlar();
                break;
            case 5:
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
                alertDialogBuilder.setTitle(this.getTitle());
                alertDialogBuilder.setMessage("Çıkış Yap?");
                alertDialogBuilder.setPositiveButton("Evet",new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Intent startMain = new Intent(Intent.ACTION_MAIN);
                        startMain.addCategory(Intent.CATEGORY_HOME);
                        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(startMain);
                    }

                });

                alertDialogBuilder.setNegativeButton("Hayır",new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }

                });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
                break;

            default:
                break;
        }

        if (fragment != null) {//fragment boş değilse
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.frame_container, fragment).commit();

            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(menuList[position]);
            mDrawerLayout.closeDrawer(mDrawerList);

        } else {
            // error in creating fragment
            mDrawerLayout.closeDrawer(mDrawerList);
        }
    }

    @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getActionBar().setTitle(mTitle);
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        mDrawerToggle.onConfigurationChanged(newConfig);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {//search iconu ile ilgili ayar.

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_main_actions, menu);
        // Associate searchable configuration with the SearchView
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
                .getActionView();
        searchView.setSearchableInfo(searchManager
                .getSearchableInfo(getComponentName()));

        return super.onCreateOptionsMenu(menu);
    }
    @Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        // TODO Auto-generated method stub

        return false;
    }

    public void dataChanges(int i){//Mesaj sayısı veya bildirim sayısı değiştiğinde çağırılıyor
        int sayi=0;

        //Gelen i değerine göre sayi belirleniyor
        //i 2 ise mesaj 3 ise bildirim
        if(i==2){
            sayi = mesaj_sayisi;
        }else if(i==3){
            sayi = bildirim_sayisi;

        }
        menuItems.set(i, new NavDrawerItem(menuList[i], menuIconList.getResourceId(i, -1), true, ""+sayi));//menüdeki değer değiştiriliyor
        adapter.notifyDataSetChanged();//adapter basştan oluşturuluor.Yeni değerlere göre
    }

}

activity_main.xml ' im;

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Frame Layout to display fragments-->

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!-- Listview to display slider menu -->

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="80dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>

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

Konuyla ilgili yardımcı olabilirseniz çok memnun olurum.

Teşekkürler

İyi Çalışmalar.

8 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user KubraSel01
KubraSel01
10.12.2019 - 07:17

https://www.google.nl/search?hl=tr&source=hp&ei=u77vXb2iNemqrgSx7KvQAQ&q=how+to+make+navigation+drawer+android+studio&oq=how+to+make+navigation+drwaer+andr&gs_l=psy-ab.1.1.0i22i30l10.1560092.1567755..1569429...0.0..0.381.7791.0j13j14j7......0....1..gws-wiz.......0i131j0j0i19j0i13i30i19j0i22i30i19.vnBDDlmnSAw

konuyla ilgili bunlara bakabilirsiniz bu yöntemde hata alıyorsanız başka yöntemler deniyebilirsiniz