I am using jjoe64.graphview.GraphView library for plotting graph.
I am appending some data from firebase database but it is showing me error.
here is my code:
FirebaseDatabase realdata = FirebaseDatabase.getInstance();
DatabaseReference real = realdata.getReference("weight");
ValueEventListener workplz = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//point value=62,pointvalue1=76
pointValue = Integer.parseInt(String.valueOf(dataSnapshot.child("currentweight").getValue()));
pointValue1 = Integer.parseInt(String.valueOf(dataSnapshot.child("goalweight").getValue()));
Log.i("xValue", String.valueOf(pointValue));
Log.i("yValue", String.valueOf(pointValue1));
valuedata = Double.parseDouble(String.valueOf(dataSnapshot.child("currentweight").getValue()));
hello();
}
public void onCancelled(@NonNull DatabaseError databaseError) {
}};
real.addValueEventListener(workplz);
GraphView graph = findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[]{
new DataPoint(0, 1),
new DataPoint(1, 5),
new DataPoint(2, 3)
});
graph.addSeries(series);
graph.getViewport().setXAxisBoundsManual(true);
graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setMinY(0);
graph.getViewport().setMaxY(200);
graph.getViewport().setMaxX(0);
graph.getViewport().setMaxX(200);
//appending data
series.appendData(new DataPoint(pointValue, pointValue1), true, 200);
While running the app i am getting this error .
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at com.example.itsandpro.Signup.GraphActivity.onCreate(GraphActivity.java:97)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
i want to add those two values to the graph.I also tried to use those values in double but still the error is same like:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference
at com.example.itsandpro.Signup.GraphActivity.onCreate(GraphActivity.java:85)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)