Soru & Cevap

Hashcode null object

11.08.2016 - 10:19

Merhaba arkadaşlar

Veritabanına veri ekleyip baseadapter kullanarak bir listviewde listeliyorum fakat bikaç tane ekledikten sonra hashcode null object reference hatası alıyorum .

public class OzelAdaptor extends BaseAdapter {
    Context c;
    degiskenler d1=new degiskenler();

    LayoutInflater layoutInflater;
    List<kitapsinifi> list;

    public OzelAdaptor(Activity activity, List<kitapsinifi> mList) {
        layoutInflater=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        list=mList;
    }
    public OzelAdaptor(Context applicationContext, List<kitapsinifi> listkitaplar) {
        list=listkitaplar;
        layoutInflater=(LayoutInflater)applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return (long)getItem(position).hashCode();
    }
   
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        View view=layoutInflater.inflate(R.layout.ornektasarim,null);

        final ImageView iv=(ImageView)view.findViewById(R.id.imageViewdizi);
        final TextView text1=(TextView)view.findViewById(R.id.textViewad);
        final TextView text2=(TextView)view.findViewById(R.id.tv_yazar);
        final TextView text3=(TextView)view.findViewById(R.id.tv_yayinevi);


        kitapsinifi kitap =list.get(position);

        String ad=kitap.getKitapad();
        String yazar=kitap.getKitapyazar();
        String yayinevi=kitap.getKitapyayinevi();






            switch (ad)
            {
                case "Elektronik":
                    Picasso.with(view.getContext()).load(d1.url_elektronikhobi).into(iv);
                    yazar=("Güclü Tuğay");
                    yayinevi=("ALFA YAYINLARI");
                    break;
              


                default:break;


            }


             text1.setText(ad);
             text2.setText(yazar);
             text3.setText(yayinevi);



        return view;
    }


}

 

27 Görüntülenme

3 Cevap

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

Profile picture for user enes-byc
enes-byc
13.08.2016 - 09:52
 java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
                                                                            at bycsoftware.kitaplik_1.OzelAdaptor.getView(OzelAdaptor.java:78)
                                                                            at android.widget.AbsListView.obtainView(AbsListView.java:2937)
                                                                            at android.widget.ListView.measureHeightOfChildren(ListView.java:1305)
                                                                            at android.widget.ListView.onMeasure(ListView.java:1212)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
                                                                            at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
                                                                            at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1079)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
                                                                            at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                            at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
                                                                            at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
                                                                            at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
                                                                            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
                                                                            at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
                                                                            at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
                                                                            at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                                                                            at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3083)
                                                                            at android.view.View.measure(View.java:20214)
                                                                            at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2683)
                                                                            at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1636)
                                                                            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1928)
                                                                            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1524)
                                                                            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7520)
                                                                            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                                                                            at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                            at android.view.Choreographer.doFrame(Choreographer.java:622)
                                                                            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                                                                            at android.os.Handler.handleCallback(Handler.java:739)

 

picture-9626-1398797004.jpg
bakiabaci
12.08.2016 - 09:38

Merhaba Enes,

Aldığın hata galiba bu kodlarla alakalı değil. Debug'da sana fırlatan hatayı ve o hata içerisindeki ilgili class kodlarını görebilirsek sana yardımcı olmaya çalışırız.

İyi çalışmalar.

picture-30491-1565085904.jpg
serhatleventyavas
12.08.2016 - 01:56

Dostum debug islemi uyguladın mı tam olarak nerede hatayı fırlatıyor kod nereye kadar geliyor orayı inceledin mi. Eğer incelediysen bizi aydınlatırsan sevinirim ona göre çözüm bulabiliriz. Eğer böyle birşey yapmadıysan lütfen yap çözümü daha kolay bulabiliriz