2015-12-22 1 views
0

У меня возникла проблема с примером пользовательского маркера, который я точно реплицировал и установил в своей Stacked Barchart, но когда я нажимаю на него, я получаю исключение.MPAndroidChart Stacked BarChart Custom Markerview Исключение Nullpointer

Код в точности такой же, как example.

Исключение я получаю выглядит следующим образом:

12-22 15:28:54.052 12901-12901/? E/AndroidRuntime: FATAL EXCEPTION: main 
               Process: com.myapp.myapp, PID: 12901 
               java.lang.NullPointerException: Attempt to read from field 'float com.github.mikephil.charting.highlight.Range.to' on a null object reference 
                at com.github.mikephil.charting.charts.BarLineChartBase.getMarkerPosition(BarLineChartBase.java:571) 
                at com.github.mikephil.charting.charts.Chart.drawMarkers(Chart.java:598) 
                at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:252) 
                at android.view.View.draw(View.java:15114) 
                at android.view.View.updateDisplayListIfDirty(View.java:14048) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.draw(View.java:15117) 
                at android.support.v4.view.ViewPager.draw(ViewPager.java:2262) 
                at android.view.View.updateDisplayListIfDirty(View.java:14048) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1229) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1077) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
                at android.view.ViewGroup.drawChild(ViewGroup.java:3404) 
                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198) 
                at android.view.View.updateDisplayListIfDirty(View.java:14043) 
                at android.view.View.getDisplayList(View.java:14071) 
                at android.view.View.draw(View.java:14838) 
               at android.view. 

Кто-то имеет какие-либо идеи?

EDIT

Так что это onValueSelected(..).

@Override 
    public void onValueSelected(Entry e, int dataSetIndex, Highlight h) { 
     barChart.highlightValue(e.getXIndex(), dataSetIndex); 
    } 
+0

Разместите ява код мыши. – Beena

+0

Я разместил 'onValueSelected (..)' @Beena –

+0

, что вы не инициализировали объект barChart –

ответ

1

Было бы хорошо, чтобы в любом случае проверить, если Entry равно нулю, как это показано в примере Stacked BarChart.

Это код из примера:

@Override 
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) { 

    BarEntry entry = (BarEntry) e; 

    if (entry.getVals() != null) 
     Log.i("VAL SELECTED", "Value: " + entry.getVals()[h.getStackIndex()]); 
    else 
     Log.i("VAL SELECTED", "Value: " + entry.getVal()); 
} 

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

  • Нет связанных вопросов^_^