It always say NullPointerException. Thank you

This is my code:

my OnCreate Method

 //region transpo
    
mRef.orderByChild("expensetitle").equalTo("Transportation").addValueEventListener(new
 ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //String transpo = 
String.valueOf(dataSnapshot.child("expensetitle").getValue());
            GenericTypeIndicator<HashMap<String, ExpenseData>> t = new 
GenericTypeIndicator<HashMap<String, ExpenseData>>() {
            };
            HashMap<String, ExpenseData> expenses = dataSnapshot.getValue(t);

            // Loop through it to get the sum
            double sum = 0;
            for (HashMap.Entry<String, ExpenseData> entry : 
expenses.entrySet()) {
                sum += entry.getValue().getAmount();

            }
            // You have your sum now
            txt3.setText(String.valueOf(sum));
           getTrans = Double.parseDouble(txt3.getText().toString());



        }


        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    //endregion


    openChart();

}


MyChart method:


 private void openChart() {



        // Pie Chart Section Names
        String[] code = new String[] { "Froyo", "Gingerbread",
                "IceCream Sandwich", "Jelly Bean", "KitKat" };

        // Pie Chart Section Value
        double[] distribution = { getTrans, 9.1, 7.8, 45.5, 33.9 };

        // Color of each Pie Chart Sections
        int[] colors = { Color.BLUE, Color.MAGENTA, Color.GREEN, Color.CYAN,
                Color.RED };

        // Instantiating CategorySeries to plot Pie Chart
        CategorySeries distributionSeries = new CategorySeries(
                " Android version distribution as on October 1, 2012");
        for (int i = 0; i < distribution.length; i++) {
            // Adding a slice with its values and name to the Pie Chart
            distributionSeries.add(code[i], distribution[i]);
        }

        // Instantiating a renderer for the Pie Chart
        DefaultRenderer defaultRenderer = new DefaultRenderer();
        for (int i = 0; i < distribution.length; i++) {
            SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
            seriesRenderer.setColor(colors[i]);
            seriesRenderer.setDisplayChartValues(true);
//Adding colors to the chart
            defaultRenderer.setBackgroundColor(Color.BLACK);
            defaultRenderer.setApplyBackgroundColor(true);
            // Adding a renderer for a slice
            defaultRenderer.addSeriesRenderer(seriesRenderer);
        }

        defaultRenderer
                .setChartTitle("Android version distribution as on December 1, 
2014. ");
        defaultRenderer.setChartTitleTextSize(20);
        defaultRenderer.setZoomButtonsVisible(false);

        LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart);
        // remove any views before u paint the chart
        chartContainer.removeAllViews();
        // drawing pie chart
        mChart = ChartFactory.getPieChartView(getBaseContext(),
                distributionSeries, defaultRenderer);
        // adding the view to the linearlayout
        chartContainer.addView(mChart);

    }

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/bc8c3fed-a676-42d9-adc5-95b6b04bda72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to