I'm making a stock simulator app in java for and android phone. Im trying to get a csv file from a URL and parse the columns into different ArrayLists but it keeps crashing. I made a class for it and added 2 lines to the manifest since I thought that's what crashed it:
Permissions in my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
My code:
public class StockALLDownloader {
public static final String LOG_TAG = "com.example.someone.stocksimulator.StockALLDownloader";
String url = "https://api.iextrading.com/1.0/ref-data/symbols?format=csv";
private ArrayList<String> symbols;
private ArrayList<String> names;
public ArrayList<String> getSymbols() {
return symbols;
}
public ArrayList<String> getNames() {
return names;
}
public StockALLDownloader(){ //gets url and adds to the symbols and names arrays
try{
URL iexfin = new URL(url);
URLConnection data = iexfin.openConnection();
Scanner input = new Scanner(data.getInputStream());
if (input.hasNext()){ //skip header line
input.nextLine();
}
while (input.hasNextLine()){
String line = input.nextLine();
Scanner scanner = new Scanner(line);
scanner.useDelimiter(",");
symbols.add(scanner.next());
names.add(scanner.next());
scanner.close();
}
input.close();
}
catch (Exception e){
Log.e(StockALLDownloader.LOG_TAG, "error stock all downloader");
}
}
}