2013-12-03 4 views
-3
public View getView(final int position, View convertView, ViewGroup parent) 
     { 

      LayoutInflater inflater=cntx.getLayoutInflater(); 
      View row = inflater.inflate(R.layout.simplerow, null); 
      // row=inflater.inflate(R.layout.simplerow, parent, false); 

      DecimalFormat df = new DecimalFormat("#.##"); 
      final TextView title = (TextView)row.findViewById(android.R.id.title); 
      TextView tvcol1 = (TextView)row.findViewById(R.id.colortext01); 


      TextView gt  = (TextView)row.findViewById(R.id.text01); 


      tvcol1.setHeight(grossheight[position]); 

      title.setText(datelabel[position]); 


      gt.setText(df.format(grossSal[position])+" /-"); 

return row; 
     } 

LogCat @Получение NullPointerException при использовании bsAdapter.getView()

java.lang.NullPointerException 
     at com.pawan.my2dchart1.MyChart$bsAdapter.getView(MyChart.java:109) 
     at com.pawan.my2dchart1.HorizontalListView.fillListRight(HorizontalListView.java:239) 
     at com.pawan.my2dchart1.HorizontalListView.fillList(HorizontalListView.java:224) 
     at com.pawan.my2dchart1.HorizontalListView.onLayout(HorizontalListView.java:201) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 
     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660) 
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1436) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
     at android.widget.ScrollView.onLayout(ScrollView.java:1459) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
     at android.view.View.layout(View.java:14289) 
     at android.view.ViewGroup.layout(ViewGroup.java:4562) 
     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976) 
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730) 
     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004) 
     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481) 
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 
     at android.view.Choreographer.doCallbacks(Choreographer.java:562) 
     at android.view.Choreographer.doFrame(Choreographer.java:532) 
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 
     at android.os.Handler.handleCallback(Handler.java:730) 
     at android.os.Handler.dispatchMessage(Handler.java:92) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5103) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
     at dalvik.system.NativeStart.main(Native Method) 
+1

Было бы неплохо узнать, что такое линия 109! – MalaKa

+1

Ваша простая строка содержит: (android.R.id.title) ;? – Unii

+0

Строка 109: title.setText (datelabel [position]); – user3061408

ответ

0

попробуйте этот код

@Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     if (convertView == null) { 
      View listView = new View(c); 
      LayoutInflater inflater; 
      listView = inflater.inflate(R.layout.simplerow,null); 
     } else 
      listView = (View) convertView; 

     DecimalFormat df = new DecimalFormat("#.##"); 
     final TextView title = (TextView)row.findViewById(R.id.title); 
     TextView tvcol1 = (TextView)row.findViewById(R.id.colortext01); 
     TextView gt  = (TextView)row.findViewById(R.id.text01); 
     tvcol1.setHeight(grossheight[position]); 
     title.setText(datelabel[position]); 
     gt.setText(df.format(grossSal[position])+" /-"); 
     return listView; 
    } 
0

Так как вы говорите (в комментариях на вопрос в), что NullPointerException произошло на линии title.setText(datelabel[position]);, есть 2 возможных источника, которые могут вызвать эту ошибку.

Возможная причина 1: В TextView имени title является null. Это может произойти только в вашем случае, только если вы раздуваете неправильный макет (что означает макет, который не содержит TextView с идентификатором R.id.title). Таким образом, решение было бы проверить, содержит ли R.layout.simplerowTextView с идентификатором R.id.title.

Возможная причина 2:datelabel массив может быть null, поэтому убедитесь, что вы начать его правильно.

Просто обратите внимание, что это будет огромная модернизация производительности, если вы используете шаблон View Holder в своем обычном Adapter. См. here для получения дополнительной информации.

Смежные вопросы