Member Avatar for OldDeveloper01

I have this printed "ljava.lang.string;@40585b18" instead of a vlaue from the string array called answers.
At the moment i am not pick really as to what is pritned out. Just get the app to display something meaningfull from the array will be a good place to start right now.

The following two lines of code is what currently prints.

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) ;   

                    }                    
}

What is the layout for this?

Member Avatar for OldDeveloper01

Thanks for the reply, sorry for the delay.

   <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:fillViewport="true">
      <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:background="#fff">

      <!--  Header  Starts-->
      <LinearLayout android:id="@+id/header"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:background="@layout/header_gradient"
              android:paddingTop="5dip"
              android:paddingBottom="5dip">
              <!-- Logo Start-->
              <ImageView android:src="@drawable/header_logo"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_marginLeft="10dip"/>
              <!-- Logo Ends -->
      </LinearLayout>
      <!--  Header Ends -->
      <!-- Footer Start -->
      <LinearLayout android:id="@+id/footer"
              android:layout_width="fill_parent"
              android:layout_height="90dip"
              android:background="@layout/footer_repeat"
              android:layout_alignParentBottom="true">
      </LinearLayout>
      <!-- Footer Ends -->

      <!-- Registration Form -->
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="10dip"
      android:layout_below="@id/header">


        <!--  question number -->
    <TextView android:id="@+id/questionNum"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#e30000"
                android:textStyle="bold"/> 

    <!--  question -->
    <TextView android:id="@+id/question"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#e30000"
                android:layout_marginTop="15dip"
                android:padding="10dip"
                android:textStyle="bold"/> 


         <!--  Answers Label -->
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Answers:" 
        android:textColor="#000000"/>


    <!--  Answer 1 -->
    <TextView android:id="@+id/answer1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#e30000"
                android:layout_marginTop="15dip"
                android:clickable="true"
                android:padding="10dip"
                android:textStyle="bold"/>

      <!--  Answer 2--> 
    <TextView android:id="@+id/answer2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#e30000"
                android:layout_marginTop="15dip"
                android:clickable="true"
                android:padding="10dip"
                android:textStyle="bold"/>

      <!--  Answer 3 -->
   <TextView android:id="@+id/answer3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#e30000"
                android:layout_marginTop="15dip"
                android:clickable="true"
                android:padding="10dip"
                android:textStyle="bold"/>

      <!--  Answer 4 -->
    <TextView android:id="@+id/answer4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#e30000"
                android:layout_marginTop="15dip"
                android:clickable="true"
                android:padding="10dip"
                android:textStyle="bold"/>



    <!--  Next Question Button -->
    <Button
        android:id="@+id/btnNext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dip"
        android:text="Next"
        android:textColor="#000000"/>


      </LinearLayout>
      <!-- question Form Ends -->
       </RelativeLayout>
   </ScrollView>

Sorry for late reply little busy with projects. Your problem is that you are trying to feed whole array into one element of array object. Se bellow for working example

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {


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

    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.main);

        // 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);

        setText(0);

        next = (Button) findViewById(R.id.btnNext);
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (qno < questions.length-1) {
                    qno++;
                    setText(qno);
                }
            }
        });

    }

    private void setText(int index) {
        ques.setText(questions[index]);
        ans1.setText(answers[index][0]);
        ans2.setText(answers[index][1]);
        ans3.setText(answers[index][2]);
        ans4.setText(answers[index][3]);
    }
}

I added also listener to your button, but you will need to change behaviour for last click when I expect you wish to show score etc. Also, instead showing answers as text views use ListView and attach radio buttons to them so you can collect answer and evaluate it on click of next button.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.