0

我打印了这个“[[ljava.lang.string;@40585b18”,而不是字符串数组中的一个值,称为答案。

目前我对打印出来的内容并不挑剔。只需让应用程序从数组中显示一些有意义的东西,这就是现在开始的好地方。

以下两行代码是当前打印的内容:

TextView quesAns4 = (TextView) findViewById(R.id.answer3);

quesAns4.setText("4) " + 答案) ;

package ks3.mathsapp.project;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MathsMultiplicationActivity extends Activity {

TextView quesnum;
TextView ques;
TextView ans1;
TextView ans2;
TextView ans3;
TextView ans4;


int qno = 0;
int right_answers = 0;
int wrong_answers = 0;
int rnd1;
int rnd2;

String [] questions = {"How much mph does the F-Duct add to the car?",
          "What car part is considered the biggest performance variable?",
          "What car part is designed to speed up air flow at the car rear?",
          "In seconds, how long does it take for a F1 car to stop when travelling at 300km/h?",
          "How many litres of air does an F1 car consume per second?",
          "What car part can heavily influence oversteer and understeer?",
          "A third of the cars downforce can come from what?",
          "Around how much race fuel would be consumed per 100km?","The first high nose cone was introduced when?",
          "An increase in what, has led to the length of exhaust pipes being shortened drastically?"};

String [] [] answers = {{"3","5","8","9"},
{"Tyres","Front Wing","F-Duct","Engine"},
{"Diffuser","Suspension","Tyres","Exhaust"},
{"4","6","8","10"},
{"650","10","75","450"},
{"Suspension","Tyres","Cockpit","Chassis"},
{"Rear Wing","Nose Cone","Chassis","Engine"},
{"75 Litres","100 Litres","50 Litres","25 Litres"},
{"1990","1989","1993","1992"},
{"Engine RPM","Nose Cone Lengths","Tyre Size","Number of Races"}};

 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multiplechoice);

// Importing all assets like buttons, text fields
quesnum = (TextView) findViewById(R.id.questionNum);
ques = (TextView) findViewById(R.id.question);
ans1 = (TextView) findViewById(R.id.answer1);
ans2 = (TextView) findViewById(R.id.answer2);
ans3 = (TextView) findViewById(R.id.answer3);
ans4 = (TextView) findViewById(R.id.answer4);

TextView quesAns1 = (TextView) findViewById(R.id.answer1); 
quesAns1.setText("1) " + answers) ;            
TextView quesAns2 = (TextView) findViewById(R.id.answer2); 
quesAns2.setText("2) " + answers) ;   
TextView quesAns3 = (TextView) findViewById(R.id.answer3); 
quesAns3.setText("3) " + answers) ;   
TextView quesAns4 = (TextView) findViewById(R.id.answer3); 
quesAns4.setText("4) " + answers) ;   
}                    
}
4

2 回答 2

2

你这样做是不对的。它应该是这样的:

quesAns1.setText("1) " + answers[0][0]);  //change index values as required
于 2012-04-12T13:41:47.650 回答
1

您将文本设置为"1) " + answers, 并且answers是字符串数组的数组。相反,您应该从数组中获取字符串:answers[0][0]例如,将获得第一个问题的第一个答案。

于 2012-04-12T13:42:20.443 回答