Illegal start of expression and cannot resolve symbol HELP
Can someone pls help me?
These are the two problems:
--------------------Configuration: j2sdk1.4.1_02 <Default>--------------------
C:\Documents and Settings\Laila\My Documents\CMT2080\Coursework\Game\Mindboggler.java:291: illegal start of expression
public void inputJButtonActionPerformed( ActionEvent event )
^
C:\Documents and Settings\Laila\My Documents\CMT2080\Coursework\Game\Mindboggler.java:285: cannot resolve symbol
symbol: method inputJButtonActionPerformed (java.awt.event.ActionEvent)
inputJButtonActionPerformed( event);
Here is my code :
//Mind boggler quiz
//Marcelyn Samson
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.border.*;
import java.lang.*;
public class Mindboggler extends JFrame
// JPanel for welcome window
private JPanel welcomeJPanel;
private JPanel presetJPanel;
private JLabel titleJLabel;
private JLabel quizJLabel;
private JLabel girlJLabel, headJLabel;
private JLabel introJLabel;
private JButton startJButton;
// JPanel for questionone window
private JPanel questiononeJPanel;
private JLabel textJLabel;
private JPanel becksJPanel;
private JButton oneJButton, twoJButton, threeJButton, fourJButton, nextJButton;
//JPanel for questiontwo window
private JPanel questiontwoJPanel;
private JPanel orlandoJPanel;
private JLabel q2JLabel;
private JCheckBox lordJCheckBox;
private JCheckBox faceJCheckBox;
private JCheckBox piratesJCheckBox;
private JButton next2JButton;
private JButton inputJButton;
//JPanel for questionthree
private JPanel questionthreeJPanel;
private JPanel howmuchJPanel;
private JLabel howmuchJLabel;
private JLabel nameJLabel;
private JTextField nameJTextField;
private JLabel moneyJLabel;
private JTextField moneyJTextField;
private JButton next3JButton;
//Publics
public JPanel welcomeJFrame, questionJFrame, questiontwoJFrame, questionthreeJFrame;
//contentPane
public Container contentPane;
//no argument constructor
public Mindboggler()
createUserInterface();
//create and position components
private void createUserInterface()/////////////////////////; semo colon do not edit copy paste
//get contentPane and set layout to null
contentPane = getContentPane();
contentPane.setLayout ( null );
welcome();
//set properties of applications window
setTitle( "Mindboggler" ); // set JFrame's title bar string
setSize( 600, 400 ); // set width and height of JFrame
setVisible( true ); // display JFrame on screen
} // end method createUserInterface
public void welcome(){
// set up welcomeJPanel
welcomeJPanel = new JPanel();
welcomeJPanel.setLayout( null );
welcomeJPanel.setBounds(0, 0, 600, 400);
welcomeJPanel.setBackground( Color.GREEN );
// set up textJLabel
titleJLabel = new JLabel();
titleJLabel.setText( "Mind Boggler" );
titleJLabel.setLocation( 30, 10);
titleJLabel.setSize( 550, 70);
titleJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 30 ) );
titleJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add( titleJLabel );
// set up presetJPanel
presetJPanel = new JPanel();
presetJPanel.setLayout( null );
presetJPanel.setBounds( 150, 10, 300, 80 );
presetJPanel.setBackground( Color.GRAY );
welcomeJPanel.add( presetJPanel );
//setup Intro JLabel
introJLabel = new JLabel();
introJLabel.setText( "Think, think, think. Can you get all the questions right?" );
introJLabel.setBounds( 40, 100, 500, 200 );
introJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 18 ) );
introJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(introJLabel);
//set up head JLabel
headJLabel = new JLabel();
headJLabel.setIcon( new ImageIcon( "head.jpeg") );
headJLabel.setBounds( 540, 5, 40, 160 );
headJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(headJLabel);
//setup girlJLabel
girlJLabel = new JLabel();
girlJLabel.setIcon( new ImageIcon( "girl.Jjpeg") );
girlJLabel.setBounds( 5, 10, 60, 100 );
girlJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(girlJLabel);
//set up startJbutton
startJButton = new JButton();
startJButton.setText( "Start" );
startJButton.setBounds(250, 300, 100, 30);
startJButton.setFont( new Font( "SansSerif", Font.BOLD, 14) );
welcomeJPanel.add(startJButton);
contentPane.add(welcomeJPanel);
startJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
question();
public void question()
//set up question one JPanel
welcomeJPanel.setVisible(false);
questiononeJPanel = new JPanel();
questiononeJPanel.setLayout( null );
questiononeJPanel.setBounds(0, 0, 600,400);
questiononeJPanel.setBackground( Color.GREEN );
// set up textJLabel
textJLabel = new JLabel();
textJLabel.setText( "Who did Beckham supposedly cheat with?" );
textJLabel.setLocation( 20, 20);
textJLabel.setSize( 550, 70);
textJLabel.setFont( new Font( "SansSerif", Font.BOLD, 20 ) );
textJLabel.setHorizontalAlignment( JLabel.CENTER );
questiononeJPanel.add( textJLabel );
// set up presetJPanel
becksJPanel = new JPanel();
becksJPanel.setLayout( null );
becksJPanel.setBorder( new TitledBorder(
"Question 1" ) );
becksJPanel.setBounds( 10, 10, 570, 80 );
becksJPanel.setBackground( Color.GRAY );
questiononeJPanel.add( becksJPanel );
// set up oneJButton
oneJButton = new JButton();
oneJButton.setBounds( 10, 120, 300, 40 );
oneJButton.setText( "Britney Spears" );
oneJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( oneJButton );
// set up twoJButton
twoJButton = new JButton();
twoJButton.setBounds( 10, 180, 300, 40 );
twoJButton.setText( "Meg Ryan" );
twoJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( twoJButton );
// set up threeJButton
threeJButton = new JButton();
threeJButton.setBounds( 10, 240, 300, 40 );
threeJButton.setText( "Rebecca Loos" );
threeJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( threeJButton );
// set up fourJButton
fourJButton = new JButton();
fourJButton.setBounds( 10, 300, 300, 40 );
fourJButton.setText( "Angelina Jolie" );
fourJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( fourJButton );
// set up nextJButton
nextJButton = new JButton();
nextJButton.setBounds ( 375, 300, 150, 40 );
nextJButton.setText("Next");
nextJButton.setBackground( Color.GRAY );
questiononeJPanel.add( nextJButton );
contentPane.add(questiononeJPanel);
nextJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questiontwo();
public void questiontwo()
//set up question two JPanel
questiononeJPanel.setVisible(false);
questiontwoJPanel=new JPanel();
questiontwoJPanel.setLayout(null);
questiontwoJPanel.setBounds(0, 0, 600, 400);
questiontwoJPanel.setBackground( Color.GREEN );
// set up q2JLabel
q2JLabel = new JLabel();
q2JLabel.setBounds( 20, 20, 550, 70 );
q2JLabel.setText( "What films has Orlando Bloom starred in?" );
q2JLabel.setFont(new Font( "SansSerif", Font.BOLD, 20 ) );
q2JLabel.setHorizontalAlignment( JLabel.CENTER );
questiontwoJPanel.add(q2JLabel);
//set up orlandoJPanel
orlandoJPanel = new JPanel();
orlandoJPanel.setLayout(null);
orlandoJPanel.setBorder( new TitledBorder("Question 2"));
orlandoJPanel.setBounds( 10, 10, 570, 80);
orlandoJPanel.setBackground(Color.GRAY);
questiontwoJPanel.add(orlandoJPanel);
// set up lordJCheckBox
lordJCheckBox = new JCheckBox();
lordJCheckBox.setBounds( 16, 112, 200, 24 );
lordJCheckBox.setText( "1. Lord of The Rings" );
questiontwoJPanel.add( lordJCheckBox );
// set up faceJCheckBox
faceJCheckBox = new JCheckBox();
faceJCheckBox.setBounds( 16, 159, 200, 24 );
faceJCheckBox.setText( "2. Face Off" );
questiontwoJPanel.add( faceJCheckBox );
// set up piratesJCheckBox
piratesJCheckBox = new JCheckBox();
piratesJCheckBox.setBounds( 16, 206, 200, 24 );
piratesJCheckBox.setText( "3. Pirates of The Caribean" );
questiontwoJPanel.add( piratesJCheckBox );
// set up inputJButton
inputJButton = new JButton();
inputJButton.setBounds(20, 256, 200, 21 );
inputJButton.setText( "Input answer" );
questiontwoJPanel.add( inputJButton );
inputJButton.addActionListener(
new ActionListener()
//event handler called when user clicks inputJButton
public void actionPerformed( ActionEvent event )
inputJButtonActionPerformed( event);
//show JOptionMessages when user clicks on JCheckBoxes and inputJButton
public void inputJButtonActionPerformed( ActionEvent event )
//display error message if no JCheckBoxes is checked
if ( ( !lordJCheckBox.isSelected() && !faceJCheckBox.isSelected() && !piratesJCheckBox.isSelected() ) )
//display error message
JOptionPane.showMessageDialog( null, "Please check two boxes", JOptionPane.ERROR_MESSAGE );
// if lordjcheckbox and pirates is selected = right
else
if ( ( lordJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats RIGHT!");
//if others are selected = wrong
else
if ( (lordJCheckBox.isSelected() && faceJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
else
( (faceJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
// set up nest2JButton
next2JButton = new JButton();
next2JButton.setBounds( 155, 296, 94, 24 );
next2JButton.setText( "Next" );
questiontwoJPanel.add( next2JButton );
contentPane.add(questiontwoJPanel);
next2JButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questionthree();
} // end questiontwo
public void questionthree()
//setup questionthree JPanel
questiontwoJPanel.setVisible(false);
questionthreeJPanel = new JPanel();
questionthreeJPanel.setLayout(null);
questionthreeJPanel.setBounds(0, 0, 600, 400);
questionthreeJPanel.setBackground( Color.GREEN);
// main method
public static void main( String[] args )
Mindboggler application = new Mindboggler();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end method main
}// end class
WOULD BE VERY GEATFUL
Just want to say thank you by the way for trying to help. Ive moved public void inputJButtonActionPerformed( ActionEvent event ) outside of brackets. Now i have a different problem on it. Sorry about this.
PROBLEM: --------------------Configuration: <Default>--------------------
C:\Documents and Settings\Laila\My Documents\CMT2080\Coursework\Game\Mindboggler.java:353: 'else' without 'if'
else ( ( !lordJCheckBox.isSelected() && !faceJCheckBox.isSelected && !piratesJCheckBox.isSelected() ) )
^
1 error
Process completed.
MY CODE:
//Mind boggler quiz
//Marcelyn Samson
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.*;
import javax.swing.border.*;
import java.lang.*;
public class Mindboggler extends JFrame
// JPanel for welcome window
private JPanel welcomeJPanel;
private JPanel presetJPanel;
private JLabel titleJLabel;
private JLabel quizJLabel;
private JLabel girlJLabel, headJLabel;
private JLabel introJLabel;
private JButton startJButton;
// JPanel for questionone window
private JPanel questiononeJPanel;
private JLabel textJLabel;
private JPanel becksJPanel;
private JButton oneJButton, twoJButton, threeJButton, fourJButton, nextJButton;
//JPanel for questiontwo window
private JPanel questiontwoJPanel;
private JPanel orlandoJPanel;
private JLabel q2JLabel;
private JCheckBox lordJCheckBox;
private JCheckBox faceJCheckBox;
private JCheckBox piratesJCheckBox;
private JButton next2JButton;
private JButton inputJButton;
//JPanel for questionthree
private JPanel questionthreeJPanel;
private JPanel howmuchJPanel;
private JLabel howmuchJLabel;
private JLabel nameJLabel;
private JTextField nameJTextField;
private JLabel moneyJLabel;
private JTextField moneyJTextField;
private JButton next3JButton;
//Publics
public JPanel welcomeJFrame, questionJFrame, questiontwoJFrame, questionthreeJFrame;
//contentPane
public Container contentPane;
//no argument constructor
public Mindboggler()
createUserInterface();
//create and position components
private void createUserInterface()/////////////////////////; semo colon do not edit copy paste
//get contentPane and set layout to null
contentPane = getContentPane();
contentPane.setLayout ( null );
welcome();
//set properties of applications window
setTitle( "Mindboggler" ); // set JFrame's title bar string
setSize( 600, 400 ); // set width and height of JFrame
setVisible( true ); // display JFrame on screen
} // end method createUserInterface
public void welcome(){
// set up welcomeJPanel
welcomeJPanel = new JPanel();
welcomeJPanel.setLayout( null );
welcomeJPanel.setBounds(0, 0, 600, 400);
welcomeJPanel.setBackground( Color.GREEN );
// set up textJLabel
titleJLabel = new JLabel();
titleJLabel.setText( "Mind Boggler" );
titleJLabel.setLocation( 30, 10);
titleJLabel.setSize( 550, 70);
titleJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 30 ) );
titleJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add( titleJLabel );
// set up presetJPanel
presetJPanel = new JPanel();
presetJPanel.setLayout( null );
presetJPanel.setBounds( 150, 10, 300, 80 );
presetJPanel.setBackground( Color.GRAY );
welcomeJPanel.add( presetJPanel );
//setup Intro JLabel
introJLabel = new JLabel();
introJLabel.setText( "Think, think, think. Can you get all the questions right?" );
introJLabel.setBounds( 40, 100, 500, 200 );
introJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 18 ) );
introJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(introJLabel);
//set up head JLabel
headJLabel = new JLabel();
headJLabel.setIcon( new ImageIcon( "head.jpeg") );
headJLabel.setBounds( 540, 5, 40, 160 );
headJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(headJLabel);
//setup girlJLabel
girlJLabel = new JLabel();
girlJLabel.setIcon( new ImageIcon( "girl.Jjpeg") );
girlJLabel.setBounds( 5, 10, 60, 100 );
girlJLabel.setHorizontalAlignment( JLabel.CENTER );
welcomeJPanel.add(girlJLabel);
//set up startJbutton
startJButton = new JButton();
startJButton.setText( "Start" );
startJButton.setBounds(250, 300, 100, 30);
startJButton.setFont( new Font( "SansSerif", Font.BOLD, 14) );
welcomeJPanel.add(startJButton);
contentPane.add(welcomeJPanel);
startJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
question();
public void question()
//set up question one JPanel
welcomeJPanel.setVisible(false);
questiononeJPanel = new JPanel();
questiononeJPanel.setLayout( null );
questiononeJPanel.setBounds(0, 0, 600,400);
questiononeJPanel.setBackground( Color.GREEN );
// set up textJLabel
textJLabel = new JLabel();
textJLabel.setText( "Who did Beckham supposedly cheat with?" );
textJLabel.setLocation( 20, 20);
textJLabel.setSize( 550, 70);
textJLabel.setFont( new Font( "SansSerif", Font.BOLD, 20 ) );
textJLabel.setHorizontalAlignment( JLabel.CENTER );
questiononeJPanel.add( textJLabel );
// set up presetJPanel
becksJPanel = new JPanel();
becksJPanel.setLayout( null );
becksJPanel.setBorder( new TitledBorder(
"Question 1" ) );
becksJPanel.setBounds( 10, 10, 570, 80 );
becksJPanel.setBackground( Color.GRAY );
questiononeJPanel.add( becksJPanel );
// set up oneJButton
oneJButton = new JButton();
oneJButton.setBounds( 10, 120, 300, 40 );
oneJButton.setText( "Britney Spears" );
oneJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( oneJButton );
// set up twoJButton
twoJButton = new JButton();
twoJButton.setBounds( 10, 180, 300, 40 );
twoJButton.setText( "Meg Ryan" );
twoJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( twoJButton );
// set up threeJButton
threeJButton = new JButton();
threeJButton.setBounds( 10, 240, 300, 40 );
threeJButton.setText( "Rebecca Loos" );
threeJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( threeJButton );
// set up fourJButton
fourJButton = new JButton();
fourJButton.setBounds( 10, 300, 300, 40 );
fourJButton.setText( "Angelina Jolie" );
fourJButton.setBackground( Color.ORANGE );
questiononeJPanel.add( fourJButton );
// set up nextJButton
nextJButton = new JButton();
nextJButton.setBounds ( 375, 300, 150, 40 );
nextJButton.setText("Next");
nextJButton.setBackground( Color.GRAY );
questiononeJPanel.add( nextJButton );
contentPane.add(questiononeJPanel);
nextJButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questiontwo();
public void questiontwo()
//set up question two JPanel
questiononeJPanel.setVisible(false);
questiontwoJPanel=new JPanel();
questiontwoJPanel.setLayout(null);
questiontwoJPanel.setBounds(0, 0, 600, 400);
questiontwoJPanel.setBackground( Color.GREEN );
// set up q2JLabel
q2JLabel = new JLabel();
q2JLabel.setBounds( 20, 20, 550, 70 );
q2JLabel.setText( "What films has Orlando Bloom starred in?" );
q2JLabel.setFont(new Font( "SansSerif", Font.BOLD, 20 ) );
q2JLabel.setHorizontalAlignment( JLabel.CENTER );
questiontwoJPanel.add(q2JLabel);
//set up orlandoJPanel
orlandoJPanel = new JPanel();
orlandoJPanel.setLayout(null);
orlandoJPanel.setBorder( new TitledBorder("Question 2"));
orlandoJPanel.setBounds( 10, 10, 570, 80);
orlandoJPanel.setBackground(Color.GRAY);
questiontwoJPanel.add(orlandoJPanel);
// set up lordJCheckBox
lordJCheckBox = new JCheckBox();
lordJCheckBox.setBounds( 16, 112, 200, 24 );
lordJCheckBox.setText( "1. Lord of The Rings" );
questiontwoJPanel.add( lordJCheckBox );
// set up faceJCheckBox
faceJCheckBox = new JCheckBox();
faceJCheckBox.setBounds( 16, 159, 200, 24 );
faceJCheckBox.setText( "2. Face Off" );
questiontwoJPanel.add( faceJCheckBox );
// set up piratesJCheckBox
piratesJCheckBox = new JCheckBox();
piratesJCheckBox.setBounds( 16, 206, 200, 24 );
piratesJCheckBox.setText( "3. Pirates of The Caribean" );
questiontwoJPanel.add( piratesJCheckBox );
// set up inputJButton
inputJButton = new JButton();
inputJButton.setBounds(20, 256, 200, 21 );
inputJButton.setText( "Input answer" );
questiontwoJPanel.add( inputJButton );
inputJButton.addActionListener(
new ActionListener()
//event handler called when user clicks inputJButton
public void actionPerformed( ActionEvent event )
inputJButtonActionPerformed( event);
// set up nest2JButton
next2JButton = new JButton();
next2JButton.setBounds( 155, 296, 94, 24 );
next2JButton.setText( "Next" );
questiontwoJPanel.add( next2JButton );
contentPane.add(questiontwoJPanel);
next2JButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
questionthree();
} // end questiontwo
public void questionthree()
//setup questionthree JPanel
questiontwoJPanel.setVisible(false);
questionthreeJPanel = new JPanel();
questionthreeJPanel.setLayout(null);
questionthreeJPanel.setBounds(0, 0, 600, 400);
questionthreeJPanel.setBackground( Color.GREEN);
//setup howmuchJLabel
howmuchJLabel = new JLabel();
howmuchJLabel.setText("I'm a student and would be very greatful if you could donate some money as it would help me very much.");
howmuchJLabel.setBounds(20, 20, 550, 70);
howmuchJLabel.setFont(new Font("SansSerif",Font.BOLD,14));
howmuchJLabel.setHorizontalAlignment(JLabel.CENTER);
questionthreeJPanel.add(howmuchJLabel);
//setup howmuchJPanel
howmuchJPanel = new JPanel();
howmuchJPanel.setLayout(null);
howmuchJPanel.setBorder( new TitledBorder("Question 3"));
howmuchJPanel.setBounds(10, 10, 570, 80);
howmuchJPanel.setBackground( Color.GRAY);
questionthreeJPanel.add(howmuchJPanel);
//setup nameJLabel
nameJLabel = new JLabel();
nameJLabel.setText("Name");
nameJLabel.setBounds(10, 160, 150, 24);
nameJLabel.setFont(new Font("SansSerif",Font.BOLD,12));
questionthreeJPanel.add(nameJLabel);
//setup nameJTextField
nameJTextField = new JTextField();
nameJTextField.setBounds(125, 160, 200, 24 );
questionthreeJPanel.add(nameJTextField);
contentPane.add(questionthreeJPanel);
//show JOptionMessages when user clicks on JCheckBoxes and inputJButton
public void inputJButtonActionPerformed( ActionEvent event )
//display error message if no JCheckBoxes is checked
else ( ( !lordJCheckBox.isSelected() && !faceJCheckBox.isSelected && !piratesJCheckBox.isSelected() ) )
//display error message
JOptionPane.showMessageDialog( null, "Please check two boxes", JOptionPane.ERROR_MESSAGE );
// if lordjcheckbox and pirates is selected = right
else
if ( ( lordJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats RIGHT!");
//if others are selected = wrong
else
if ( (lordJCheckBox.isSelected() && faceJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
else
( (faceJCheckBox.isSelected() && piratesJCheckBox.isSelected() ))
JOptionPane.showMessageDialog(null, "Thats WRONG");
// main method
public static void main( String[] args )
Mindboggler application = new Mindboggler();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end method main
}// end class
Similar Messages
-
Cannot find package error and cannot resolve symbol error
Hi
I have a file Assignment.java in C:\TIJCode\c03 folder. But this file belongs to the default package. This file imports a package com.bruceeckel.simpletest which is in C:\TIJCode\ folder. Now this package has a file named Test.java which accesses a few more files fromt he same package.
I set the classpath to C:\TIJCode. When i try to run the Assignment file I get an error saying package com.bruceeckel.simpletest cannot be found and cannot resolve symbol error. symbol: Test Class: Assignment.
The files in com.bruceeckel.simpletest package were not compiled. So I first tried to do that. But I get a cannot resolve symbol error while trying to compile a file NumOfLinesException which inherits SImpleTestException file. The exact error message is
NumOfLinesException.java : 7 : cannot resolve symbol
symbol : class SimpleTestException
location : class com.bruceeckel.simpletest.NumOfLinesException extends SimpleTestException
The exact code in each of above mentioned files is
//: c03:Assignment.java
// Assignment with objects is a bit tricky.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import com.bruceeckel.simpletest.*;
class Number {
int i;
public class Assignment {
static Test monitor = new Test();
public static void main(String[] args) {
Number n1 = new Number();
Number n2 = new Number();
n1.i = 9;
n2.i = 47;
System.out.println("1: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1 = n2;
System.out.println("2: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1.i = 27;
System.out.println("3: n1.i: " + n1.i +
", n2.i: " + n2.i);
monitor.expect(new String[] {
"1: n1.i: 9, n2.i: 47",
"2: n1.i: 47, n2.i: 47",
"3: n1.i: 27, n2.i: 27"
} ///:~
//: com:bruceeckel:simpletest:SimpleTestException.java
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package com.bruceeckel.simpletest;
public class SimpleTestException extends RuntimeException {
public SimpleTestException(String msg) {
super(msg);
} ///:~
//: com:bruceeckel:simpletest:NumOfLinesException.java
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package com.bruceeckel.simpletest;
public class NumOfLinesException extends SimpleTestException {
public NumOfLinesException(int exp, int out) {
super("Number of lines of output and "
+ "expected output did not match.\n" +
"expected: <" + exp + ">\n" +
"output: <" + out + "> lines)");
} ///:~
//: com:bruceeckel:simpletest:Test.java
// Simple utility for testing program output. Intercepts
// System.out to print both to the console and a buffer.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package com.bruceeckel.simpletest;
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class Test {
// Bit-shifted so they can be added together:
public static final int
EXACT = 1 << 0, // Lines must match exactly
AT_LEAST = 1 << 1, // Must be at least these lines
IGNORE_ORDER = 1 << 2, // Ignore line order
WAIT = 1 << 3; // Delay until all lines are output
private String className;
private TestStream testStream;
public Test() {
// Discover the name of the class this
// object was created within:
className =
new Throwable().getStackTrace()[1].getClassName();
testStream = new TestStream(className);
public static List fileToList(String fname) {
ArrayList list = new ArrayList();
try {
BufferedReader in =
new BufferedReader(new FileReader(fname));
try {
String line;
while((line = in.readLine()) != null) {
if(fname.endsWith(".txt"))
list.add(line);
else
list.add(new TestExpression(line));
} finally {
in.close();
} catch (IOException e) {
throw new RuntimeException(e);
return list;
public static List arrayToList(Object[] array) {
List l = new ArrayList();
for(int i = 0; i < array.length; i++) {
if(array[i] instanceof TestExpression) {
TestExpression re = (TestExpression)array;
for(int j = 0; j < re.getNumber(); j++)
l.add(re);
} else {
l.add(new TestExpression(array[i].toString()));
return l;
public void expect(Object[] exp, int flags) {
if((flags & WAIT) != 0)
while(testStream.numOfLines < exp.length) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
List output = fileToList(className + "Output.txt");
if((flags & IGNORE_ORDER) == IGNORE_ORDER)
OutputVerifier.verifyIgnoreOrder(output, exp);
else if((flags & AT_LEAST) == AT_LEAST)
OutputVerifier.verifyAtLeast(output,
arrayToList(exp));
else
OutputVerifier.verify(output, arrayToList(exp));
// Clean up the output file - see c06:Detergent.java
testStream.openOutputFile();
public void expect(Object[] expected) {
expect(expected, EXACT);
public void expect(Object[] expectFirst,
String fname, int flags) {
List expected = fileToList(fname);
for(int i = 0; i < expectFirst.length; i++)
expected.add(i, expectFirst[i]);
expect(expected.toArray(), flags);
public void expect(Object[] expectFirst, String fname) {
expect(expectFirst, fname, EXACT);
public void expect(String fname) {
expect(new Object[] {}, fname, EXACT);
} ///:~What do you have in the C:\TIJCode\ directory? Does the directory structure mimic the package structure for the stuff you're importing?
-
Missing method body and cannot resolve symbol
I keep getting these two errors when trying to compile. I know that I need to call my fibonacci and factorial functions from the main function. Is this why I am getting the missing method body error? How do I correct this?
Am I getting the cannot resolve symbol because I have to set the num and fact to equal something?
Thanks
public class Firstassignment
public static void main(String[]args)
System.out.println();
public static void fibonacci(String[]args);
int even=1;
int odd=1;
while (odd<=100);
System.out.println(even);
int temp = even;
even = odd;
odd = odd + temp;
public static void factorial (String[]args);
for (int count=1;
count<=num;
count++);
fact = fact * count;
outputbox.printLine("Factorial of" + num + "is" + fact);Hey... :o)
the problem is that you've put semicolons at the end of the function signature, like this:
public static void fibonacci(String[]args);
}that should happen only when the function is abstract... so ur function should actually look like this:
public static void fibonacci(String[]args)
}also, i think you've missed out on the declarations (like what are fact and num??).... -
IntValue - ")" expected and Cannot Resolve Symbol
I used intValue to convert an Integer to primitive (see below) and ran into syntax errors.
LogDataBean lb = new LogDataBean();
lb.setLog_time( ( String )row.get( "LOG_TIME" ) );
lb.setLog_pid( intValue( Integer )row.get( "LOG_PID" )); //where syntax error occur
lb.setLog_user( ( String )row.get( "LOG_USER" ) );the row.get( "LOG_PID" ) gets the value of the column "LOG_PID" from a database table and returns an object. Therefore, I first cast the object to Integer and then try to use the intValue to convert it to a primitive int.
But, the statement resulted in compilation error: ")" expected.
When I modified the statement a little bit by adding a pair of parenthesis:
lb.setLog_pid( intValue( ( Integer )row.get( "LOG_PID" ) ) ); //where syntax error occurI got "Cannot Resolve Symbol: intValue". I have import java.lang.Integer in the beginning of the class.Integer.parseInt(row.get( "LOG_PID" ))
I'm assuming thats what you want to. Although you syntax is terribly wrong. Have a look at some tutorials. -
Try/catch and 'cannot resolve symbol'
I am relatively new to java programming and something has me puzzled...
Why do I get a 'cannot resolve symbol' message when I include a variable definition in a try/catch section. When I put it/them before the 'try' statement it compiles as expected. How are statements inside a try compiled differently than those outside?
try {
StringBuffer pageBuffer = new StringBuffer();
String inputLine;
BufferedReader in = new BufferedReader(
new InputStreamReader( theURL.openStream() ) );
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
pageBuffer.append(inputLine);
in.close();
} catch (Exception ignored) {}C:\Projects\WebExplorer\PageVisitor.java:142: cannot resolve symbol
symbol : variable pageBuffer
location: class PageVisitor
return pageBuffer.toString();
PaulA try block is just like any other block delimited by {...} in that all variables declared inside it are local to that block. I.e. they are not visible or usable anywhere outside it. Your pageBuffer variable, for example, is a local variable that can only be used inside the try-block in which it is declared.
Your obvious solution, knowing that, is to declare the variables outside the try and catch blocks. Remember to initialize them (even to null), otherwise the compiler will complain about variables that may not have been initialized. -
"cannot resolve symbol" help..
Here is a very short and simpel program that won't compile after I reinstalled java on my computer.
import java.lang.Math.*;
import java.awt.*;
public class PiTest extends Frame {
public static void main(String[] p){
System.out.println("testing MATHs");
System.out.println(""+sin(10));
I get the following error:
PiTest.java:8: cannot resolve symbol
symbol : method sin (int)
location: class PiTest
System.out.println(""+sin(10));
^
[total 1553ms]
1 error
Why doesn't the compiler recognise the sine function? I have set my classpath to c:\j2sdk1.4.1_01\lib.
I don't know what I'm doing wrong...Replace sin(10) with Math.sin(10), it should work.
import java.lang.Math.*;
import java.awt.*;
public class PiTest extends Frame {
public static void main(String[] p){
System.out.println("testing MATHs");
//System.out.println(""+sin(10));
System.out.println(""+Math.sin(10)); -
Help.. incompatiable type and cannot resolve symbol error...
I have this class Box
class Box{
private int width;
private int height;
private int depth;
private int BoxCounter;
public void click()
BoxCounter = 0;
}and in my main code, I'm calling it via
private Box arrBox[];All this goes fine until I try to place code in to make array empty upon a selected action by
if (color == blue) {arrBox = new Box();}Here I'm getting the error saying that its an incompatible type... it says I have Box but it requires class Box[]...(the ^ pointing at the word "new")
also, I have this
public void button()
arrBox.click()
}This returns the unable to resolve symbol error (the ^ points at the dot).... I tried changing things around but the problem persists, can someone point out where I hv gone wrong?
Many thanksprivate Box arrBox[];The line above does not create an array, it only declares that the variable arrBox can refernce an array of type Box. Arrays are objects just like Box - you need a new Box[10], for example, to create the array.
if (color == blue) {arrBox = new Box();}
Here I'm getting the error saying that its an
incompatible type... it says I have Box but it
requires class Box[]...(the ^ pointing at the word
"new")As previously stated, arrBox is a reference to an array of Box, not an object instance of Box.
A lot of your trouble can be resolved by understanding how arrays work in java. Try here.
http://java.sun.com/docs/books/tutorial/java/data/arrays.html
You must create an array similar to creating any object. Next, you must create objects to go inside the array. It's difficult without knowing the rest of your code, but here goes.
private Box[] arrBox = new Box[10];
for(int index=0;index<arrBox.length;index++) {
int color = getColor(index); //I'm making this up
if(color == blue) arrBox[index] = new Box();
}The above code will create a new Box for any index where the color is blue. The indices where the color isn't blue are equal to null. -
Javac compiler Error - cannot resolve symbol - symbol StringBuilder?
Hi ,
I am using hp - ux system with java version "1.4.2.06". when i try to compile a program called CharSequenceDemo.java which is found in the java tutorials at this link
[CharSequenceDemo.java|http://java.sun.com/docs/books/tutorial/java/IandI/examples/CharSequenceDemo.java]
i get the following error:
$/opt/java1.4/bin/javac CharSequenceDemo.java
CharSequenceDemo.java:38: cannot resolve symbol
symbol : class StringBuilder
location: class CharSequenceDemo
StringBuilder sub =
^
CharSequenceDemo.java:39: cannot resolve symbol
symbol : class StringBuilder
location: class CharSequenceDemo
new StringBuilder(s.subSequence(fromEnd(end), fromEnd(start)));
^
CharSequenceDemo.java:44: cannot resolve symbol
symbol : class StringBuilder
location: class CharSequenceDemo
StringBuilder s = new StringBuilder(this.s);
^
CharSequenceDemo.java:44: cannot resolve symbol
symbol : class StringBuilder
location: class CharSequenceDemo
StringBuilder s = new StringBuilder(this.s);
^
4 errors
Please help on how to compile this program.I've been struggling with the same issue. The difference is that my system says I'm using version 1.6.0_05. I've tried running jucheck.exe. It tells me I've got the latest version installed.
Here is the code:
import java.lang.StringBuilder;
import java.util.Formatter;
public class UsingFormatter {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("usage: " +
"java format/UsingFormatter <format string>");
System.exit(0);
String format = args[0];
StringBuilder stringBuilder = new StringBuilder();
Formatter formatter = new Formatter(stringBuilder);
formatter.format("Pi is approximately " + format +
", and e is about " + format, Math.PI, Math.E);
System.out.println(stringBuilder);
}When I type javac UsingFormatter.java, I get:
UsingFormatter.java:1: cannot resolve symbol
symbol : class StringBuilder
location: package lang
import java.lang.StringBuilder;
^
UsingFormatter.java:2: cannot resolve symbol
symbol : class Formatter
location: package util
import java.util.Formatter;
^
UsingFormatter.java:14: cannot resolve symbol
symbol : class StringBuilder
location: class UsingFormatter
StringBuilder stringBuilder = new StringBuilder();
^
UsingFormatter.java:14: cannot resolve symbol
symbol : class StringBuilder
location: class UsingFormatter
StringBuilder stringBuilder = new StringBuilder();
^
UsingFormatter.java:15: cannot resolve symbol
symbol : class Formatter
location: class UsingFormatter
Formatter formatter = new Formatter(stringBuilder);
^
UsingFormatter.java:15: cannot resolve symbol
symbol : class Formatter
location: class UsingFormatter
Formatter formatter = new Formatter(stringBuilder);
^
6 errors
The compiler refuses to recognize the symbols StringBuilder and Formatter.
I have spent hours googling for an answer and trying every suggestion. Nothing works, not even the one about dropping the computer from the rooftop.
Ultimately, what I'm trying to accomplish (in a different program) is to use a text file as a form letter template and replace the %s placeholders with stings from my form object.
Any advice?
Edited by: javastudent_99 on Apr 3, 2008 1:48 PM -
need some help figuring this out. When I try to compile it says:
compile:
[mkdir] Created dir: D:\sk\hiptop-sdk\examples\clock\work\2.3\classes
[javac] Compiling 5 source files to D:\sk\hiptop-sdk\examples\clock\work\2.3
\classes
[javac] D:\sk\hiptop-sdk\examples\clock\work\2.3\source\com\loo432\clock\Mai
nWindow.java:62: illegal start of expression
[javac] public static void recieveEvent() {
[javac] ^
[javac] 1 errorHere's my code
package com.loo432.clock;
import danger.app.Application;
import danger.app.Event;
import danger.ui.Color;
import danger.ui.Font;
import danger.ui.Menu;
import danger.ui.Pen;
import danger.ui.Rect;
import danger.ui.ScreenWindow;
import danger.util.DEBUG;
* Implements the main window class.
class MainWindow
extends ScreenWindow
implements Resources, Commands {
//* -------------------- clockWindow
public MainWindow() {
//* -------------------- adjustActionMenuState
public void adjustActionMenuState(Menu hwMenu) {
//Menu hwMenu = getActionMenu();
hwMenu.removeAllItems();
hwMenu.addFromResource(Application.getCurrentApp().getResources(), ID_MENU_CLOCK, this);
//* -------------------- paint
public void paint(Pen inPen) {
Rect bounds = getBounds();
Font font = Font.findBoldSystemFont();
String message = Application.getCurrentApp().getString(ID_STRING_CLOCK);
clear(inPen);
inPen.setColor(Color.BLACK);
inPen.drawRect(bounds);
inPen.setFont(font);
inPen.drawText((bounds.getWidth() -
font.getWidth(message)) / 2,
(bounds.getHeight() -
(font.getAscent() + font.getDescent())) / 2,
message);
//* -------------------- receiveEvent
* Handles events. Called automatically whenever the application
* receives an event.
public boolean receiveEvent(Event e) {
switch (e.type) {
case EVENT_ONE:
public static void recieveEvent(String[] arguments) {
// get current time and date
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int month = now.get(Calendar.MONTH) + 1;
int day = now.get(Calendar.DAY_OF_MONTH);
int year = now.get(Calendar.YEAR);
// display greeting
if (hour < 12)
System.out.println("Good morning.\n");
else if (hour < 17)
System.out.println("Good afternoon.\n");
else
System.out.println("Good evening.\n");
// begin time message by showing the minutes
System.out.print("It's");
if (minute != 0) {
System.out.print(" " + minute + " ");
System.out.print( (minute != 1) ? "minutes" :
"minute");
System.out.print(" past");
// display the hour
System.out.print(" ");
System.out.print( (hour > 12) ? (hour - 12) : hour );
System.out.print(" o'clock on ");
// display the name of the month
switch (month) {
case (1):
System.out.print("January");
break;
case (2):
System.out.print("February");
break;
case (3):
System.out.print("March");
break;
case (4):
System.out.print("April");
break;
case (5):
System.out.print("May");
break;
case (6):
System.out.print("June");
break;
case (7):
System.out.print("July");
break;
case (8):
System.out.print("August");
break;
case (9):
System.out.print("September");
break;
case (10):
System.out.print("October");
break;
case (11):
System.out.print("November");
break;
case (12):
System.out.print("December");
// display the date and year
System.out.println(" " + day + ", " + year + ".");
DEBUG.p("clock: Received kCmd_One");
return true;
case EVENT_TWO:
// Todo: Insert code here...
DEBUG.p("clock: Received kCmd_Two");
return true;
return super.receiveEvent(e);
//* -------------------- eventWidgetDown
public boolean eventWidgetDown(int inWhichWidget, Event inEvent) {
switch (inWhichWidget) {
case Event.DEVICE_WHEEL:
break;
case Event.DEVICE_MULTIPLE_WHEEL:
break;
case Event.DEVICE_WHEEL_BUTTON:
break;
case Event.DEVICE_ARROW_UP:
break;
case Event.DEVICE_ARROW_DOWN:
break;
case Event.DEVICE_ARROW_LEFT:
break;
case Event.DEVICE_ARROW_RIGHT:
break;
case Event.DEVICE_BUTTON_JUMP:
// Always make sure to call super.eventWidgetUp for this control so the system
// can execute the correct behavior (returning to the Jump screen with phone selected).
break;
return super.eventWidgetDown(inWhichWidget, inEvent);
//* -------------------- eventWidgetUp
public boolean eventWidgetUp(int inWhichWidget, Event inEvent) {
switch (inWhichWidget) {
case Event.DEVICE_WHEEL:
break;
case Event.DEVICE_MULTIPLE_WHEEL:
break;
case Event.DEVICE_WHEEL_BUTTON:
break;
case Event.DEVICE_ARROW_UP:
break;
case Event.DEVICE_ARROW_DOWN:
break;
case Event.DEVICE_ARROW_LEFT:
break;
case Event.DEVICE_ARROW_RIGHT:
break;
This demonstrates how to use a control from Sidekick2 in a way that is still compatible
with original Sidekick devices. We implement the DEVICE_BUTTON_CANCEL event which is
defined in the Sidekick2Events.java file. On original Sidekick devices, this event is
never sent. On Sidekick2 devices, you will get this event and should handle it appropriately.
case Hiptop2Events.DEVICE_BUTTON_CANCEL:
Application.getCurrentApp().returnToLauncher();
return true;
case Event.DEVICE_BUTTON_BACK:
Application.getCurrentApp().returnToLauncher();
return true;
case Event.DEVICE_BUTTON_JUMP:
// Always make sure to call super.eventWidgetUp for this control so the system
// can execute the correct behavior (returning to the Jump screen with phone selected).
break;
return super.eventWidgetUp(inWhichWidget, inEvent);
}The compiler is already telling you exactly where the error is:
[javac] D:\sk\hiptop-sdk\examples\clock\work\2.3\source\com\loo432\clock\MainWindow.java:62: illegal start of expression
[javac] public static void recieveEvent() {
[javac] ^
[javac] 1 errorIt's saying that on line 62 of MainWindow.java, you have an illegal start of expression, and it's showing you exactly the line of code that's causing it.
The fix is to stop doing what you're doing, because it's not valid Java. How you do that depends on what you're trying to accomplish with that particular line of code, which is what I was asking before. -
PLEASE HELP: cannot resolve symbol class
it's showing me the error on the following lines 7 and 9
it says cannot resolve symbol class Name and cannot resolve symbol class Phone
I also have a package name addressBook and it contains two files Entry.java and Address.java
Here is the code:
import java.io.*;
import addressBook.*;
public class AddressDr
public static void main(String[] args)throws IOException
Name name;
Address address;
Phone phone;
Entry entry;
String first, last, middle, street, city, state, zip;
int areaCode, number;
BufferedReader in;
in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outFile;
outFile=new PrintWriter(new FileWriter("Entries"));
System.out.println("Quit entered fot the first name ends the " + "application.");
System.out.print("Enter first name: ");
first=in.readLine();
while (first.compareTo("Quit") !=0)
System.out.print("Enter last name: ");
last=in.readLine();
System.out.print("Enter middle name: ");
middle=in.readLine();
name=new Name(first, last, middle);
System.out.print("Enter street address: ");
street=in.readLine();
System.out.print("Enter city: ");
city=in.readLine();
System.out.print("Enter state: ");
state=in.readLine();
System.out.print("Enter ZIP code: ");
zip=in.readLine();
address=new Address(street, city, state, zip);
System.out.print("Enter areaCode: ");
areaCode = Integer.parseInt(in.readLine());
System.out.print("Enter number: ");
number=Integer.parseInt(in.readLine());
phone=new Phone(areaCode, number);
entry= new Entry(name, address, phone);
entry.writeToFile(outFile);
System.out.print("Enter first name: ");
first=in.readLine();
outFile.close();
}OK. Here is how I did it.
I have AddressDr which is Address driver.
I have two files Address and Entry which in package addressBook.
AddressDr:
import java.io.*;
import addressBook.*;
public class AddressDr
public static void main(String[] args)throws IOException
Name name;
Address address;
Phone phone;
Entry entry;
String first, last, middle, street, city, state, zip;
int areaCode, number;
BufferedReader in;
in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outFile;
outFile=new PrintWriter(new FileWriter("Entries"));
System.out.println("Quit entered fot the first name ends the " + "application.");
System.out.print("Enter first name: ");
first=in.readLine();
while (first.compareTo("Quit") !=0)
System.out.print("Enter last name: ");
last=in.readLine();
System.out.print("Enter middle name: ");
middle=in.readLine();
name=new Name(first, last, middle);
System.out.print("Enter street address: ");
street=in.readLine();
System.out.print("Enter city: ");
city=in.readLine();
System.out.print("Enter state: ");
state=in.readLine();
System.out.print("Enter ZIP code: ");
zip=in.readLine();
address=new Address(street, city, state, zip);
System.out.print("Enter areaCode: ");
areaCode = Integer.parseInt(in.readLine());
System.out.print("Enter number: ");
number=Integer.parseInt(in.readLine());
phone=new Phone(areaCode, number);
entry= new Entry(name, address, phone);
entry.writeToFile(outFile);
System.out.print("Enter first name: ");
first=in.readLine();
outFile.close();
Entry:
package addressBook;
import java.io.*;
public class Entry
Name name;
Address address;
Phone phone;
public Entry(Name newName, Address newAddress, Phone phoneNumber)
name = newName;
address = newAddress;
phone = phoneNumber;
public Name knowName()
return name;
public Address knowAddress()
return address;
public Phone knowPhone()
return phone;
public void writeToFile(PrintWriter outFile)
outFile.println(name.knowFirstName());
outFile.println(name.knowLastName());
outFile.println(name.knowMiddleName());
oufFile.println(address.knowStreet());
outFile.println(address.knowState());
outFile.println(address.knowCity());
outFile.println(address.knowZip());
outFile.println(phone.knowAreaCode());
outFile.println(phone.knowDigits());
Address:
package addressBook;
public class Address
String street;
String city;
String state;
String zipCode;
public Address(String newStreet, String newCity, String newState, String zip)
street=newStreet;
city=newCity;
state=newState;
zipCode=zip;
public String knowStreet()
return street;
public String knowCity()
return city;
public String knowState()
return state;
public String knowZip()
return zipCode;
} -
ERROR MESSAGE: 20: illegal start of expression
There is something wrong with my program because I have one error and it says "illegal start of expression" and all of my parenthesis and brackets are correct what else is wrong. Here is my program:
import javax.swing.*;
import java.util.*;
public class StudentApp
public static void main(String [] args) throws NullPointerException
//declare variables and initialize
String sID, sName, sHoursStr;
int choice = 0, sHours, i;
Student aStudent = Null;
Vector sVector = new Vector();
//add objects to Vector
Vector studentVector = new Vector();
studentVector = addStudent(studentVector);
sVector.add(aStudent);
public static Vector addStudent(Vector sVector)
public static Vector addStudent(Vector sVector)
sVector.remove(aStudent);
aStudent = (Student) sVector.get(i);
sID = aStudent.getID();
aStudent = (Student) sVector.get(i);
sHours = aStudent.getHours();
//get objects from a vector and print
for(i = 0; i < sVector.size(); i++)
aStudent = (String) sVector.get(i);
System.out.println(aStudent);
//copy vector contents into an Array
String [] anArray = new String[sVector.size()];
sVector.copyInto(anArray);
for(j = 0; j < anArray.length; j++)
System.out.println(anArray[j]);
System.exit(0);
System.exit(0);
public static Student[] addStudent(Student [] anArray)
String sID = JOptionPane.showInputDialog("Enter student's ID: ");
String sName = JOptionPane.showInputDialog("Enter student's name: ");
String sHoursStr = JOptionPane.showInputDialog("Enter student's hours: ");
int sHours = Integer.parseInt(sHoursStr);
Student aStudent = new Student(sID, sName, sHours);
for(int i = 0; i < anArray.length; i++)
if(anArray.getID() == "")
anArray[i] = aStudent;
System.out.println(anArray[i]);
break;
return(anArray);
public static void addHours(Student [] anArray)
int totalHours = 0;
for(int i = 0; i < anArray.length; i++)
totalHours += anArray[i].getHours();
JOptionPane.showMessageDialog(null, "Total hours are: " + totalHours);
public static void findStudent(Student [] anArray)
String requestedID = JOptionPane.showInputDialog("Enter ID of student: ");
boolean foundIt = false;
for(int i = 0; i < anArray.length; i++)
if(anArray[i].getID().equals(requestedID))
JOptionPane.showMessageDialog(null, anArray[i]);
foundIt = true;
break;
if(!foundIt)
JOptionPane.showMessageDialog(null, "Student not found");
Could someone help me out please?import javax.swing.*;
import java.util.*;
public class StudentApp
public static void main(String [] args) throws NullPointerException
//declare variables and initialize
String sID, sName, sHoursStr;
int choice = 0, sHours, i;
Student aStudent = Null;
Vector sVector = new Vector();
//add objects to Vector
Vector studentVector = new Vector();
studentVector = addStudent(studentVector);
sVector.add(aStudent);
//get objects from a vector and print
for(i = 0; i < sVector.size(); i++)
aStudent = (String) sVector.get(i);
System.out.println(aStudent);
//copy vector contents into an Array
String [] anArray = new String[sVector.size()];
sVector.copyInto(anArray);
for(j = 0; j < anArray.length; j++)
System.out.println(anArray[j]);
for(i = 0; i < studentArray.length; i++)
studentArray[i] = new Student(); // load the array with empty data
while(choice != 4) // keep repeating the menu until 4 is selected
String instructions = "Enter\n"
+ " 1 to add a Student\n"
+ " 2 to delete a Student given the ID\n"
+ " 3 to sum and display the semester hours for all the current Students\n"
+ " 4 to quit";
String choiceStr = JOptionPane.showInputDialog(instructions);
choice = Integer.parseInt(choiceStr);
switch(choice)
case 1:
studentArray = addStudent(studentArray); // call method, send array
break;
case 2:
deleteStudent(studentArray); // call method, send array
break;
case 3:
addHours(studentArray); // call method, send array
break;
} // end switch
System.exit(0);
} // end while
System.exit(0);
public static Vector addStudent(Vector sVector)
public static Vector addStudent(Vector sVector)
sVector.remove(aStudent);
aStudent = (Student) sVector.get(i);
sID = aStudent.getID();
aStudent = (Student) sVector.get(i);
sHours = aStudent.getHours();
Vector studentVector = new Vector();
studentVector = addStudent(studentVector);
sVector.add(aStudent);
String sID = JOptionPane.showInputDialog("Enter student's ID: ");
String sName = JOptionPane.showInputDialog("Enter student's name: ");
String sHoursStr = JOptionPane.showInputDialog("Enter student's hours: ");
int sHours = Integer.parseInt(sHoursStr);
Student aStudent = new Student(sID, sName, sHours);
for(int i = 0; i < anArray.length; i++)
if(anArray.getID() == "")
anArray[i] = aStudent;
System.out.println(anArray[i]);
break;
return(anArray);
System.exit(0);
public static void deleteStudent(Student [] anArray)
String requestedID = JOptionPane.showInputDialog("Enter ID of student that you would like to delete: ");
sVector.remove(aStudent);
aStudent = (Student) sVector.get(i);
sID = aStudent.getID();
sVector.remove(aStudent);
if(!foundIt)
JOptionPane.showMessageDialog(null, "Student not found");
public static void addHours(Student [] anArray)
for(i = 0; i < sVector.get; i++)
aStudent = (Student) sVector.get(i);
sHours = aStudent.getHours();
totalHours += sHours; // add up hours
JOptionPane.showMessageDialog(null, "Total hours are: " + totalHours);
Here is my program.. can someone please fix it? -
Cannot resolve symbol: HashMap, put and strings
Hi,
why woudl I get a "cannot resolve symbol" at the line indicated by <============
sec_cands[i] should be a String already.
Can someone help me ?
Thanks in advance.
HashMap temp = new HashMap();
String [] sec_cands = sec_ex.getTargetPhrases();
int sec_length = sec_cands.length;
String [] allCands = new String[total_length];
if (sec_length > 0 ) {
for (int i = 0; i < sec_cands.length; i++)
allCands[fr_length+i] = sec_cands;
temp.put(sec_cands[i], true); <=================Sorry, I accidentally deleted a subscript from a line. The real code is "
HashMap temp = new HashMap();
String [] sec_cands = sec_ex.getTargetPhrases();
int sec_length = sec_cands.length;
String [] allCands = new String[total_length];
if (sec_length > 0 ) {
for (int i = 0; i < sec_cands.length; i++)
allCands[fr_length+i] = sec_cands;
temp.put(sec_cands[i], true); <================= -
"cannot resolve symbol" in a Timer !!!Please Help!!!
I am doing a program for a class which involves timers. I am using JCreator and when i try to construct a new timer, the compiler points to the "new" in the line:
Timer T1=new Timer(interval, ActionListener);
^
This is what it looks like and the error reads: cannot resolve symbol; constructor Timer.
please tell me if yiou have any information or suggestions as to how this error might be remedied.Sure, here it is:
import java.awt.event.*;
import javax.swing.Timer;
import javax.swing.JOptionPane;
import java.util.*;
interface ActionListener
void actionPerformed(ActionEvent event);
class Ploid
public static void main(String[] args)
class Car implements ActionListener
int mpg=30;
int mph=35;
int gtank=20;
int interval;
int changer;
int totalmiles;
Car(int x)
interval=x;
public void actionPerformed(ActionEvent event)
for(int c=0;c<(interval/1000);c++)
totalmiles=totalmiles+mph;
int hyt=mpg*gtank;
if(totalmiles>hyt)
int y=totalmiles-hyt;
totalmiles=totalmiles-y;
System.out.println(totalmiles);
else
System.out.println(totalmiles);
class SUV implements ActionListener
int mpg=15;
int mph=55;
int gtank=30;
int interval;
int changer;
int totalmiles;
SUV(int x)
interval=x;
public void actionPerformed(ActionEvent event)
for(int c=0;c<(interval/1000);c++)
totalmiles=totalmiles+mph;
int hyt=mpg*gtank;
if(totalmiles>hyt)
int y=totalmiles-hyt;
totalmiles=totalmiles-y;
System.out.println(totalmiles);
else
System.out.println(totalmiles);
class Semi implements ActionListener
int mpg=60;
int mph=80;
int gtank=50;
int interval;
int changer;
int totalmiles;
Semi(int x)
interval=x;
public void actionPerformed(ActionEvent event)
for(int c=0;c<(interval/1000);c++)
totalmiles=totalmiles+mph;
int hyt=mpg*gtank;
if(totalmiles>hyt)
int y=totalmiles-hyt;
totalmiles=totalmiles-y;
System.out.println(totalmiles);
else
System.out.println(totalmiles);
String flag="y";
String trav=JOptionPane.showInputDialog("How long do you want to drive?(1000=1 hour)");
int t1=Integer.parseInt(trav);
Car listen=new Car(t1);
SUV listener2=new SUV(t1);
Semi listener3=new Semi(t1);
final int t2=t1/1000;
final int t3=t1/t2;
ActionListener listener=null;
Timer T1=new Timer(t3, listener);
Timer T2=new Timer(t3, listener);
Timer T3=new Timer(t3, listener);
while(flag.equals("y"))
T1.start();
T2.start();
T3.start();
String g=JOptionPane.showInputDialog("Do you want to drive again?");
if((g.equals("y"))||(g.equals("Y")))
System.out.println("Let's Drive!");
else
flag=g;
System.exit(0);
}Here is the errors:
[errors]
A:\Ploid2.java:116: cannot resolve symbol
symbol : constructor Timer (int,ActionListener)
location: class javax.swing.Timer
Timer T1=new Timer(t3, listener);
^
A:\Ploid2.java:117: cannot resolve symbol
symbol : constructor Timer (int,ActionListener)
location: class javax.swing.Timer
Timer T2=new Timer(t3, listener);
^
A:\Ploid2.java:118: cannot resolve symbol
symbol : constructor Timer (int,ActionListener)
location: class javax.swing.Timer
Timer T3=new Timer(t3, listener);
^
3 errors
Process completed.
[errors]
****There is the source code and the errors the compiler returns. That should be more help.**** -
JSP page "cannot resolve symbol"
Hi,
I'm using j2sdk1.4.2_01 and tomcat-5.0.13. I'm developing within Eclipse 3.0.0 with the Tomcat plugin.
In my project ("Agenda2") i only created one class ("Persona"), that is correctely compiled (%TOMCAT_HOME%\webapps\Agenda2\WEB-INF\src\Persona.java results in %TOMCAT_HOME%\webapps\Agenda2\WEB-INF\classes\Persona.class, and 0 problems are shown in the Problems list.
In %TOMCAT_HOME%\webapps\Agenda2 i have my Edit.jsp, that begins with these lines:
<%@ page language="java" contentType="text/html" %>
<HTML>
<HEAD>
<TITLE>Edit</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="personaAtt" class="Persona">
<jsp:setProperty name="personaAtt" property="*" />
</jsp:useBean>
....When i call the JSP from the browser, i get this error:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 8 in the jsp file: /Edit.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Programmi\Java\tomcat-5.0.13\webapps\Agenda2\work\org\apache\jsp\Edit_jsp.java:48: cannot resolve symbol
symbol : class Persona
location: class org.apache.jsp.Edit_jsp
Persona personaAtt = null;
^The error message mentions line 8, which is the one following <BODY>, that is
<jsp:useBean id="personaAtt" class="Persona">My impression is that there is some path problem, but despite my tries i can't get it.
The folders tree under %TOMCAT_HOME%\webapps\Agenda2\ is:
-WEB-INF
--classes
--lib
--src
-work
--org
---apache
----jspDoes anybody can see the problem ?Thanks! I'm going to try to put the class into a package as both you have suggested, and i'll post here the result.
In the meantime i have a related newbie question:
putting the class into a package, is this kind of a workaround, or it's the "normal thing" ?
I mean, is it mandatory to put classes into a package in order to import them from JSP pages ?
It was my understanding that it isn't mandatory, but - from your replies and many other posts in this forum - i'm starting to think that i'm wrong. -
Solaris Deployment Failure for cannot resolve symbol on PersistentContainer
Hello, I'm having trouble diagnosing the following deployment failure.
What are some common causes of this? My server was created using an
Express Integration domain with some custom JMS destinations added
afterwards via the console. I am deploying an application built with
Workshop (straight from workshop). I copied over an application from
Windows to Solaris, deleted the .workshop directory and .beabuild.txt
and rebuilt the application to deploy.
I get this error a few times.
####<Aug 21, 2003 10:48:19 AM EDT> <Info> <EJB> <rhino> <cgServer>
<ExecuteThread: '1' for queue: 'weblogic.kernel.System'> <<WLS Kernel>>
<> <BEA-012033> <Compiling generated EJB classes produced the following
Java compiler output:
/export/data/ident/bea/user_projects/domains/ident1Server.conf/./cgServer/.wlnotdelete/EJBCompilerCache/-7dxi2hv35mro/com/bea/wlwgen/PersistentContainer_3fq3ar_Impl.java:143:
cannot resolve symbol
symbol : class BMPContainerBean$DuplicateKeyRemoteException
location: package bean
perchance you meant 'BMPContainerBean.DuplicateKeyRemoteException'
throws
com.bea.wlw.runtime.core.bean.BMPContainerBean$DuplicateKeyRemoteException
^
1 error
This then causes other errors repeating that the deployment failed (let
me know if you need more to diagnose this):
Exception:weblogic.management.ApplicationException: prepare failed for
.workshop/myApp/EJB/myProc_1trtqtoxcz4uv
Module: .workshop/myApp/EJB/myProc_1trtqtoxcz4uv Error:
Exception preparing module:
EJBModule(.workshop/myApp/EJB/myProc_1trtqtoxcz4uv,status=NEW)
Unable to deploy EJB: .workshop/myApp/EJB/myProc_1trtqtoxcz4uv from
.workshop/myApp/EJB/myProc_1trtqtoxcz4uv:
Compiler failed executable.execBut by default WLS8.1 comes with jdk141_02 ...correct ?
AND what i understand is that...the bug you posted is related to a bug in jdk1.4.2
....correct ??
correct me if i wrong.
-sangita
Steven Ostrowski <[email protected]> wrote:
It looks like this is a bug in the BEA-generated code that is then
compiled by WLS. The generated code was using the Class1$Class2 notation
to reference the class, but since $ is a valid character in the class
name, this does not behave as intended. This used to be a bug in
pre-1.4.2 but is now fixed in 1.4.2 (look at bug 4635044, and this is
also mentioned in the 1.4.2 release notes and the Java Developer forums).
The generated code should be:
com.bea.wlw.runtime.core.bean.BMPContainerBean.DuplicateKeyRemoteException
not
com.bea.wlw.runtime.core.bean.BMPContainerBean$DuplicateKeyRemoteException
Thanks again for the good response. I'll send this in to BEA support.
Steven Ostrowski wrote:
One other thing to add, this was fixed by changing the JAVA_HOME
variable inside of the startWeblogic.sh script. Setting it in workshop
did not change anything.
Steven Ostrowski wrote:
Wow, you hit it right on target! I was using 1.4.2 then tried it on
1.4.1_03 and it deployed fine.
Is this a bug in BEA or in the JDK? In either case, where should I
report this bug?
Thanks again
Rob Woollen wrote:
What version of the JDK are you using? I believe they changed the
inner class naming conventions in 1.4.2, and it's breaking lots of
people.
-- Rob
Steven Ostrowski wrote:
Hello, I'm having trouble diagnosing the following deployment
failure. What are some common causes of this? My server was created
using an Express Integration domain with some custom JMS
destinations added afterwards via the console. I am deploying an
application built with Workshop (straight from workshop). I copied
over an application from Windows to Solaris, deleted the .workshop
directory and .beabuild.txt and rebuilt the application to deploy.
I get this error a few times.
####<Aug 21, 2003 10:48:19 AM EDT> <Info> <EJB> <rhino> <cgServer>
<ExecuteThread: '1' for queue: 'weblogic.kernel.System'> <<WLS
Kernel>> <> <BEA-012033> <Compiling generated EJB classes produced
the following Java compiler output:
/export/data/ident/bea/user_projects/domains/ident1Server.conf/./cgServer/.wlnotdelete/EJBCompilerCache/-7dxi2hv35mro/com/bea/wlwgen/PersistentContainer_3fq3ar_Impl.java:143:
cannot resolve symbol
symbol : class BMPContainerBean$DuplicateKeyRemoteException
location: package bean
perchance you meant 'BMPContainerBean.DuplicateKeyRemoteException'
throws
com.bea.wlw.runtime.core.bean.BMPContainerBean$DuplicateKeyRemoteException
^
1 error
This then causes other errors repeating that the deployment failed
(let me know if you need more to diagnose this):
Exception:weblogic.management.ApplicationException: prepare failed
for .workshop/myApp/EJB/myProc_1trtqtoxcz4uv
Module: .workshop/myApp/EJB/myProc_1trtqtoxcz4uv Error:
Exception preparing module:
EJBModule(.workshop/myApp/EJB/myProc_1trtqtoxcz4uv,status=NEW)
Unable to deploy EJB: .workshop/myApp/EJB/myProc_1trtqtoxcz4uv from
.workshop/myApp/EJB/myProc_1trtqtoxcz4uv:
Compiler failed executable.exec
Maybe you are looking for
-
Sender File Adapter - No error, but not generating any message
I am working on a file to RFC scenario. The sender file adapter is using content conversion to read a comma delimited file. The file is being picked up and archived correctly, and the adapter monitor does not show any errors. However, the process
-
Revision: 762 Author: [email protected] Date: 2008-03-10 07:44:49 -0700 (Mon, 10 Mar 2008) Log Message: -update the 3.0 branch to use build.properties to create the flex-sdk-description.xml Modified Paths: flex/sdk/branches/3.0.x/build.properties fle
-
IMovie crashes when I try to add audio file
Things used to work fine, but now iMovie "quits unexpectedly" when I start to drag an audio file from the list on the right pane. Any thoughts on how to remedy this?
-
Allocate exception for servlet jsp
Hi everybody. I'm using appserver 7 2004q2UR3 on a linux box (RHEL 3). Sometimes, when we change some class or jsp included in a webapp, that application fails with the next error: javax.servlet.ServletException: Cannot allocate servlet jsp because i
-
Adjusting field size depending on data returned
Hi I need to display output from an xmltype column in the database. How can I set the field so that it adjusts its size depending on the amount of data returned for that xml column? Thx!