Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Reading array into TextView
    primarykey
    data
    text
    <p>I have this piece of code. I am trying to read elements of the array and display it in a textview in android. The code displays the correct thing if I just use a print statement plain java instead of the android sdk. I've been trying to figure it out for a while now. Any help?</p> <pre><code> package com.example.trivia; import java.io.File; import java.io.IOException; import java.util.Random; 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 { String [][]array; String [][] questionsArray; int []playindexArray = new int[50]; TextView timer, questions; Button answerA, answerB, answerC, answerD; String show = "Buttons and Question"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play); 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); //countdowntimer CountDownTimer count = new CountDownTimer(32000, 1000) { public void onTick(long millisUntilFinished) { timer.setText("TIME REMAINING: " + millisUntilFinished / 1000); } public void onFinish() { timer.setText("TIME UP!"); } }; count.start(); try { readCSV(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void readCSV() throws IOException{ array = new String[117][6]; 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&lt; temp.length; i++){ array[row][i] = temp[i]; } row++; } questionsArray = new String[117][6]; questionsArray = array; questions.setText(questionsArray[0][2]); } </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