AnyChart-Android icon indicating copy to clipboard operation
AnyChart-Android copied to clipboard

Cannot run GetStarted's Code - Null Object Reference Exception Thrown

Open marina07 opened this issue 6 years ago • 1 comments

When running the code provided on Github for getting started , as well as others found on the Internet, an exception is thrown: Process: com.example.savingstrackerapp, PID: 12965 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mpereira.savingstrackerapp/com.mpereira.savingstrackerapp.Activities.TestActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.anychart.AnyChartView$JsListener com.anychart.AnyChartView.getJsListener()' on a null object reference More details on https://stackoverflow.com/questions/59025210/why-is-anychart-returning-null-object-reference-exception.

marina07 avatar Nov 25 '19 20:11 marina07

@marina07 Check your XML (you are using relative layout), imports in the main activity, API level you are using, and make sure that you have added AnyChart library to Gradle correctly according to Gettings Started guide. Your main activity code is ok, I have successfully built a chart based on your code.

Here is the result: Screenshot 2019-11-26 at 10 55 15

The xml file content is the following:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.anychart.AnyChartView
        android:id="@+id/any_chart_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

Compare your xml with the one provided above.

Shestac92 avatar Nov 26 '19 03:11 Shestac92