1

Coding Help

gabe4356's Avatar gabe43563/1/14 7:31 pm
1 emeralds 370 7
3/2/2014 4:18 pm
Kiwi_'s Avatar Kiwi_
Ok, so I am working on a minecraft quiz, and I have a problem exporting my code. When I run it in eclipse it works fine. But when I try to export it, it says it finished with warnings. And when I try to run the executable Jar file, it won't work. The part that has the error is this part:
public static void main(String args[]) {

And this is all of my code:
package Main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.swing.*;
@SuppressWarnings("serial")
public class main extends JDialog {

static String

Name = JOptionPane.showInputDialog(null, "Enter Your Name:");


List<Question> questions = new ArrayList<Question>();
int score=0;
ButtonGroup group = new ButtonGroup();
JButton btnOk = new JButton("Next Question");
public main(){
super();
setModal(true);
setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
questions.add(new Question("How many iron ingots does it take to make an Iron golem?", new String[]{"10", "50", "45", "35"}, "45"));
questions.add(new Question("What was the original name of Minecraft going to be?", new String[]{"Mine Game", "Total Miner","Mob Slayer", "Cave Miner","Minecraft"}, "Cave Miner"));
questions.add(new Question("How much health does a normal palyer have when they spawn in a world?", new String[]{"10", "20", "3", "100"}, "20"));
questions.add(new Question("What do most people hate the most about Minecraft?", new String[]{"Sponge's", "Lagg", "The name", "Monsters"}, "Lagg"));
questions.add(new Question("What surface do you travel slower on?", new String[]{"Ice", "Soul Sand", "Ice below Soul Sand", "Ice above Soul Sand", "Lava"}, "Ice below Soul Sand"));
questions.add(new Question("What is the square root of 64? (Yes, this is related to Minecraft, max stack size 64)", new String[]{"3", "6", "1", "8", "64"}, "8"));
questions.add(new Question("How many wooden tools are there in Minecraft?", new String[]{"5", "4", "38", "6"}, "4"));
questions.add(new Question("What was the coding language that was used to create Minecraft?", new String[]{"DOS", "Javascript", "Java", "HTML", "XHTML", "C++"}, "Java"));
questions.add(new Question("Is there a command to do /warp in default Minecraft?", new String[]{"Yes", "No"}, "No"));
questions.add(new Question("Who did Notch give the ownership of Minecraft to?", new String[]{"Notch", "Jeb", "Dinnerbone"}, "Jeb"));
questions.add(new Question("What materials do you need to create a watch?", new String[]{"Gold, iron, redstone", "Gold, redstone", "Iron, redstone", "Gold, Iron, Redstone, Compass"}, "Gold, redstone"));
}
public int startQuiz(){
int score=0;
for (Question q : questions){
displayQuestion(q);
if (group.getSelection().getActionCommand().equals(q.getCorrectAnswer())){
score++;
}
}
dispose();
return score;
}
private void displayQuestion(Question q){
getContentPane().removeAll();
for (Enumeration<AbstractButton> buttonGroup=group.getElements(); buttonGroup.hasMoreElements(); ){
group.remove((AbstractButton)buttonGroup.nextElement());
}
JLabel questionText = new JLabel(q.getQuestion());
getContentPane().add(questionText);
for (String answer : q.getAnswers()){
JRadioButton radio = new JRadioButton(answer);
radio.setActionCommand(answer);
group.add(radio);
getContentPane().add(radio);
}
getContentPane().add(btnOk);
pack();
setVisible(true);
}
public static void main(String args[]) {
main quiz = new main();
int score = quiz.startQuiz();
JOptionPane.showMessageDialog(null,"Your score on the minecraft quiz is is: "+score,"",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "Quiz made by: gabe4356, question ideas by: TacticalToaster.");
JOptionPane.showMessageDialog(null, "I hope you enjoyed the game " + Name);
}
class Question {
String question="";
String[] answers;
String correctAnswer;
public Question(String question, String[] possibleAnswers, String correctAnswer){
this.question = question;
this.answers = possibleAnswers;
this.correctAnswer = correctAnswer;
}
public String getQuestion() {
return question;
}
public String[] getAnswers() {
return answers;
}
public String getCorrectAnswer() {
return correctAnswer;
}
}
}


Please help?
Posted by gabe4356's Avatar
gabe4356
Level 52 : Grandmaster Blob
205

Create an account or sign in to comment.

7

1
03/02/2014 4:18 pm
Level 8 : Apprentice Engineer
Kiwi_
Kiwi_'s Avatar
Why are you using eclipse for this? just use something simple like Sublime Text 2 where you cant really go wrong without it telling you off,

But anyway send me error report and I'll give it a look see
1
03/01/2014 8:46 pm
Level 24 : Expert Toast
nolez15
nolez15's Avatar
I'm not trying it out, but looking at it, it all clearly looks fine to me..

Seems like it should work fine.
1
03/01/2014 8:30 pm
Level 31 : Artisan Toast
ShadowCatEXE
ShadowCatEXE's Avatar
I tried out your code... There doesn't seem to be anything wrong with it. When it gave you the error, did you go back to see what it was? if you did, what was the error...?
1
03/01/2014 8:41 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Did you try exporting it, that's when it doesn't work
1
03/01/2014 8:45 pm
Level 31 : Artisan Toast
ShadowCatEXE
ShadowCatEXE's Avatar
Yes, I exported it and it worked fine for me. Give me a pm, I'll try and help you out.
1
03/01/2014 9:00 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
I PM'ed you with a more detailed error report.
1
03/01/2014 8:12 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Anyone? Please?
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome