2016-11-17 3 views
0

私はsqliteから値をフェッチしたリストビューを持っています。sqliteからフェッチした値は、チェックする条件を使用したベースアダプタに格納されています文字列が値を持っているかいないが、それでも、それは私に私が条件でNOT NULLを追加しても、nullポインタ例外を示していますが、それはない作品でしたし、ここに私のコードです:sqliteデータベースからbaseadapterにアンドロイドでデータをロードする際にNULLポインタ例外を取得する

final Daybooklist m = daybooklists.get(position); 
    if (m.getUsertype().startsWith("farmer") && m.getUsertype() != null) { 
     day_name.setText(m.getName()); 
     day_description.setText(m.getDescription()); 
     day_type.setText(m.getType()); 
     if (m.getName().startsWith("no") && m.getName() != null) { 
      day_name.setText(" "); 
     } else if (m.getDescription().startsWith("no") && m.getDescription() != null) { 
      day_description.setText(" "); 
     } 
     day_amount.setText("\u20B9" + m.getAmountin()); 

    } else if (m.getUsertype().startsWith("advancefarmer") && m.getUsertype() != null) { 
     day_name.setText(m.getName()); 
     day_description.setText(m.getDescription()); 
     day_type.setText(m.getType()); 
     if (m.getName().startsWith("no") && m.getName() != null) { 
      day_name.setText(" "); 
     } else if (m.getDescription().startsWith("no") && m.getDescription() != null) { 
      day_description.setText(" "); 
     } 
     Log.e("amountout",m.getAmountout()); 
     day_amount.setText("\u20B9" + m.getAmountout()); 
    } else { 
     day_name.setText(m.getName()); 
     day_description.setText(m.getDescription()); 
     day_type.setText(m.getType()); 
     if (m.getName().startsWith("no") && m.getName()!=null) { 
      day_name.setText(" "); 
     } else if (m.getDescription().startsWith("no") && m.getDescription() != null) { 
      day_description.setText(" "); 
     } 
     Log.e("amountout",m.getAmountout()); 
     day_amount.setText("\u20B9" + m.getAmountout()); 

    } 

例外:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference 
                    at codingtown.coconut.daybook.adapter.Daybooklist_adapter.getView(Daybooklist_adapter.java:96) 
                    at android.widget.AbsListView.obtainView(AbsListView.java:2360) 
                    at android.widget.ListView.measureHeightOfChildren(ListView.java:1270) 
                    at android.widget.ListView.onMeasure(ListView.java:1182) 
                    at codingtown.coconut.libraries.expandablelistview.ExpandableHeightListView.onMeasure(ExpandableHeightListView.java:34) 
+0

"m"変数には問題がありません。ヌルオブジェクトを返すm.getUsertype()。 Daybooklistを適切に設定し、UserTypeを適切に割り当てるかどうかを確認します。if(m.getUsertype()!= null && m.getUsertype()。startsWith( "farmer"))。ナルチェックは決して実行されません。 – Naeem

答えて

0

このようなコードを変更します

if(m.getUsertype() != null && !m.getUsertype().isEmpty()) { 


if (m.getUsertype().startsWith("farmer") 
{ 
} 
else if (m.getUsertype().startsWith("advancefarmer") 
{ 
} 
.... 
} 
+0

if(m.getUsertype()!= null &&!m.getUsertype()。isEmpty()){'の代わりに' if(!TextUtils.isEmpty(m.getUsertype()){ – SleepyTonic

関連する問題