Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot process converting csv file to arrays in android
    primarykey
    data
    text
    <p>I'm very very new to android &amp; JAVA, and I'm trying to learn writing android apps by myself. I met a problem when I was trying to read values from a csv file and plot them out. To be more specific, I was trying to modify Androidplot example.</p> <p>The original Androidplot example works, while my modified one never work...I tried to find the problem but I failed failed failed...Every time I tried to debug the codes, ActivityThread.java just pops out, and there's a little arrow pointing to the following codes:</p> <pre><code>catch (Exception e) { if (!mInstrumentation.onException(activity, e)) { throw new RuntimeException( "Unable to start activity " + component + ": " + e.toString(), e); } } </code></pre> <p>Can anybody tell me what the problem really is? Any help will be much appreciated =)</p> <p>Below is my modified codes:</p> <pre><code>package edu.ius.rwisman.AndroidPlotExample; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import com.androidplot.xy.SimpleXYSeries; import com.androidplot.series.XYSeries; import com.androidplot.xy.*; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.text.DecimalFormat; import java.util.Arrays; public class AndroidPlotExampleActivity extends Activity { private XYPlot mySimpleXYPlot; @SuppressWarnings("null") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Initialize our XYPlot reference: mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot); Number[] series1Numbers = null; Number[] series2Numbers = null; int row = 0; // Create two arrays of y-values to plot: try { File file = new File("/home/hanrui/workspace/table.csv"); BufferedReader reader = new BufferedReader(new FileReader(file)); reader.readLine(); String line = null; while((line=reader.readLine())!=null&amp;&amp;row&lt;24){ String item[] = line.split(","); String last = item[item.length-1]; int value = Integer.parseInt(last); series1Numbers[row] = value; series2Numbers[row] = value; row++; } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Turn the above arrays into XYSeries: XYSeries series1 = new SimpleXYSeries( Arrays.asList(series1Numbers), // SimpleXYSeries takes a List so turn our array into a List SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value "Series1"); // Set the display title of the series // Same as above, for series2 XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2"); // Create a formatter to use for drawing a series using LineAndPointRenderer: LineAndPointFormatter series1Format = new LineAndPointFormatter( Color.rgb(0, 200, 0), // line color Color.rgb(0, 100, 0), // point color Color.rgb(150, 190, 150)); // fill color (optional) // Add series1 to the xyplot: mySimpleXYPlot.addSeries(series1, series1Format); // Same as above, with series2: mySimpleXYPlot.addSeries(series2, new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), Color.rgb(150, 150, 190))); // Reduce the number of range labels mySimpleXYPlot.setTicksPerRangeLabel(3); // By default, AndroidPlot displays developer guides to aid in laying out your plot. // To get rid of them call disableAllMarkup(): mySimpleXYPlot.disableAllMarkup(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload