2012-04-12 62 views
0

我有这个印刷“[[ljava.lang.string; @ 40585b18”,而不是从字符串数组称为答案的vlaue。应用程序打印“[[ljava.lang.string; @ 40585b18”,而不是数组值

目前我并不挑剔到底是什么。只要让应用程序显示来自阵列的意义,将是现在开始的好地方。

下面的两行代码是什么目前打印:

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

quesAns4.setText(“4)”+ answers);

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) ; 
}      
} 
+0

尝试索引你的数组.. e,g,'answers [0]'分配'quesAns1'的值。此外,类似的东西属于您的资源,而不是硬编码到应用程序中。 – Jens 2012-04-12 13:41:33

+0

我将如何去存储资源中的答案数组? – ManWithNoName 2012-04-12 14:43:43

+0

'App打印“ljava.lang.string; @ 40585b18”'。其实它没有:它印上“[[Ljava.lang.String; @ 40585b18”。请在发布错误消息,堆栈跟踪,意外输出等时保持准确。 – EJP 2012-04-13 01:07:39

回答

2

你做错了。它应该是这样的:

quesAns1.setText("1) " + answers[0][0]); //change index values as required 
+0

感谢您的反馈 TextView quesAns1 =(TextView)findViewById(R.id.answer1); (“1”)+ answers [2] [1]); 我增加了类似于你所说的。我现在可以从数组中读取数据。模型。我如何去匹配每个问题与正确asnwers? 我一直在使用我去年使用的闪光测验作为可以找到的代码的模型: http://www.scribd.com/doc/17215213/Build-a-Quiz-in-AS3 但是将actionscript翻译成java是很困难的。 – ManWithNoName 2012-04-12 14:13:06

+0

我建议你使用某种'HashMap '来配对问题和答案...... – waqaslam 2012-04-12 14:15:11

1

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