PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.53k stars 9.01k forks source link

Error inflating class com.github.mikephil.charting.charts.LineChart #5241

Open fllaryora opened 2 years ago

fllaryora commented 2 years ago

Summary I am having E/AndroidRuntime: FATAL EXCEPTION Caused by: android.view.InflateException Caused by: java.lang.reflect.InvocationTargetException

Expected Behavior This only happen when I am inflating a xml for a PDF . (it is using a background thread). When It inflates the view normally that crash behavior does not happen (it is using the ui thread).

Device (please complete the following information):

Additional Context `E/AndroidRuntime: FATAL EXCEPTION: pool-10-thread-1 Process: com.intecanar.ondiet, PID: 17468 android.view.InflateException: Binary XML file line #7 in com.intecanar.ondiet:layout/pdf_chart: Binary XML file line #7 in com.intecanar.ondiet:layout/pdf_chart: Error inflating class com.github.mikephil.charting.charts.LineChart Caused by: android.view.InflateException: Binary XML file line #7 in com.intecanar.ondiet:layout/pdf_chart: Error inflating class com.github.mikephil.charting.charts.LineChart Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:852) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082) at android.view.LayoutInflater.inflate(LayoutInflater.java:680) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at android.view.LayoutInflater.inflate(LayoutInflater.java:479)

 Caused by: java.lang.RuntimeException: Can't create handler inside thread Thread[pool-10-thread-1,5,main] that has not called Looper.prepare()
    at android.os.Handler.<init>(Handler.java:227)
    at android.os.Handler.<init>(Handler.java:129)
    at android.view.GestureDetector$GestureHandler.<init>(GestureDetector.java:306)
    at android.view.GestureDetector.<init>(GestureDetector.java:419)
    at android.view.GestureDetector.<init>(GestureDetector.java:397)
    at com.github.mikephil.charting.listener.ChartTouchListener.<init>(ChartTouchListener.java:56)
    at com.github.mikephil.charting.listener.BarLineChartTouchListener.<init>(BarLineChartTouchListener.java:87)
    at com.github.mikephil.charting.charts.BarLineChartBase.init(BarLineChartBase.java:168)
    at com.github.mikephil.charting.charts.LineChart.init(LineChart.java:32)
    at com.github.mikephil.charting.charts.Chart.<init>(Chart.java:192)
    at com.github.mikephil.charting.charts.BarLineChartBase.<init>(BarLineChartBase.java:144)
    at com.github.mikephil.charting.charts.LineChart.<init>(LineChart.java:23)
    at java.lang.reflect.Constructor.newInstance0(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:852) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121) 
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:680) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:532) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:479) 
fllaryora commented 2 years ago

The chart was thought to be used for UI thead only Caused by: java.lang.RuntimeException: Can't create handler inside thread Thread[pool-10-thread-1,5,main] that has not called Looper.prepare() I think mGestureDetector = new GestureDetector(chart.getContext(), this); is failing here. I am going to think how deactivate this.