1

私はこのコードを持っています。配列の要素を読み取り、Androidのテキストビューに表示しようとしています。android sdkの代わりにprintステートメントのplainjavaを使用すると、コードは正しいものを表示します。私はしばらくの間それを理解しようとしてきました。何か助けはありますか?

     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< temp.length; i++){
              array[row][i] = temp[i];   
            }
           row++;
         }
        questionsArray = new String[117][6];
        questionsArray = array;
        questions.setText(questionsArray[0][2]);
        }
4

1 に答える 1

2

TextViewあなたのコードにはありません。方法でもないsetText。最も単純なTextView作品はこのように

TextView textView = (TextView) findViewById(R.id.id_of_your_textview);
text.setText("your text");

最初に試した関連コードを表示します。次に、発生しているエラーを表示します。これにより、探しているものを取得するプロセスがスピードアップします。

于 2013-03-22T05:43:01.163 に答える