Reputation: 516
I have a school project I'm not supposed to be starting til monday, and it's not due for another 6 weeks or longer. We are creating a program in java to add what we want to a database, I chose games (title, genre, platform, price, quantity(string, combobox, combobox, double, int)), I'm using a stack to add all of the objects to, but for some reason I can't get it to compile for some reason, and I keep getting really strange errors. My error and then code are below respectively.
nathan@ubuntu:~/Desktop/TAFE/Jeff (Java)/personalProject$ javac *.java
GameCombo.java:11: <identifier> expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: illegal start of type
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: ')' expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: ';' expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: illegal start of type
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: <identifier> expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: ';' expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: illegal start of type
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: <identifier> expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: <identifier> expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: illegal start of type
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: <identifier> expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: ';' expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: illegal start of type
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: <identifier> expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
GameCombo.java:11: ';' expected
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
^
16 errors
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class GameCombo extends JPanel {
ArrayList<Game> gamesList = new ArrayList<Game>();
Stack<Game> gamesStack = new Stack<Game>();
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
//gamesList.add(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
//gamesList.add(new Game("[Dead Space]", "Xbox 360", "Horror", "$68.00", "1"));
//String[] games = {"", "[Halo: Reach] Xbox 360; Action; $108.00; 2;", "[Dead Space] Xbox 360; Horror; $65.00; 1;"};
private JComboBox _gameBox = new JComboBox(gamesStack);
public GameCombo() {
setLayout(new GridLayout(1,1,1,1));
add(_gameBox);
}
}
Upvotes: 0
Views: 244
Reputation: 166
You can't have your code directly in the classbody, you must put it into a method or constructor.
Upvotes: 1
Reputation: 951
You need to first define a method and then write the relevant code within the method . I am not disclosing much as this is a home work project . Try reading up more on java's classes and methods
Upvotes: 2
Reputation: 137272
This call:
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
should be in some method, since you want to do it i every new object, as it looks from your code, why not moving it to the constructor:
public class GameCombo extends JPanel {
ArrayList<Game> gamesList = new ArrayList<Game>();
Stack<Game> gamesStack = new Stack<Game>();
private JComboBox _gameBox;
public GameCombo() {
setLayout(new GridLayout(1,1,1,1));
gamesStack.push(new Game("[Halo: Reach]", 3, 1, 108.00, 2));
_gameBox = new JComboBox(gamesStack);
add(_gameBox);
}
}
Upvotes: 3