Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Resolve AppActivity Crash Issue On This Code and Barchart Not See?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 536
    Answer it

    Need a help in appactivity crash issue My code is:

    package wallet.ask.com.abcd;
    import android.app.ProgressDialog;
    import android.graphics.Color;
    import android.os.AsyncTask;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import com.github.mikephil.charting.charts.BarChart;
    import com.github.mikephil.charting.data.BarData;
    import com.github.mikephil.charting.data.BarDataSet;
    import com.github.mikephil.charting.data.BarEntry;
    import com.github.mikephil.charting.utils.ColorTemplate;
    import org.json.JSONArray;
    import org.json.JSONObject;
    import java.util.ArrayList;
    import java.util.List;
    
    public class MainActivity extends AppCompatActivity {
    String[] stringArray1, stringArray2;
    ArrayList<String> arrayListString1, arrayListString2;
    List<ChartPojo> list;
     ChartPojo object;
    ArrayList<BarEntry> valueSet1 = new ArrayList<>();
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            list = new ArrayList<ChartPojo>();
    
            new LoadDataAsyncTask().execute();
    
            arrayListString1 = new ArrayList<String>();
            arrayListString2 = new ArrayList<String>();
    
            stringArray1 = new String[arrayListString1.size()];
            stringArray2 = new String[arrayListString2.size()];
    
    
            BarChart chart = (BarChart) findViewById(R.id.chart);
    BarData data = new BarData(arrayListString1, getDataSet());
    
            chart.setData(data);
            chart.setDescription("My Chart");
            chart.animateXY(2000, 2000);
            chart.invalidate();
    
        }
     private ArrayList<BarDataSet> getDataSet() {
            ArrayList<BarDataSet> dataSets = null;
    
    BarEntry v1e1 = new BarEntry(new float[stringArray2.length], stringArray1.length); // Jan
            valueSet1.add(v1e1);
    
    BarDataSet barDataSet1 = new BarDataSet(valueSet1, "Brand 1");
            barDataSet1.setColor(Color.rgb(0, 155, 0));
    
            dataSets = new ArrayList<>();
            dataSets.add(barDataSet1);
            return dataSets;
    }
    private ArrayList<String> getXAxisValues() {
            ArrayList<String> xAxis = new ArrayList<>();
            xAxis.add("JAN");
            xAxis.add("FEB");
            xAxis.add("MAR");
            xAxis.add("APR");
            xAxis.add("MAY");
            xAxis.add("JUN");
            return xAxis;
        }
    class LoadDataAsyncTask extends AsyncTask<String, String, String> {
            private ProgressDialog dialog;
            String response = "";
            private JSONObject res;
            String runtime;
    
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                dialog = new ProgressDialog(MainActivity.this);
                dialog.setMessage("Please Wait..");
                dialog.setCancelable(false);
                dialog.show();
            }
    
            @Override
            protected String doInBackground(String... params) {
                try {
    
                    JSONObject vehicle_json = new JSONObject();
    
                    vehicle_json.put("pAccountId", "2");
                    vehicle_json.put("unitId", "160323132");
                    vehicle_json.put("startDate", "2017-07-22 11:23:12");
                    vehicle_json.put("endDate", "2017-07-29 11:23:12");
                    //  vehicle_json.put("minSpeed",speed);
    //                Log.d("stopstop123456", AccountId + " " + unitId + " " + fromDate + toDate);
    
    
                    res = CustomHttpClient.postJsonObject("http://", vehicle_json, MainActivity.this);
    
    
                    String resData = res.getString("ResponseData");
                    Log.d("stopstop12345", resData);
    //                JSONObject jres = new JSONObject(resData);
    
                    JSONArray array1 = new JSONArray(resData);
                    //JSONArray array=new JSONArray(array1.get(0).toString());
                    //JSONObject jobj=array1.get(0);
                    JSONArray array = new JSONArray(array1.get(0).toString());
    
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject jsonVehicleObj = new JSONObject(array.get(i).toString());
    
                        ChartPojo p = new ChartPojo();
    
                        p.setStrDate(jsonVehicleObj.getString("date"));
                        p.setStrDistance(jsonVehicleObj.getString("distance"));
                        p.setStrRunTime(jsonVehicleObj.getString("run_time"));
    
                        list.add(p);
    }
    
                } catch (Exception e) {
                    Log.d("errorrrr", e.toString());
                }
    for (int j = 0; j < list.size(); j++) {
    
                    object = list.get(j);
    arrayListString1.add(object.getStrDate());
     stringArray2 = arrayListString1.toArray(stringArray1);
    
       arrayListString2.add(object.getStrRunTime());
       stringArray2 = arrayListString2.toArray(stringArray2);
    }
                return response;
            }
    
            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }}
        }}

     

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: