Thanks in advance for the help. I want to read a CSV into array and then output contents in textView. When I run this code in the android emulator, my textView is empty. I have no idea what I'm doing wrong. The reading of the file works in normal java with print statements. Can someone tell me what the bug is here? Why the code doesn't show the string inside array[0][1] in the textView, is it because of where I call it? I have tried all I can but can't seem to get it to work. Thanks a bunch.
package com.example.trivia;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.Button;
import android.widget.TextView;
public class PlayActivity extends Activity {
//define buttons and arrays
String [][]array;
TextView timer, questions;
Button answerA, answerB, answerC, answerD;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
initialize();
try {
play();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void initialize(){
timer = (TextView) findViewById(R.id.timer);
questions = (TextView) findViewById(R.id.questions);
answerA = (Button) findViewById(R.id.buttonA);
answerB = (Button) findViewById(R.id.buttonB);
answerC = (Button) findViewById(R.id.buttonC);
answerD = (Button) findViewById(R.id.buttonD);
array = new String [117][6];
}
public void play() throws FileNotFoundException{
String delimiter = ",";
int row =0;
File file = new File("questions1.csv");
Scanner sc = new Scanner(file);
while (sc.hasNextLine())
{
String line = sc.nextLine();
String [] temp = line.split(delimiter);
for(int i = 0; i< temp.length; i++){
array[row][i] = temp[i];
}
row++;
}
String show = array[0][1];
questions.setText(show);
}
}