I've created two java files that read a .csv of results for a monthly fishing competition, but I'm stuck on getting it to display in an activity. I was thinking that I'd need to use an intent to pass the arraylist from the reader to another activity, but I'm not sure how to do this and what I've tried so far throws up unexpected end of decalration, no method or unknown variable or field errors.
the idea is to eventually get it into a table, but I'd just like to display something just now
Already tried
System.out.println
and variations on
Intent intent = getIntent();
intent.putStringArrayListExtra("OverallBoatCamp", OverallBoatChamp) test);
read about parcelable or serialiseable but one article mentioned arraylist is already serialiseable
tutorials I've come accross either are too basic just dealing with simple arrays, or don't say how to get this to display.
Code has no errors in AIDE and logcat shows csv is being read ok, with only a ARDT failed lock error. App runs and compiles fine but I just can't seem to get anything to display.
Code is:
BoatLeaderboard.java
import android.app.*;
import android.os.*;
import java.util.*;
import java.io.*;
import java.nio.charset.*;
import org.apache.http.impl.conn.*;
import android.util.*;
import android.content.*;
public class BoatLeaderboards extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.boatleaderboards);
getActionBar().setDisplayHomeAsUpEnabled(true);
readMatchData();
}
private List<OverallBoatChamp> boatchamplist = new ArrayList<>();
private void readMatchData(){
InputStream is = getResources().openRawResource(R.raw.boatl);
BufferedReader Reader = new BufferedReader(
new InputStreamReader (is, Charset.forName("UTF-8"))
);
String line = "";
try {
//Step over headers
Reader.readLine();
while ( (line = Reader.readLine()) != null) {
Log.d("BoatLeaderboards", "Line: " + line);
//Split by commas
String[] tokens = line.split(",");
//read the data
OverallBoatChamp champlist = new OverallBoatChamp();
champlist.setAngler(tokens[0]);
if (tokens.length >= 2 && tokens[1].length() > 0){
champlist.setOct(Integer.parseInt(tokens[1]));
} else {
champlist.setOct(0);
}
if (tokens.length >= 3 && tokens[2].length() > 0){
champlist.setNov(Integer.parseInt(tokens[2]));
} else {
champlist.setNov(0);
}
if (tokens.length >= 4 && tokens[3].length() > 0){
champlist.setDec(Integer.parseInt(tokens[3]));
} else {
champlist.setDec(0);
}
if (tokens.length >= 5 && tokens[4].length() > 0){
champlist.setJan(Integer.parseInt(tokens[4]));
} else {
champlist.setJan(0);
}
if (tokens.length >= 6 && tokens[5].length() > 0){
champlist.setFeb(Integer.parseInt(tokens[5]));
} else {
champlist.setFeb(0);
}
if (tokens.length >= 7 && tokens[6].length() > 0){
champlist.setMar(Integer.parseInt(tokens[6]));
} else {
champlist.setMar(0);
}
if (tokens.length >= 8 && tokens[7].length() > 0){
champlist.setApr(Integer.parseInt(tokens[7]));
} else {
champlist.setApr(0);
}
if (tokens.length >= 9 && tokens[8].length() > 0){
champlist.setMay(Integer.parseInt(tokens[8]));
} else {
champlist.setMay(0);
}
if (tokens.length >= 10 && tokens[9].length() > 0){
champlist.setJun(Integer.parseInt(tokens[9]));
} else {
champlist.setJun(0);
}
if (tokens.length >= 11 && tokens[10].length() > 0){
champlist.setJul(Integer.parseInt(tokens[10]));
} else {
champlist.setJul(0);
}
if (tokens.length >= 12 && tokens[11].length() > 0){
champlist.setAug(Integer.parseInt(tokens[11]));
} else {
champlist.setAug(0);
}
if (tokens.length >= 13 && tokens[12].length() > 0){
champlist.setSep(Integer.parseInt(tokens[12]));
} else {
champlist.setSep(0);
}
boatchamplist.add(champlist);
Log.d("BoatLeaderboards","Just created: " + champlist);
}
} catch (IOException e){
Log.wtf("BoatLeaderboards", "Error Reading Data File! on line" + line, e);
e.printStackTrace();
}
}
}
OverallBoatChamp.java
import org.xml.sax.ext.*;
public class OverallBoatChamp {
private String angler;
private int oct;
private int nov;
private int dec;
private int jan;
private int feb;
private int mar;
private int apr;
private int may;
private int jun;
private int jul;
private int aug;
private int sep;
public String getAngler() {
return angler;
}
public void setAngler(String angler){
this.angler = angler;
}
public int getOct() {
return oct;
}
public void setOct(int oct){
this.oct = oct;
}
public int getNov() {
return nov;
}
public void setNov(int nov){
this.nov = nov;
}
public int getDec() {
return dec;
}
public void setDec(int dec){
this.dec = dec;
}
public int getJan() {
return jan;
}
public void setJan(int jan){
this.jan = jan;
}
public int getFeb() {
return feb;
}
public void setFeb(int feb){
this.feb = feb;
}
public int getMar() {
return mar;
}
public void setMar(int mar){
this.mar = mar;
}
public int getApr() {
return apr;
}
public void setApr(int apr){
this.apr = apr;
}
public int getMay() {
return may;
}
public void setMay(int may){
this.may = may;
}
public int getJun() {
return jun;
}
public void setJun(int jun){
this.jun = jun;
}
public int getJul() {
return jul;
}
public void setJul(int jul){
this.jul = jul;
}
public int getAug() {
return aug;
}
public void setAug(int aug){
this.aug = aug;
}
public int getSep() {
return sep;
}
public void setSep(int sep){
this.sep = sep;
}
@Override
public String toString(){
return "OverallBoatChamp{" +
"Angler='" + angler + '\''+
", Oct=" + oct +
", Nov=" + nov +
", Dec=" + dec +
", Jan=" + jan +
", Feb=" + feb +
", Mar=" + mar +
", Apr=" + apr +
", May=" + may +
", Jun=" + jun +
", Jul=" + jul +
", Aug=" + aug +
", Sep=" + sep +
'}';
}
}