Android ProgressBar NPE

时间:2013-11-24 17:34:26

标签: android listview nullpointerexception

Ciao,stòcercandodi visualizzare una ProgressBar per ogni riga della listview。在questa riga di codice中加入NPE:mProgress.setProgress(0); 似乎没有找到ProgressBar。我在onCreate()中初始化了PreogressBar。谢谢你的帮助

ListAdapter adapter = new ArrayAdapter<Dettaglio>(this, R.layout.dettaglio, R.id.tv_totale_group, dettagli){

                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
                            View row = super.getView(position, convertView, parent);

                            TextView tvEn, tvCaa, tvPer;
                            tvEn = (TextView) row.findViewById(R.id.tv_to_group);
                            tvCaa = (TextView) row.findViewById(R.id.tv_cat_group);
                            tvPer = (TextView) row.findViewById(R.id.tv_perc_cat);    
                            ProgressBar mProgress;
                mProgress = (ProgressBar) findViewById(R.id.progress_e);
                            mProgress.setProgress(0);
                            mProgress.setMax(100);



                            Dettaglio d = dettagli.get(position);

                            tvCaa.setText(d.categorie+"");

                            double value = Double.valueOf(d.en);
                            NumberFormat formatter = NumberFormat.getCurrencyInstance();
                            String en = formatter.format(value );
                            tvEn.setText(en+"");

                            //percent-------------------------
                            double totaleE = 0;
                            for (Dettaglio c : dettagli){
                                    totaleE += c.en;
                            }

                            value = d.en / totaleE *100;                                    

                             DecimalFormat decimalFormat = new DecimalFormat("0.#");
                             String en1 = decimalFormat.format(value );   
                             tvPer.setText(en1+"%");

                             //----PROGRESS BAR----------------------------------------

                             int valore_per_barra = (int) Math.floor(value);

                            mProgress.setProgress(valore_per_barra);


                            return row;
                    }
            };

            lista.setAdapter(adapter);   

1 个答案:

答案 0 :(得分:0)

在listAdapter中初始化progressBar而不是oncreate