Error in jjoe64 GraphView Library

≯℡__Kan透↙ 提交于 2019-12-25 18:39:20

问题


someone can help me? I found this error and I can't find the resolution to my problem. This is the Android Error:

09-15 18:26:47.434 3096-3096/com.example.user.navigationdrawer E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.user.navigationdrawer, PID: 3096
  java.lang.IllegalArgumentException: new x-value must be greater then the last value. x-values has to be ordered in ASC.
  at com.jjoe64.graphview.series.BaseSeries.appendData(BaseSeries.java:388)
  at com.example.user.navigationdrawer.SeventhFragment$1.onDataChange(SeventhFragment.java:75)
  at com.firebase.client.Query$1.onDataChange(Query.java:158)
  at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45)
  at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
  at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

And This is my code:

package com.example.user.navigationdrawer;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.BarGraphSeries;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.series.Series;

public class SeventhFragment extends Fragment{

GraphView graphView;
FirebaseAuth auth;
FirebaseUser user;
Firebase mRef;
LineGraphSeries<DataPoint> series;

View myView;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    myView = inflater.inflate(R.layout.seventh_layout, container, false);
    graphView = (GraphView) myView.findViewById(R.id.graph);

    auth = FirebaseAuth.getInstance();
    user = auth.getCurrentUser();

    if (user == null){
        Activity activity = getActivity();
        Toast.makeText(activity, "Per accedere a questa funzione devi aver effettuato il login.", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(activity, LoginActivity.class));
    }

    graphView.getViewport().setXAxisBoundsManual(true);
    graphView.getViewport().setMinX(0.0);
    graphView.getViewport().setMaxX(24);
    // set manual Y bounds
    graphView.getViewport().setYAxisBoundsManual(true);
    graphView.getViewport().setMinY(0.0);
    graphView.getViewport().setMaxY(2000);

    graphView.getViewport().setScrollable(true);

    series = new LineGraphSeries<DataPoint>();

    mRef = new Firebase("my url" );
    mRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            final double Valore = dataSnapshot.getValue(double.class);
            series.appendData(new DataPoint(1, Valore), false, 24); //what number must i write here?
        }@Override
        public void onCancelled(FirebaseError firebaseError) {
        }});

    mRef = new Firebase("my url" );
    mRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            final double Valore = dataSnapshot.getValue(double.class);
            series.appendData(new DataPoint(2, Valore), false, 25); //what number must i write here?
        }@Override
        public void onCancelled(FirebaseError firebaseError) {

        }});

    graphView.addSeries(series);
    return myView;
}}

I want to set in the graph the data i recived from FireBase but it gives me an error. I'm using the library: com.jjoe64:graphview:4.1.0' HELP!


回答1:


The listener callbacks are asynchronous. This means your call to graphView.addSeries(series) executes before the callbacks fire where you append the DataPoints to series.

For a detailed explanation, see this answer.




回答2:


ADD jar file as a library .It is indicating that you did not add GraphView Library in your project .



来源:https://stackoverflow.com/questions/39518283/error-in-jjoe64-graphview-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!