Cannot resolve symbol switch( faces[i] ){
ok, back to "how do i"
... can u take a peek at this & tell me what i've done wrong? Please?
i have an array that holds the card count,
faces[2][][][][3][][][][][] <<<< has 2 aces & 3 5's
and i am trying to acces this array in method EVALUATE
method EVALUATE is called from Class Ex3_10c
and evaluate is an inner class??
problem:
C:\J\jhtp\exerc\chptr10\Ex10_3c.java:100: cannot resolve symbol
symbol : variable faces
location: class Ex10_3c
switch(faces){
^
C:\J\jhtp\exerc\chptr10\Ex10_3c.java:103: cannot resolve symbol
symbol : variable faces
location: class Ex10_3c
displayHand1.append( "\n" + "Case 1: " + faces[i] );
public class Ex10_3c extends JFrame {
private Card deck[];
private Card hand[];
private int currentCard;
private JButton dealButton, shuffleButton;
//private JTextField displayHand1;
private JTextArea displayHand1;
private JLabel status;
public Ex10_3c()
super( "Card Dealing Program" );
final int faces[] = new int[13];
int suits[] = new int[4];
deck = new Card[ 52 ];
currentCard = -1;
hand = new Card[5];
for ( int i = 0; i < deck.length; i++ )
deck[ i ] = new Card( i%13,i/13 );
//deck[i] = new Card(face[i%13],suits[i/13]<<<<WRONG understand what your passing
Container c = getContentPane();
c.setLayout( new FlowLayout() );
displayHand1 = new JTextArea( 9,15);
dealButton = new JButton( "Deal Hand1" );
dealButton.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
displayHand1.setText("");
int cntr = 0;
while ( cntr<5 ){
Card dealt = dealCard();
if ( dealt != null ) {
hand[cntr] = dealt;
displayHand1.append( "\n" + dealt.toString() );
status.setText( "Card #: " + currentCard );
if (cntr==5){evaluate();}
cntr++;
else {
displayHand1.setText(
"NO MORE CARDS TO DEAL" );
status.setText(
"Shuffle cards to continue" );
cntr = 6;
}//endo of while
}//end of actionPerformed
}//endof actionListener
c.add( dealButton );
shuffleButton = new JButton( "Shuffle cards" );
shuffleButton.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
displayHand1.setText( "SHUFFLING ..." );
shuffle();
displayHand1.setText( "DECK IS SHUFFLED" );
c.add( shuffleButton );
displayHand1 = new JTextArea( 9,15 );
displayHand1.setEditable( false );
c.add( displayHand1 );
status = new JLabel();
c.add( status );
setSize( 300, 300 ); // set the window size
show(); // show the window
public String evaluate(){
//go thru array & determine if its holding counts > 2, if so then good value
//you have an array of 13,holding cnt within array for each face-card in hand
//you have an array of 4,holding cnt within array for each suit-card in hand
//does hand[] contain 2 of the same numbers
for (int i=0; i<13; i++){
switch(faces){
case 0:
displayHand1.append( "\n" + "Case 1: " + faces[i] );
case 1:
displayHand1.append( "\n" + "Case 2: " + faces[i] );
case 2:
displayHand1.append( "\n" + "Case 3: " + faces[i] );
case 3:
displayHand1.append( "\n" + "Case 4: " + faces[i] );
default:
displayHand1.append( "\n" + "Case default: ");
}//end of switch
}//end of for
}//end of evaluate
public void shuffle()
currentCard = -1;
for ( int i = 0; i < deck.length; i++ ) {
int j = ( int ) ( Math.random() * 52 );
Card temp = deck[ i ]; // swap
deck[ i ] = deck[ j ]; // the
deck[ j ] = temp; // cards
dealButton.setEnabled( true );
public Card dealCard()
if ( ++currentCard < deck.length )
return deck[ currentCard ];
else {
dealButton.setEnabled( false );
return null;
public static void main( String args[] )
Ex10_3c app = new Ex10_3c();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
System.exit( 0 );
class Card {
private int face;
private int suit;
public Card( int f, int s )
face = f;
suit = s;
public int getFace(){
return face;
public int getSuit(){
return suit;
public String toString() { return face + " of " + suit; }
Hey,
faces is not in scope in the evaluate function, because it is declared in the constructor, but used in another method. A variable is valid until the next (matching) }.
Declaring faces outside of the function will do the trick.
Kind regards,
Levi
Similar Messages
-
Cannot resolve symbol: method getCodeBase ()
I`m creating a dice game that makes a sound when player wins or looses. Instaed I`m getting the following error message: Cannot resolve symbol: method getCodeBase (). I think this depends on the fact that I have a separate applet launcher but cannot figure out how to solve this, please help!!
This is the applet launcher
import javax.swing.*;
import java.awt.*;
// [MC] Public class DiceApplet
public class DiceApplet extends JApplet
// [MC] Constructor.
public DiceApplet()
// [MC] Sets the contentPane property. This method is called by the constructor.
this.setContentPane(new DicePanel());
This is the die class
import java.awt.*;
import javax.swing.*;
// [MC] Public class Die
public class Die extends JPanel
// ======================================================================
// [MC] Instance variable.
private int myFaceValue; // [MC] Value that shows on face of die.
// [MC] End instance variable.
// ======================================================================
// [MC] Constructor.
// [MC] Initialises die to blue background and initial roll.
public Die()
// [MC] Sets the background colour of the die to blue.
setBackground(Color.blue);
// [MC] Sets the foreground colour of the die to gray.
setForeground(Color.gray);
// [MC] Sets the border colour of the die to white.
setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.white));
// [MC] Sets to random initial value.
roll();
} // [MC] End constructor.
// ======================================================================
// [MC] Method roll.
// [MC] Produces random roll in the range of 1 to 6.
public int roll()
int val = (int)(6*Math.random() + 1); // [MC] Range from 1 to 6.
setValue(val);
return val; // [MC] Returns a value from 1 to 6.
} // [MC] End method roll.
// [MC] Method setValue
// [MC] Sets the value of the die. Causes repaint.
public void setValue(int dots)
myFaceValue = dots;
repaint(); // [MC] Value has changed, must repaint.
} // [MC] End method setValue.
// ======================================================================
// [MC] Method getValue.
// [MC] Returns result of last roll.
public int getValue()
return myFaceValue;
} // [MC] End method getValue.
// ======================================================================
// [MC] Method paintComponent.
// [MC] Draws dots of die face.
public void paintComponent(Graphics g)
// [MC] Call superclass's paint method.
super.paintComponent(g);
// [MC] Sets panel width.
int w = getWidth();
// [MC] Sets panel height.
int h = getHeight();
// [MC] Draws border.
g.drawRect(0, 0, w-1, h-1);
// Switch
switch (myFaceValue)
case 1: drawDot(g, w/2, h/2);
break;
case 3: drawDot(g, w/2, h/2);
case 2: drawDot(g, w/4, h/4);
drawDot(g, 3*w/4, 3*h/4);
break;
case 5: drawDot(g, w/2, h/2);
case 4: drawDot(g, w/4, h/4);
drawDot(g, 3*w/4, 3*h/4);
drawDot(g, 3*w/4, h/4);
drawDot(g, w/4, 3*h/4);
break;
case 6: drawDot(g, w/4, h/4);
drawDot(g, 3*w/4, 3*h/4);
drawDot(g, 3*w/4, h/4);
drawDot(g, w/4, 3*h/4);
drawDot(g, w/4, h/2);
drawDot(g, 3*w/4, h/2);
break;
} // [MC] End switch.
} // [MC] End method paintComponent.
// [MC] Method drawDot.
/** Utility method used by paintComponent(). */
private void drawDot(Graphics g, int x, int y)
// [MC] Gets panel width.
int w = getWidth();
// [MC] Gets panel height.
int h = getHeight();
// [MC] Local variable.
int d;
// [MC] Sets diameter of dot proportional to panel size.
d = (w + h)/10;
// [MC] Sets colour for dot to white.
Color myDotColor = new Color(255, 255, 255);
g.setColor(myDotColor);
// [MC] Draws dot.
g.fillOval(x-d/2, y-d/2, d, d);
} // [MC] End method drawDot.
This is the class giving the error message
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.applet.AudioClip;
import java.applet.Applet;
import java.net.*;
// [MC] Public class DicePanel
public class DicePanel extends JPanel
// ======================================================================
// [MC] Instance variables.
// [MC] Creates new instances of the component for the die.
private Die myLeftDie; // [MC] Component for left die.
private Die myRightDie; // [MC] Component for right die.
// [MC] Creates the button (rollButton) to roll the dice.
private JButton rollButton = new JButton("Roll Dice");
// [MC] Creates the text fields. Creates new instance of JTextField.
// [MC] Creates the text field (rollNumberTextField) to display number of rolls.
private JTextField rollNumberTextField = new JTextField(20);
// [MC] Creates the text field (rollResultTextField) to display result of roll.
private JTextField rollResultTextField = new JTextField(20);
// [MC] Creates the text field (rollPointsTextField) to display the player`s points.
private JTextField rollPointsTextField = new JTextField(20);
// [MC] Creates the text field (gameFinalResultTextField) to display the final game result.
private JTextField gameFinalResultTextField = new JTextField(20);
// [MC] Initialises instance variables declared in the inner listeners.
private int result = 0, resultLeft = 0, resultRight = 0;
private int rolls = 0;
private int finalResult = 0;
private int points = 0;
private boolean first = true;
private AudioClip winClip = null;
private AudioClip looseClip = null;
// ======================================================================
// [MC] Constructor. Creates border layout panel.
DicePanel()
// [MC] Creates the dice
myLeftDie = new Die();
myRightDie = new Die();
// ======================================================================
// [MC] Creates the buttons.
// [MC] Creates the button (newGameButton) to start new game.
JButton newGameButton = new JButton("New Game");
// *[MC] Creates the button (rollButton) to roll the dice.
// *JButton rollButton = new JButton("Roll Dice");
// [MC] Sets the font of the buttons.
// [MC[ Sets the font of the button newGameButton.
newGameButton.setFont(new Font("Batang", Font.BOLD, 20));
// [MC[ Sets the font of the button rollButton.
rollButton.setFont(new Font("Batang", Font.BOLD, 20));
// [MC] Sets the button border format.
// [MC] Sets the button with compound borders.
Border compound;
// [MC] Border format local variables.
Border blackline, raisedetched, loweredetched, raisedbevel, loweredbevel, empty;
// [MC] Initialises border formats.
//blackline = BorderFactory.createLineBorder(Color.gray);
raisedetched = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
raisedbevel = BorderFactory.createRaisedBevelBorder();
//loweredbevel = BorderFactory.createLoweredBevelBorder();
// [MC] Sets compound border format.
compound = BorderFactory.createCompoundBorder(raisedetched, raisedbevel);
// [MC] Sets the button (newGameButton) with compound border format.
newGameButton.setBorder(compound);
// [MC] Sets the button (rollButton) with compound border format.
rollButton.setBorder(compound);
// [MC] Adds listener.
// [MC] Adds listener to rollButton.
rollButton.addActionListener(new RollListener());
// [MC] Adds listener to newGameButton.
newGameButton.addActionListener(new NewGameListener());
// ======================================================================
// [MC] Creates the labels. Creates new instance of JLabel.
// [MC] Creates the label (rollNumberLabel) for the number of rolls.
JLabel rollNumberLabel = new JLabel("Roll Number");
// [MC] Creates the label (rollResultLabel) for the result of roll.
JLabel rollResultLabel = new JLabel("Roll Result");
// [MC] Creates the label (rollPointsLabel) for the player`s points.
JLabel rollPointsLabel = new JLabel("Player Points");
// [MC] Creates the label (gameFinalResult) for the final game result.
JLabel gameFinalResultLabel = new JLabel("Final Result");
// [MC] Sets the label font.
rollNumberLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
rollResultLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
rollPointsLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
gameFinalResultLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
// [MC] Sets the label title alignment.
rollNumberLabel.setHorizontalAlignment(JLabel.CENTER);
rollResultLabel.setHorizontalAlignment(JLabel.CENTER);
rollPointsLabel.setHorizontalAlignment(JLabel.CENTER);
gameFinalResultLabel.setHorizontalAlignment(JLabel.CENTER);
// [MC] Sets the label border format.
//rollNumberLabel.setBorder(loweredetched);
//rollResultLabel.setBorder(loweredetched);
//rollPointsLabel.setBorder(loweredetched);
//gameFinalResultLabel.setBorder(loweredetched);
// ======================================================================
// [MC] Sets the text field font.
rollNumberTextField.setFont(new Font("Sansserif", Font.PLAIN, 16));
rollResultTextField.setFont(new Font("Sansserif", Font.PLAIN, 16));
rollPointsTextField.setFont(new Font("Sansserif", Font.PLAIN, 16));
gameFinalResultTextField.setFont(new Font("Sansserif", Font.BOLD, 16));
// [MC] Sets the text field text alignment.
rollNumberTextField.setHorizontalAlignment(JTextField.CENTER);
rollResultTextField.setHorizontalAlignment(JTextField.CENTER);
rollPointsTextField.setHorizontalAlignment(JTextField.CENTER);
gameFinalResultTextField.setHorizontalAlignment(JTextField.CENTER);
// [MC] Sets the text field text colour.
gameFinalResultTextField.setForeground(Color.blue);
// [MC] Sets the text field to not editable.
rollNumberTextField.setEditable(false);
rollResultTextField.setEditable(false);
rollPointsTextField.setEditable(false);
gameFinalResultTextField.setEditable(false);
// ======================================================================
// [MC] Gets sounds.
winClip = getAudioClip(getCodeBase(), "bunny1.au");
looseClip = getAudioClip(getCodeBase(), "bunny1.au");
// ======================================================================
// [MC] Sets the layout manager (GridBagLayout) for this container.
this.setLayout(new GridBagLayout());
// [MC] Creates new instance of GridBagConstraints.
GridBagConstraints c = new GridBagConstraints();
// [MC] Makes the component fill its display area entirely.
c.fill = GridBagConstraints.BOTH;
// [MC] Layouts components.
// [MC] Adds the component newGameButton to this container.
c.gridx = 0; // [MC] Makes this component the leftmost column (column 1).
c.gridy = 0; // [MC] Makes this component the uppermost row (row 1).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 2; // [MC] Specifies the number of columns the component uses (2 columns).
this.add(newGameButton, c); // [MC] Adds the button newGameButton.
// [MC] Adds the component rollButton to this container.
c.gridx = 2; // [MC] Makes this component the third column from left (column 3).
c.gridy = 0; // [MC] Make this component the uppermost row (row 1).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 rows).
c.gridwidth = 2; // [MC] Specifies the number of columns the component uses (2 columns).
this.add(rollButton, c); // [MC] Adds the button rollButton.
// [MC] Adds the component rollNumberLabel to this container.
c.gridx = 0; // [MC] Makes this component the leftmost column (column 1).
c.gridy = 3; // [MC] Makes this component the third row from top (row 3).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
c.weightx = 0.1; // [MC] Requests any extra vertical (column) space.
this.add(rollNumberLabel, c); // [MC] Adds the label rollNumberLabel.
// [MC] Adds the component rollResultLabel to this container.
c.gridx = 1; // [MC] Makes this component the second column from left (column 2).
c.gridy = 3; // [MC] Makes this component the third row from top (row 3).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
this.add(rollResultLabel, c); // [MC] Adds the label rollResultLabel.
// [MC] Adds the component rollPointsLabel to this container.
c.gridx = 2; // [MC] Makes this component the third column from left (column 3).
c.gridy = 3; // [MC] Makes this component the third row from top (row 3).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
this.add(rollPointsLabel, c); // [MC] Adds the label rollPointsLabel.
// [MC] Adds the component gameFinalResultLabel to this container.
c.gridx = 3; // [MC] Makes this component the fourth column from left (column 4).
c.gridy = 3; // [MC] Makes this component the third row from top (row 3).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
this.add(gameFinalResultLabel, c); // [MC] Adds the label gameFinalResultLabel.
// [MC] Adds the component rollNumberTextField to this container.
c.gridx = 0; // [MC] Makes this component the leftmost column (column 1).
c.gridy = 4; // [MC] Makes this component the fourth row from top (row 4).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
c.weightx = 0.1; // [MC] Requests any extra vertical (column) space.
this.add(rollNumberTextField, c); // [MC] Adds the text field rollNumberTextField.
// [MC] Adds the component rollResultTextField to this container.
c.gridx = 1; // [MC] Makes this component the second column from left (column 2).
c.gridy = 4; // [MC] Makes this component the fourth row from top (row 4).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
this.add(rollResultTextField, c); // [MC] Adds the text field rollResultTextField.
// [MC] Adds the component rollPointsTextField to this container.
c.gridx = 2; // [MC] Makes this component the third column from left (column 3).
c.gridy = 4; // [MC] Makes this component the fourth row from top (row 4).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
this.add(rollPointsTextField, c); // [MC] Adds the text field rollPointsTextField.
// [MC] Adds the component gameFinalResultTextField to this container.
c.gridx = 3; // [MC] Makes this component the fourth column from left (column 4).
c.gridy = 4; // [MC] Makes this component the fourth row from top (row 4).
c.gridheight = 1; // [MC] Specifies the number of rows the component uses (1 row).
c.gridwidth = 1; // [MC] Specifies the number of columns the component uses (1 column).
this.add(gameFinalResultTextField, c); // [MC] Adds the text field gameFinalResultTextField.
// [MC] Adds the component myLeftDie to this container.
c.gridx = 0; // [MC] Makes this component the leftmost column (column 1).
c.gridy = 1; // [MC] Makes this component the second row from top (row 2).
c.gridheight = 2; // [MC] Specifies the number of rows the component uses (2 rows).
c.gridwidth = 2; // [MC] Specifies the number of columns the component uses (2 columns).
c.weightx = 1.0; // [MC] Requests any extra vertical (column) space.
c.weighty = 1.0; // [MC] Requests any extra horizontal (row) space.
this.add(myLeftDie, c); // [MC] Adds the component myLeftDie.
// [MC] Adds the component myRightDie to this container.
c.gridx = 2; // [MC] Makes this component the third column from left (column 3).
c.gridy = 1; // [MC] Makes this component the second row from top (row 2).
c.gridheight = 2; // [MC] Specifies the number of rows the component uses (2 rows).
c.gridwidth = 2; // [MC] Specifies the number of columns the component uses (2 column).
c.weightx = 1.0; // [MC] Requests any extra column (vertical) space.
c.weighty = 1.0; // [MC] Requests any extra horizontal (row) space.
this.add(myRightDie, c); // [MC] Adds the component myRightDie.
} // [MC] end constructor
// ======================================================================
// [MC] Private class RollListener
// [MC] Inner listener class for rollButton.
private class RollListener implements ActionListener
public void actionPerformed(ActionEvent e)
// [MC] Rolls the dice.
myLeftDie.roll(); // [MC] Rolls left die.
myRightDie.roll(); // [MC] Rolls right die.
finalResult = 0; // [MC] If result = 0 then game is not over.
rolls++; // [MC] Increments the number of rolls.
// [MC] Displays the roll number.
rollNumberTextField.setText(" " + rolls + " ");
// [MC] Returns the result (number of dots) of last roll.
resultLeft = myLeftDie.getValue(); // [MC] Returns the result of the left die.
resultRight = myRightDie.getValue(); // [MC] Returns the result of the right die.
result = resultLeft + resultRight; // [MC] Returns the total result of dice.
// [MC] Displays the result of last roll.
rollResultTextField.setText(" " + result + " ");
// [MC] Sets the rules for the game.
// [MC] Sets the rules for the first roll of dice.
if (first)
// [MC] If the result is 2, 3 or 12 on the first throw, the player loses.
if (result == 2 || result == 3 || result == 12)
finalResult = 2; // [MC] If result = 2 then the player loses and the game is over.
gameFinalResultTextField.setText("LOOSE");
Toolkit.getDefaultToolkit().beep();
rollButton.setEnabled(false); // [MC] Disable rollButton.
first = true; // [MC] Game over after first roll.
// [MC] If the result is 7 or 11 on the first throw, the player wins.
else if (result == 7 || result == 11)
finalResult = 1; // [MC] If result = 1 then the player wins and the game is over.
gameFinalResultTextField.setText("WIN");
//Toolkit.getDefaultToolkit().beep();
rollButton.setEnabled(false); // [MC] Disable rollButton.
first = true; // [MC] Game over after first roll.
// [MC] If the player didn`t win or lose then the results 4, 5, 6, 8, 9 or 10 become the player`s point.
else if (result == 4 || result == 5 || result == 6 || result == 8 || result == 9 || result == 10);
// [MC] Returns the player`s points.
points = result; // [MC] Returns the player`s points.
// [MC] Displays the player`s points.
rollPointsTextField.setText(" " + points + " ");
first = false; // [MC] Game is not over after first roll.
// [MC] Sets the rules for the next rolls (from second roll onwards) of the dice.
// [MC] If the result is 7, then the player loses.
else if (result == 7)
finalResult = 2; // [MC] If result = 2 then the player loses and the game is over.
gameFinalResultTextField.setText("LOOSE");
Toolkit.getDefaultToolkit().beep();
rollButton.setEnabled(false); // [MC] Disable rollButton.
// [MC] If the result is equal to the player`s point, then the player wins.
else if (result == points)
finalResult = 1; // [MC] If result = 1 then the player wins and the game is over.
gameFinalResultTextField.setText("WIN");
winClip.play();
//Toolkit.getDefaultToolkit().beep();
rollButton.setEnabled(false); // [MC] Disable rollButton.
} // [MC] End public void actionPerformed(ActionEvent e).
} // [MC] End private class RollListener.
// ======================================================================
// [MC] Private class NewGameListener
// [MC] Inner listener class for newGameButton.
private class NewGameListener implements ActionListener
public void actionPerformed(ActionEvent e)
// [MC] Initialises instance variables.
first = true; // [MC] Initialise dice roll to first roll.
rolls = 0; // [MC] Initialises number of rolls to 0.
// [MC] Initialises text fields.
rollResultTextField.setText("");
rollNumberTextField.setText("");
rollPointsTextField.setText("");
gameFinalResultTextField.setText("");
rollButton.setEnabled(true); // [MC] Enable rollButton.
} // [MC] End public void actionPerformed(ActionEvent e).
}// [MC] End private class NewGameListener implements ActionListener.
} // [MC] End public class DicePanel extends JPanel.make a backup copy before these changes
it now compiles, but I haven't run/tested it
changed constructor to init(), extending Applet, not JApplet
// [MC] Public class DiceApplet
public class DiceApplet extends Applet
// [MC] Constructor.
public void init()
// [MC] Sets the contentPane property. This method is called by the constructor.
add(new DicePanel());
}then the 'error lines' become
winClip = ((Applet)getParent()).getAudioClip(((Applet)getParent()).getCodeBase(), "bunny1.au");
looseClip = ((Applet)getParent()).getAudioClip(((Applet)getParent()).getCodeBase(), "bunny1.au");there might be additional problems when you run/test it, but this might get you started -
Import javax.ejb.EJBHome; cannot resolve symbol
Hi i wonder if anyone can help me. I have read alot of the posts regarding this issue and have tried everything to do with the paths and environmental variables and even reinstalled everything.
import javax.ejb.EJBHome; cannot resolve symbol
This is the problem i keep getting and here are the paths that i set:
SET PATH=c:\j2sdkee1.3\bin;c:\jdk1.3.1_01\bin;c:\jakarta-ant-1.3\bin
SET ANT_HOME=c:\jakarta-ant-1.3
SET JAVA_HOME=c:\jdk1.3.1_01
SET J2EE_HOME=c:\j2sdkee1.3
SET CLASSPATH=c:\j2sdkee1.3\lib\j2ee.jar;c:\jakarta-ant-1.3\lib\ant.jar;c:\jdk1.3.1_01\lib\tools.jar
What am i doing wrong???Im not sure, everything looks ok to me, but here is what i tried:
I wrote this little test class, and compiled it
import javax.ejb.EJBHome;
public class test
public test()
I got the same error you did (or similar)
D:\>javac test.java
test.java:1: package javax.ejb does not exist
import javax.ejb.EJBHome;
^
1 error
then I added the j2ee.jar to my classpath and everything worked fine.
here are my env vars:
JAVA_HOME=d:\dev\jdk
J2EE_HOME=d:\dev\j2sdkee
CLASSPATH=...;%J2EE_HOME%\lib\j2ee.jar
If I were you I would double check all the paths you have set up then try a simple case like the one above. If your running NT/2000 make sure the JAVA_HOME, J2EE_HOME and CLASSPATH are system variables not user variables. Another thing you can try is adding the j2ee.jar to the classpath with the -classpath compiler switch.
javac -classpath %CLASSPATH%;d:\dev\j2sdkee\lib\j2ee.jar test.java
Other than those things I'm not sure
Good Luck -
Cannot resolve symbol error while trying to define methods in a class
Well, I'm fairly new to java and I'm trying to write a simple program that will take user input for up to 100 die and how many sides they have and will then roll them and output the frequencies of numbers occuring. I have overloaded the constructor for the Die class to reflect different choices the user may have when initializing the Die.
Here is my code:import java.util.*;
import java.io.*;
public class Die
private final int MIN_FACES = 4;
private int numFaces;
private int i = 0;
private int faceValue;
private Die currentDie;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private String line = null;
public Die()
numFaces = 6;
faceValue = 1;
public Die (int faces)
if (faces < MIN_FACES) {
numFaces = 6;
System.out.println ("Minimum number of faces allowed is 6.");
System.out.println ("Setting faces to 6... . . . . . . . . .");
else
numFaces = faces;
faceValue = 1;
//Returns an array of Die Objects
public Die (int num_die, int faces)
numFaces = faces;
Die[] protoDie = new Die[num_die];
for (i = 0; i <= num_die-1; i++)
Die currentDie = new Die(numFaces);
protoDie = protoDie.initMultiDie(currentDie, i);
public Die (double num_die)
int numberOfDie = (int) num_die;
Die[] protoDie = new Die[numberOfDie];
System.out.print ("Enter the number of sides for die #" + i);
for (i=0; i <= protoDie.length; i++) {
do {
try {
line = br.readLine();
numFaces = Integer.parseInt(line);
catch (NumberFormatException nfe) {
System.out.println ("You must enter an integer.");
System.out.print ("Setting number of dice to 0, please reenter: ");
if (numFaces < 0) {
System.out.println ("The number of sides must be positive.");
numFaces *= -1;
System.out.println ("Number of sides is: " + numFaces);
else
if (numFaces = 0) {
System.out.println ("Zero dice is no fun. =[");
System.out.print ("Please reenter the number of sides: ");
numFaces = 0;
while (numFaces == 0);
Die currentDie = new Die(numFaces);
protoDie[i] = protoDie.initMultiDie(currentDie, i);
i = 0;
public Die[] initMultiDie (Die[] protoDie, Die currentDie, int i)
protoDie[i] = currentDie;
return protoDie;
public Die reInit (int sides)
currentDie.roll();
return currentDie;
public int roll()
faceValue = (int) (Math.random() * numFaces) + 1;
return faceValue;
}When I compile I get 2 errors at lines 42 and 73 saying:
Cannot resolve symbol | symbol: method initMultiDie(Die, int) | location: class Die[] | protoDie[i] = protoDie.initMultiDie(currentDie, i)
I've tried mixing things up with invoking the method, such as including protoDie in the parameter liist, instead of invoking the initMultiDie method thru the protoDie Die[] object. I'm a little confused as to what I can and cannot do with defining arrays of Objects like Die. Thank you for any input you may be able to provide.
~LijeI may as well just replace Die with Dice and allow
Dice to represent a collection of 1 die.. I just like
to cut on bloat and make my programs be as efficient
as possible.Efficiency and avoiding code bloat are good goals, but you don't necessarily achieve it by creating the smallest number of classes. If you have N algorithms in M lines, then you have that many, regardless of whether they're in one class or two. A really long source file can be a worse example of bloat than two source files of half the size -- it can be harder to read, less clear in the design, and thus with more bugs...
The important thing is clarity and a strong design.
The weird thing is, that initMultiDie is
what seems to be throwing up the error, but I don't
see why. Meh, I'm sure I'll figure it out.Refactoring a class to make the design more transparent often helps you figure out bugs. -
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 GEATFULJust 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 -
Visual Studio 2012 cannot resolve symbol or Errors control is not a member of class
Visual Studio 2012 Web Site Project (Note not a Web application, so there are not Designer.vb files) > Site works perfectly fine and using IIS and attaching to IIS to debug code.
However, if I try to build the site inside of Visual Studio I am getting lots of Errors ‘pnlName’ is not a member of ‘Page_Name’ In the code behind I am getting errors ‘Cannot resolve symbol ‘pnlName’
.ascx Page
<li style="margin-right:0;" id="pnlName" runat="server"><a href="/cart" title="Checkout" class="global-checkout">Checkout</a></li>
.ascx.vb page
Me.pnlName.Attributes.Remove("style")
I have cleaned, rebuild and nothing gets rid of these errors, but again the site works as designed, but I would like to launch and debug inside of Visual Studio.
Moojjoo MCP, MCTS
MCP Virtual Business Card
http://moojjoo.blogspot.comCor,
What I am stating is this is a solution using the Web Site Project instead of a
Web Application Project.
Web Site projects do not require Designer.vb files, Web Application Projects add Designer.vb files in the solution.
Background: I have been hired to support a very successful e-commerce site that was built by a 3rd party vendor (I had no input on the contract or specification, because I would have went with
MVC). The site works 100% correctly, however from my 2003 - 2015 experience with Visual Studio and Web Development being in Web Forms and MVC I have always built ASP.NET Solutions using the Web Application Project Templates, which compiles the code down
to .dlls.
A Web Site project does not compile the code, but simply uses the .vb files and they have to be migrated to the server with the .aspx files. http://msdn.microsoft.com/en-us/library/dd547590%28v=vs.110%29.aspx
Currently the only way I can debug this Solution is to attach to the w3wp.exe process running locally on my work station.
The Solution is comprised of two Web Sites, which I cannot get it to compile because of the following errors -
'webServerControlName' is not a member of '(Protected Code Behind Class Name)' I am reaching out to the MSDN community to see if anyone has experienced this issue with
Web Site Projects.
I hope that clears up the Project Type question.
Moojjoo MCP, MCTS
MCP Virtual Business Card
http://moojjoo.blogspot.com -
Getting error message Cannot Resolve Symbol when trying to compile a class
Hello All -
I am getting an error message cannot resolve symbol while trying to compile a java class that calls another java class in the same package. The called class compiles fine, but the calling class generates
the following error message:
D:\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\cal>javac
ConnectionPool.java
ConnectionPool.java:158: cannot resolve symbol
symbol : class PooledConnection
location: class cal.ConnectionPool
private void addConnection(PooledConnection value) {
^
ConnectionPool.java:144: cannot resolve symbol
symbol : class PooledConnection
location: class cal.ConnectionPool
PooledConnection pcon = new PooledConnection(con);
^
ConnectionPool.java:144: cannot resolve symbol
symbol : class PooledConnection
location: class cal.ConnectionPool
PooledConnection pcon = new PooledConnection(con);
The code is listed as follows for PooledConnection.java (it compiles fine)
package cal;
import java.sql.*;
public class PooledConnection {
// Real JDBC Connection
private Connection connection = null;
// boolean flag used to determine if connection is in use
private boolean inuse = false;
// Constructor that takes the passed in JDBC Connection
// and stores it in the connection attribute.
public PooledConnection(Connection value) {
if ( value != null ) {
connection = value;
// Returns a reference to the JDBC Connection
public Connection getConnection() {
// get the JDBC Connection
return connection;
// Set the status of the PooledConnection.
public void setInUse(boolean value) {
inuse = value;
// Returns the current status of the PooledConnection.
public boolean inUse() {
return inuse;
// Close the real JDBC Connection
public void close() {
try {
connection.close();
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
Now the code for ConnectionPool.java class that gives the cannot
resolve symbol error
package cal;
import java.sql.*;
import java.util.*;
public class ConnectionPool {
// JDBC Driver Name
private String driver = null;
// URL of database
private String url = null;
// Initial number of connections.
private int size = 0;
// Username
private String username = new String("");
// Password
private String password = new String("");
// Vector of JDBC Connections
private Vector pool = null;
public ConnectionPool() {
// Set the value of the JDBC Driver
public void setDriver(String value) {
if ( value != null ) {
driver = value;
// Get the value of the JDBC Driver
public String getDriver() {
return driver;
// Set the URL Pointing to the Datasource
public void setURL(String value ) {
if ( value != null ) {
url = value;
// Get the URL Pointing to the Datasource
public String getURL() {
return url;
// Set the initial number of connections
public void setSize(int value) {
if ( value > 1 ) {
size = value;
// Get the initial number of connections
public int getSize() {
return size;
// Set the username
public void setUsername(String value) {
if ( value != null ) {
username = value;
// Get the username
public String getUserName() {
return username;
// Set the password
public void setPassword(String value) {
if ( value != null ) {
password = value;
// Get the password
public String getPassword() {
return password;
// Creates and returns a connection
private Connection createConnection() throws Exception {
Connection con = null;
// Create a Connection
con = DriverManager.getConnection(url,
username, password);
return con;
// Initialize the pool
public synchronized void initializePool() throws Exception {
// Check our initial values
if ( driver == null ) {
throw new Exception("No Driver Name Specified!");
if ( url == null ) {
throw new Exception("No URL Specified!");
if ( size < 1 ) {
throw new Exception("Pool size is less than 1!");
// Create the Connections
try {
// Load the Driver class file
Class.forName(driver);
// Create Connections based on the size member
for ( int x = 0; x < size; x++ ) {
Connection con = createConnection();
if ( con != null ) {
// Create a PooledConnection to encapsulate the
// real JDBC Connection
PooledConnection pcon = new PooledConnection(con);
// Add the Connection to the pool.
addConnection(pcon);
catch (Exception e) {
System.err.println(e.getMessage());
throw new Exception(e.getMessage());
// Adds the PooledConnection to the pool
private void addConnection(PooledConnection value) {
// If the pool is null, create a new vector
// with the initial size of "size"
if ( pool == null ) {
pool = new Vector(size);
// Add the PooledConnection Object to the vector
pool.addElement(value);
public synchronized void releaseConnection(Connection con) {
// find the PooledConnection Object
for ( int x = 0; x < pool.size(); x++ ) {
PooledConnection pcon =
(PooledConnection)pool.elementAt(x);
// Check for correct Connection
if ( pcon.getConnection() == con ) {
System.err.println("Releasing Connection " + x);
// Set its inuse attribute to false, which
// releases it for use
pcon.setInUse(false);
break;
// Find an available connection
public synchronized Connection getConnection()
throws Exception {
PooledConnection pcon = null;
// find a connection not in use
for ( int x = 0; x < pool.size(); x++ ) {
pcon = (PooledConnection)pool.elementAt(x);
// Check to see if the Connection is in use
if ( pcon.inUse() == false ) {
// Mark it as in use
pcon.setInUse(true);
// return the JDBC Connection stored in the
// PooledConnection object
return pcon.getConnection();
// Could not find a free connection,
// create and add a new one
try {
// Create a new JDBC Connection
Connection con = createConnection();
// Create a new PooledConnection, passing it the JDBC
// Connection
pcon = new PooledConnection(con);
// Mark the connection as in use
pcon.setInUse(true);
// Add the new PooledConnection object to the pool
pool.addElement(pcon);
catch (Exception e) {
System.err.println(e.getMessage());
throw new Exception(e.getMessage());
// return the new Connection
return pcon.getConnection();
// When shutting down the pool, you need to first empty it.
public synchronized void emptyPool() {
// Iterate over the entire pool closing the
// JDBC Connections.
for ( int x = 0; x < pool.size(); x++ ) {
System.err.println("Closing JDBC Connection " + x);
PooledConnection pcon =
(PooledConnection)pool.elementAt(x);
// If the PooledConnection is not in use, close it
if ( pcon.inUse() == false ) {
pcon.close();
else {
// If it is still in use, sleep for 30 seconds and
// force close.
try {
java.lang.Thread.sleep(30000);
pcon.close();
catch (InterruptedException ie) {
System.err.println(ie.getMessage());
I am using Sun JDK Version 1.3.0_02" and Apache/Tomcat 4.0. Both the calling and the called class are in the same directory.
Any help would be greatly appreciated.
tnx..
addiIs ConnectionPool in this "cal" package as well as PooledConnection? From the directory you are compiling from it appears that it is. If it is, then you are compiling it incorrectly. To compile ConnectionPool (and PooledConnection similarly), you must change the current directory to the one that contains cal and type
javac cal/ConnectionPool. -
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??).... -
"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.**** -
Class error - cannot resolve symbol "MyDocumentListener"
Hello,
this is a groaner I'm sure, but I don't see the problem.
Newbie-itis probably ...
I'm not concerned with what the class does, but it would be nice for the silly thing to compile!
What the heck am I missing for "MyDocumentListener" ?
C:\divelog>javac -classpath C:\ CenterPanel.java
CenterPanel.java:53: cannot resolve symbol
symbol : class MyDocumentListener
location: class divelog.CenterPanel
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
^
CenterPanel.java:53: cannot resolve symbol
symbol : class MyDocumentListener
location: class divelog.CenterPanel
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
^
2 errors
package divelog;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
import javax.swing.text.*;
public class CenterPanel extends JPanel implements ActionListener
{ // Opens class
static private final String newline = "\n";
private JTextArea comments;
private JScrollPane scrollpane;
private JButton saveButton, openButton;
private JLabel whiteshark;
private Box box;
private BufferedReader br ;
private String str;
private JTextArea instruct;
private File defaultDirectory = new File("C://divelog");
private File fileDirectory = null;
private File currentFile= null;
public CenterPanel()
{ // open constructor CenterPanel
setBackground(Color.white);
comments = new JTextArea("Enter comments, such as " +
"location, water conditions, sea life you observed," +
" and problems you may have encountered.", 15, 10);
comments.setLineWrap(true);
comments.setWrapStyleWord(true);
comments.setEditable(true);
comments.setFont(new Font("Times-Roman", Font.PLAIN, 14));
// add a document listener for changes to the text,
// query before opening a new file to decide if we need to save changes.
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
comments.getDocument().addDocumentListener(myDocumentListener); // create the reference for the class
// ------ Document listener class -----------
class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
Calculate(e);
public void removeUpdate(DocumentEvent e) {
Calculate(e);
public void changedUpdate(DocumentEvent e) {
private void Calculate(DocumentEvent e) {
// do something here
scrollpane = new JScrollPane(comments);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
saveButton = new JButton("Save Comments", new ImageIcon("images/Save16.gif"));
saveButton.addActionListener( this );
saveButton.setToolTipText("Click this button to save the current file.");
openButton = new JButton("Open File...", new ImageIcon("images/Open16.gif"));
openButton.addActionListener( this );
openButton.setToolTipText("Click this button to open a file.");
whiteshark = new JLabel("", new ImageIcon("images/gwhite.gif"), JLabel.CENTER);
Box boxH;
boxH = Box.createHorizontalBox();
boxH.add(openButton);
boxH.add(Box.createHorizontalStrut(15));
boxH.add(saveButton);
box = Box.createVerticalBox();
box.add(scrollpane);
box.add(Box.createVerticalStrut(10));
box.add(boxH);
box.add(Box.createVerticalStrut(15));
box.add(whiteshark);
add(box);
} // closes constructor CenterPanel
public void actionPerformed( ActionEvent evt )
{ // open method actionPerformed
JFileChooser jfc = new JFileChooser();
// these do not work !!
// -- set the file types to view --
// ExtensionFileFilter filter = new ExtensionFileFilter();
// FileFilter filter = new FileFilter();
//filter.addExtension("java");
//filter.addExtension("txt");
//filter.setDescription("Text & Java Files");
//jfc.setFileFilter(filter);
//Add a custom file filter and disable the default "Accept All" file filter.
jfc.addChoosableFileFilter(new JTFilter());
jfc.setAcceptAllFileFilterUsed(false);
// -- open the default directory --
// public void setCurrentDirectory(File dir)
// jfc.setCurrentDirectory(new File("C://divelog"));
jfc.setCurrentDirectory(defaultDirectory);
jfc.setSize(400, 300);
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
Container parent = saveButton.getParent();
//========================= Test Button Actions ================================
//========================= Open Button ================================
if (evt.getSource() == openButton)
int choice = jfc.showOpenDialog(CenterPanel.this);
File file = jfc.getSelectedFile();
/* a: */
if (file != null && choice == JFileChooser.APPROVE_OPTION)
String filename = jfc.getSelectedFile().getAbsolutePath();
// -- compare the currentFile to the file chosen, alert of loosing any changes to currentFile --
// If (currentFile != filename)
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
try
{ //opens try
comments.getLineCount( );
// -- clear the old data before importing the new file --
comments.selectAll();
comments.replaceSelection("");
// -- get the new data ---
br = new BufferedReader (new FileReader(file));
while ((str = br.readLine()) != null)
{//opens while
comments.append(str);
} //closes while
} // close try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Open command not successful:" + ioe + newline);
} // close catch
// ---- display the values of the directory variables -----------------------
comments.append(
newline + "The f directory variable contains: " + f +
newline + "The fileDirectory variable contains: " + fileDirectory +
newline + "The defaultDirectory variable contains: " + defaultDirectory );
else
comments.append("Open command cancelled by user." + newline);
} //close if statement /* a: */
//========================= Save Button ================================
} else if (evt.getSource() == saveButton)
int choice = jfc.showSaveDialog(CenterPanel.this);
if (choice == JFileChooser.APPROVE_OPTION)
File fileName = jfc.getSelectedFile();
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
//check for existing files. Warn users & ask if they want to overwrite
for(int i = 0; i < fileName.length(); i ++) {
File tmp = null;
tmp = (fileName);
if (tmp.exists()) // display pop-up alert
//public static int showConfirmDialog( Component parentComponent,
// Object message,
// String title,
// int optionType,
// int messageType,
// Icon icon);
int confirm = JOptionPane.showConfirmDialog(null,
fileName + " already exists on " + fileDirectory
+ "\n \nContinue?", // msg
"Warning! Overwrite File!", // title
JOptionPane.OK_CANCEL_OPTION, // buttons displayed
// JOptionPane.ERROR_MESSAGE
// JOptionPane.INFORMATION_MESSAGE
// JOptionPane.PLAIN_MESSAGE
// JOptionPane.QUESTION_MESSAGE
JOptionPane.WARNING_MESSAGE,
null);
if (confirm != JOptionPane.YES_OPTION)
{ //user cancels the file overwrite.
try {
jfc.cancelSelection();
break;
catch(Exception e) {}
// ----- Save the file if everything is OK ----------------------------
try
{ // opens try
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
bw.write(comments.getText());
bw.flush();
bw.close();
comments.append( newline + newline + "Saving: " + fileName.getName() + "." + newline);
break;
} // closes try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Save command unsuccessful:" + ioe + newline);
} // close catch
} // if exists
} //close for loop
else
comments.append("Save command cancelled by user." + newline);
} // end-if save button
} // close method actionPerformed
} //close constructor CenterPanel
} // Closes class CenterPanelThere is no way to be able to see MyDocumentListener class in the way you wrote. The reason is because MyDocumentListener class inside the constructor itself. MyDocumentListener class is an inner class, not suppose to be inside a constructor or a method. What you need to do is simple thing, just move it from inside the constructor and place it between two methods.
that's all folks
Qusay -
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;
} -
Recieving cannot resolve symbol symbol : class Serializable
I'm receiving the error:
cannot resolve symbol symbol : class Serializable
The class is as follows:
//package cscie160.hw5;
import java.io.Serializable
* @author Eddie Brodie
* @version %I%, %G%
public class AccountInfo implements Serializable
public int _accountNumber;
public int _pin;
public AccountInfo(int accountNumber, int pin)
_accountNumber = accountNumber;
_pin = pin;
I've tried importing java.*
I've also checked my classpath.
Any ideas?Try taking the import statement out of the comment block; that might help
-
Cannot resolve symbol: class OracleDriver
Attempting to compile a servlet on Apache Server using same jdeveloper jdbc libraries:
classes12.jar & nls_charset12.jar
Error message:
$compilejava2.sh ProdJobs
ProdJobs.java:361: cannot resolve symbol
symbol : class OracleDriver
location: package driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Am I missing something else?
JeffreyEnter this code into your program and then put the Oracle jar file that contains the driver in your run-time classpath.
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
catch(ClassNotFoundException cnfe) {
// driver not found
}The effect of this is that the classloader will load the Oracle driver for you then call it's static initiailizer that does a bunch of magic that results in the Java runtime knowing that there's a JDBC driver out there.
It is a little weird - but that's the way it works. -
Cannot resolve symbol: class EJBObject
Using javac I get this compile error on this file Calculator.java
Calculator.java:1: cannot resolve symbol
symbol : class EJBObject
location: package ejb
import javax.ejb.EJBObject;
^
Calculator.java:5: cannot resolve symbol
symbol : class EJBObject
location: interface Calculator
public interface Calculator extends EJBObject {
Source code for Calculator.java
import javax.ejb.EJBObject;
import java.rmi.*;
public interface Calculator extends EJBObject {
public long add (int x, int y) throws RemoteException;
public long subtract (int x, int y) throws RemoteException;This code is from a book, so I will assume its a classpath problem. My
classpath looks like:
"C\QTJava.zip".;%J2EE_HOME%\lib\j2ee.jar;%J2EE_HOME%\lib\locale
Also the following enviorment varibales have been set to:
J2EE_HOME
C:\Development\Java\j2sdkee1.3.1
JAVA_HOME
C:\Development\Java\jdk1.3.1
Path
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System;%JAVA_HOME%\bin;%J2EE_HOME%\bin
I can run j2EE, like "j2EE -verbose" (no problems)
also run cloudscape, like "cloudscape -start" (no problems)
also can run deploytool, like "deploytool" (no problems, & deploy sample ear files from cd book)
Your help is appreicated. -
Cannot resolve symbol class graphics
does anyone know what the error
cannot resolve symbol class graphics means?
with this code i can't seem to call the graphics method to draw the line....any reason why?
import javax.swing.*;
import java.*;
public class LineDraw extends JFrame {
public static void main(String[] args) {
LineDraw ld = new LineDraw();
ld.setSize(500,500);
ld.setVisible(true);
ld.enterVariables();
public void init(){
private int x1;
private int x2;
private int y1;
private int y2;
public void paint(Graphics g) {
g.GetGraphics(g);
super.paintComponent(g);
g.drawLine(x1, y1, x2, y2);
public void enterVariables() {
x1 = Integer.parseInt(JOptionPane.showInputDialog("Enter x1:"));
y1 = Integer.parseInt(JOptionPane.showInputDialog("Enter y1:"));
x2 = Integer.parseInt(JOptionPane.showInputDialog("Enter x2:"));
y2 = Integer.parseInt(JOptionPane.showInputDialog("Enter y2:"));
repaint();
}well the exact error message is ...by the way now that i think about it
if the graphics method shoudl not be part of the JFrame class then what method would i use to draw 2D Graphics?
--------------------Configuration: <Default>--------------------
C:\Documents and Settings\c1s5\My Documents\LineDraw.java:21: cannot resolve symbol
symbol : class Graphics
location: class LineDraw
public void paint(Graphics g)
^
1 error
Process completed.
and the exact code is
import javax.swing.*;
import java.*;
public class LineDraw extends JFrame {
public static void main(String[] args) {
LineDraw ld = new LineDraw();
ld.setSize(1024,500);
ld.setVisible(true);
ld.enterVariables();
private int x1;
private int x2;
private int y1;
private int y2;
public void paint(Graphics g)
super.paintComponent(g);
g.drawLine(x1, y1, x2, y2);
public void enterVariables() {
x1 = Integer.parseInt(JOptionPane.showInputDialog("Enter x1:"));
y1 = Integer.parseInt(JOptionPane.showInputDialog("Enter y1:"));
x2 = Integer.parseInt(JOptionPane.showInputDialog("Enter x2:"));
y2 = Integer.parseInt(JOptionPane.showInputDialog("Enter y2:"));
repaint();
}
Maybe you are looking for
-
Hp laserjet 1300 not receive signals from computer
HP Laserjet 1300 seems not to receive signals from my computer. Please explain This question was solved. View Solution.
-
How to copy iphoto picture library to flash drive?
How can I copy all the pictures in iphoto to a flash drive?
-
How to disable the certificate hostname verification?
In JSSE changes file <http://java.sun.com/products/jsse/CHANGES.txt> It states the following: "It is sometimes useful to "disable" the certificate hostname verification during project development. A single certificate can now be shared among many dev
-
Player with external html-playlist
Hey Everybody! I'm quite new with Flash, but dying to now more about it (and being able to make all kinds of wicked things). But for now, I'm a noob yet. With a question I really can't figure out myself: I made a video player in flash (AS 3.0, Flash
-
Can you please apply comments upon my coding tech....
I use a servlet to send data from a form to a Mysql database. The servlet code is the following. When i submit the form i receive an Error 500 from Tomcat upon the 69th line of the code. The code has as follows. package mypackage; import java.sql.*;