I have check out answers like thees Variable is accessed within inner class. Needs to be declared final but it does not address what I am after.
I'm using GraphView to plot retrieved data from Google Firebase. The data is supposed to be a continuous line like this :
But when I run the program, it goes on like this instead :
Here's my lines of code :
public class RetrieveApp extends AppCompatActivity {
Integer hrValue;
ArrayList<Integer> array2; //array to contain hrValue
private ListView mListView;
LineGraphSeries<DataPoint> series ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_retrieve_app);
GraphView graph = (GraphView)findViewById(R.id.graph);
series = new LineGraphSeries<DataPoint>();
DatabaseReference userdatabase = FirebaseDatabase.getInstance().getReference().child("Users");
auth = FirebaseAuth.getInstance();
user = auth.getCurrentUser();
DatabaseReference ref = userdatabase.child(user.getUid());
array2 = new ArrayList<>(); //array untuk hr
//RETRIEVE DATA HR VALUE
ref.child("hrvalue").child("nilaihr").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
hrValue = dataSnapshot.child("tmpHR").getValue(Integer.class);
showData(dataSnapshot);
double y,x ;
x = 0.0;
GraphView graph = (GraphView)findViewById(R.id.graph);
series = new LineGraphSeries<DataPoint>();
for (int i=0; i<1000; i++){
x = x+i;
y = hrValue;
series.appendData(new DataPoint(x, y), true, 1000);
}
graph.addSeries(series);
}
Everytime I try to move these two lines to onCreate,
GraphView graph = (GraphView)findViewById(R.id.graph);
series = new LineGraphSeries<DataPoint>();
The graph.addSeries(series)
line keeps on telling me :
Variable 'graph' is accessed from within inner class, needs to be declared final.
What should I do to address this problem? Any kind of help would be appreciated. Thank you!