Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Have no idea whats Wrong(Need Help with a script)
Have no idea whats Wrong [message #1244473] Wed, 12 February 2014 11:43 Go to next message
Super EvilKiwi is currently offline Super EvilKiwiFriend
Messages: 1
Registered: February 2014
Junior Member
Ok,
Im new here so if I did anything wrong please say so.
I used a tutorial to creat this script but some how after removing every error there was the APP still crashed using the AVD Manager.



package de.hendrock.quiz;


import de.hendrock.quiz.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;

import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class Best_App_EU extends Activity {

	public int currentQuestion;
	    public String [] questions; 
	    public String [] answers;
	    public Button answerButton;
	    public Button questionButton; 
	    public TextView questionView;
	    public TextView answerView;
	    public EditText answerText;
	
 
   public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quiz);
        init();
    } 
    
    public void init() {
    	questions = new String[]{"What is the capital of Egypt?",
    "What class are you in right now?"};
    	answers = new String[]{"Cairo","IST380"};
    	currentQuestion = -1;
    	answerButton = (Button)findViewById( R.id.AnswerButton);
    	questionButton = (Button)findViewById(R.id.QuestionButton);
    	questionView = (TextView) findViewById(R.id.QuestionTextView); 
    	answerView = (TextView) findViewById(R.id.AnswerTextView); 
    	answerText = (EditText) findViewById(R.id.AnswerText);
    	answerButton.setOnClickListener(new OnClickListener(){
    	@Override
    	public void onClick(View v) { checkAnswer();
    	}});    
    	questionButton.setOnClickListener(new OnClickListener(){  	
    	@Override
    	public void onClick(View v) { showQuestion();
    	}}); }
    
    
    	public void showQuestion()
    	{
    	currentQuestion++; 
    	if(currentQuestion == questions.length)
    		currentQuestion =0;
    	
    	questionView.setText(questions[currentQuestion]);
    	answerView.setText("");
    	answerText.setText(""); 
    	}
    		
    	
    public boolean isCorrect(String answer)
    { 
     return (answer.equalsIgnoreCase(answers[currentQuestion])); 
     } 
    
 
  public void checkAnswer() 
  {
	  String answer = answerText.getText().toString();
	  if(isCorrect(answer)) 
		  answerView.setText("You're right!");
	  else
		  answerView.setText("Sorry, the correct answer is" +
		  answers[currentQuestion]);   
 
  } 
    }



[Updated on: Wed, 12 February 2014 13:38] by Moderator

Report message to a moderator

Re: Have no idea whats Wrong [message #1244536 is a reply to message #1244473] Wed, 12 February 2014 13:38 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3071
Registered: July 2009
Senior Member
These forums are for discussing Eclipse, but this is a question about general Android programming. You should ask on an Android-specific forum instead.
Previous Topic:Using Data Source Explorer Connection
Next Topic:Standalone Files in Eclipse
Goto Forum:
  


Current Time: Wed Oct 21 19:57:00 GMT 2020

Powered by FUDForum. Page generated in 0.03095 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top