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

Similar Messages

  • Cannot resolve symbol - getCodeBase()

    Hey,
    I'm trying to read from a file into my java applet however, I get the following error:
    Player.java [49:1] cannot resolve symbol
    symbol : method getCodeBase ()
    location: class Player
    url = new URL(getCodeBase().toString() + "/bot" + playerNo + ".txt");
    ^
    1 error
    Errors compiling Player.
    The ^ should point at the 'g' of getCodeBase. I'm not sure what is up as I import both .net.* and .applet.* and have used similar syntax in another class which works fine. Any ideas what's up?

    getCodeBase() is an Applet method. You need you have a reference to the applet.,

  • 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??)....

  • Factory method generateRandomCircle: "cannot resolve symbol"

    I have written 2 classes: Point and Circle, which uses Point objects in order to create a Circle object. I have created a factory method for Point, which creates random Point objects and a for Circle, which does the same. "newRandomInstance" works fine for Point, but "generateRandomCircle" throws a "cannot resolve symbol" error. "main" is inside Point class. What's the problem?
    Thanks
    ================================================
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class Circle implements Cloneable
    public static Circle generateRandomCircle()
    int a= (int) (Math.random()* Short.MAX_VALUE);
    int b= (int) (Math.random()* Short.MAX_VALUE);
    Point p=new Point(a,b);
    int r= (int) (Math.random()* Short.MAX_VALUE);
    Circle c= new Circle(p,r);
    return c;
    ===============================================
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class Point implements Cloneable, Comparable
    public static Point newRandomInstance()
    int x = (int) (Math.random() * Short.MAX_VALUE);
    int y = (int) (Math.random() * Short.MAX_VALUE);
    return new Point(x,y);
    public static void main (String[] args)
    Circle cRandom= generateRandomCircle(); //doesn't work
    System.out.println(cRandom.getCenter()+" "+ cRandom.getRadius());
    Point randomP= newRandomInstance(); //works OK
    randomP.printPoint();
    }

    I tried "Circle cRandom=
    Circle.generateRandomCircle(); " instead of "Circle
    cRandom= generateRandomCircle();" and it worked. Why
    did this happen?Because generateRandomCircle() exists in class Circle and not in class Point where your are trying to use it.
    >
    Function "newRandomInstance()" works either as
    "Point.newRandomInstance()" or as
    "newRandomInstance()", however. Why does this
    controversy exist?No controversy! Your main() is contained within class Point and as such knows about everything that is declared in class Point() but nothing about what is in class Circle unless you tell it to look in class Circle.

  • 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.
    ~Lije

    I 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.

  • "cannot resolve symbol" when compiling a class that calls methods

    I am currently taking a Intro to Java class. This problem has my instructor baffled. If I have two classes saved in separate files, for example:
    one class might contain the constructor with get and set statements,
    the other class contains the main() method and calls the constructor.
    The first file compiles clean. When I compile the second file, I get the "cannot resolve symbol error" referring to the first class.
    If I copy both files to floppy and take them to school. I can compile and run them with no problem.
    If I copy the constructor file to the second file and delete the "public" from the class declaration of the constructor, it will compile and run at home.
    At home, I am running Windows ME. At school, Windows 2000 Professional.
    The textbook that we are using came with a CD from which I downloaded the SDK and Runtime Environment. I have tried uninstalling and reinstalling. I have also tried downloading directly from the Sun website and still the error persists.
    I came across a new twist tonight. I copied class files from the CD to my hard drive. 4 separate files. 3 of which are called by the 4th.
    I can run these with no problem.
    Any ideas, why I would have compile errors????
    Thanks!!

    Oooops ... violated....
    Well first a constructor should have the same name as the class name so in our case what we have actually created is a static method statementOfPhilosophy() in class SetUpSite and not a constructor.
    Now why does second class report unresolved symbol ???
    Look at this line
    Class XYZ=new XYZ();
    sounds familiar, well this is what is missing from your second class, since there is no object how can it call a method ...
    why the precompiled classes run is cuz they contain the right code perhaps so my suggestion to you is,
    1) Review the meaning and implementation of Constructors
    2) Ask your instructor to do the same ( no pun intended ... )
    3) Check out this for understanding PATH & CLASSPATH http://www.geocities.com/gaurav007_2000/java/
    4) Look at the "import" statement, when we have code in different files and we need to incorporate some code in another it is always a good idea to use import statement, that solves quite a few errors.
    5) Finally forgive any goof up on this reply, I have looked at source code after 12 months of hibernation post dot com doom ... so m a bit rusty... shall get better soon though :)
    warm regards and good wishes,
    Gaurav
    CW :-> Mother of all computer languages.
    I HAM ( Radio-Active )
    * OS has no significance in this error
    ** uninstalling and reinstalling ? r u nuttttttts ??? don't ever do that again unless your compiler fails to start, as long as it is giving a valid error it is working man ... all we need to do is to interpret the error and try to fix the code not the machine or compiler.

  • Need help - method call error cannot resolve symbol

    My code compiles fine but I continue to receive a method call error "cannot resolve symbol - variable superman" - can't figure out why. Here is my code:
    public static String caesar(String message, int shift)
    {   [b]String result = "";
    for(int i = 0; i < message.length(); ++i)
    {   [b]char newChar = message.charAt(i + shift);
    result += newChar;
    return result.toUpperCase();
    I entered "superman" for message and "3" for the shift. Can someone please help? Thanks!

    Your post worked great - especially since it made me realize I was going about it all wrong! I was attempting to convert "superman" to "vxshupdq" - basically a cipher shift starting at index 0 and shifting it 3 character values which would result in s changing to v. I restructured my code:
    public static String caesar(String message, int shift)
    {   [b]String result = "";
    for(int i = 0; i < message.length(); ++i)
    {   [b]char newChar = message.charAt(i);
    result += (newChar + shift) % message.length();
    return result.toUpperCase();
    But it's displaying the result as a "60305041". How can I get it to display the actual characters?

  • 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 CenterPanel

    There 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

  • 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();
    }

  • Cannot resolve symbol error even with class imported

    Hi
    I'm trying to print out a java.version system property but keep getting a
    cannot resolve symbol error
    symbol: class getProperty
    location: class java.lang.System
    I've looked at the API and getProperty() is a method of lang.System
    Can anyone throw any light?
    thanks
    import java.lang.System;
    class PropertiesTest {
        public static void main(String[] args) {
                String v = new System.getProperty("java.version");
                 System.out.println(v);
    }

    Thanks Jos
    It compiles but I now get a runtime error
    Exception in thread "main"
    java.lang.NoClassDefFoundError:PropertiesTest
    What do you reckon is the problem?
    thanks
    java -cp .;<any other directories or jars>
    YourClassNameYou get a NoClassDefFoundError message because the
    JVM (Java Virtual Machine) can't find your class. The
    way to remedy this is to ensure that your class is
    included in the classpath. The example assumes that
    you are in the same directory as the class you're
    trying to run.I know it's a bad habit but I've put this file (PropertiesTest.java) and the compiled class (PropertiesTest.class) both in my bin folder which contains the javac compiler

  • Cannot resolve symbol java.awt.graphics

    // DrawRectangleDemo.java
    import java.awt.*;
    import java.lang.Object;
    import java.applet.Applet;
    public class DrawRectangleDemo extends Applet
         public void paint (Graphics g)
              // Get the height and width of the applet's drawing surface.
              int width = getSize ().width;
              int height = getSize ().height;
              int rectWidth = (width-50)/3;
              int rectHeight = (height-70)/2;
              int x = 5;
              int y = 5;
              g.drawRect (x, y, rectWidth, rectHeight);
              g.drawString ("drawRect", x, rectHeight + 30);
              x += rectWidth + 20;
              g.fillRect (x, y, rectWidth, rectHeight);
              // Calculate a border area with each side equal tp 25% of
              // the rectangle's width.
              int border = (int) (rectWidth * 0.25);
              // Clear 50% of the filled rectangle.
              g.clearRect (x + border, y + border,
                             rectWidth - 2 * border, rectHeight - 2 * border);
              g.drawString ("fillRect/clearRect", x, rectHeight + 30);
              x += rectWidth + 20;
              g.drawRoundRect (x, y, rectWidth, rectHeight, 15, 15);
              g.drawString ("drawRoundRect", x, rectHeight + 30);
              x=5;
              y += rectHeight + 40;
              g.setColor (Color.yellow);
              for (int i = 0; i < 4; i++)
                   g.draw3DRect (x + i * 2, y + i * 2,
                                       rectWidth - i * 4, rectHeight - i * 4, false);
              g.setColor (Color.black);
              g.drawString ("draw3DRect", x, y, + rectHeight + 25);
              x += rectWidth + 20;
              g.setColor (Color.yellow);
              g.fill3DRect (x, y, rectWidth, rectHeight, true);
              g.setColor (Color.black);
              g.drawString ("fill3DRect", x, y, + rectHeight + 25);
    Help me with this codes. I typed correctly but there still errors.
    --------------------Configuration: JDK version 1.3.1 <Default>--------------------
    D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:56: cannot resolve symbol
    symbol : method drawString (java.lang.String,int,int,int)
    location: class java.awt.Graphics
              g.drawString ("draw3DRect", x, y, + rectHeight + 25);
    ^
    D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:64: cannot resolve symbol
    symbol : method drawString (java.lang.String,int,int,int)
    location: class java.awt.Graphics
              g.drawString ("fill3DRect", x, y, + rectHeight + 25);
    ^
    2 errors
    Process completed.
    -------------------------------------------------------------------------------------------------------------------------------

    cannot resolve symbol
    symbol : method drawString (java.lang.String,int,int,int)
    This is telling you that you are trying to invoke the drawString() method with 4 parameters: String, int, int, int
    If you look at the API the drawString() method need 3 parameters: String, int, int - so you have an extra int
    location: class java.awt.Graphics
    g.drawString ("draw3DRect", x, y, + rectHeight + 25);
    Now is you look at your code you will find that you have 3 ',' in you method call. (I don't think you want the ',' after the y.

  • Compiling error - cannot resolve symbol

    Hi,
    I am working on writing out this basic code for a project. When I compile, I get an error "Cannot resolve symbol" for the gpa variable. Please help!
    My intention is to use the hours and points from the crHours and nbrPoints methods, and use them to calculate GPA in the grPtAvg method:
    public class Student
         public static void main(String[]args)
    idNum();
    crHours();
    nbrpoints();
    gpa = grPtAvg(hours, points);
    System.out.println("Student's GPA is " + gpa);
    public static void idNum()
    int id = 2520;
    System.out.println("Student's ID is " + id);
    public static float crHours()
    float hours = 5;
    System.out.println("Student's credit hours are " + hours);
    return hours;
    public static float nbrpoints()
    float points = 22;
    System.out.println("Student's earned points are " + points);
    return points;
    public static float grPtAvg(float hours, float points)
    float gpa;
    gpa = points / hours;
    System.out.println("Student's computed GPA is " + gpa);
    return gpa;

    That's because you're doing the same thing (in a somewhat different way) with those.
    The variables: hours and points have already been returned to main methd, right?Yes, but then the main method ignores them.
    So, they should be available at this point in the code, is that right?Available in the sense that you can read them, but not in the sense that there are hours and points variables within scope in the main method.
    You want to do this:
    public static void main(String[] args) {
       idNum();
       float hours = crHours();
       float points = nbrpoints();
       //create a new float
       float myComputetdGpa = grPtAvg(hours, points);
       System.out.println("Student's GPA is " + myComputedGpa);
    }

  • BufferedReader cannot resolve symbol

    Hi,
    I need some help with a java program which reads xml files to a specified location, running it on a UNIX machine using Java 1.4.1. I modified the code to include the BufferedReader class, but it keeps complaining about not being able to resolve symbol at line 50 & 53. Any help here would be appreciated, since I'm a newbie.
    bash-2.05$ javac outputScript.java
    outputScript.java:50: cannot resolve symbol
    symbol : constructor InputStreamReader (java.lang.String)
    location: class java.io.InputStreamReader
    BufferedReader in = new BufferedReader(new InputStreamReader("in"));
    ^
    outputScript.java:53: cannot resolve symbol
    symbol : method available ()
    location: class java.io.BufferedReader
    while (in.available() !=0)
    Here's the code:
    //package cognos8_3;
    import java.io.*;
    import java.io.InputStreamReader;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.File;
    * outputScript.java
    * Copyright Cognos Incorporated. All Rights Reserved.
    * Cognos and the Cognos logo are trademarks of Cognos Incorporated.
    * Description: (KB 1013700) - Sample script that will rename output files generated by CM.OUTPUTLOCATION - Cognos 8.3
    class outputScript
    public static void main(String args[])
         String reportName = "";
         String reportViewName = "";
         String outputLocation = "/data/cognos/rn_filecp/";
         String defName = "";
         String ofTime = "";
         String burstKey = "";
         int countRenamed = 0;
         // get the list of desc files in the outputlocation
         File descFiles = new File(outputLocation);
         String[] children = descFiles.list();
         if (children == null || children.length == 0)
              System.out.println("Invalid file location or no reports found to rename.");
         else
                   System.out.println("Found " + children.length + " files in this location, search for file names containing '_desc.'.");
              for (int i=0; i<children.length; i++)
                   try
                        // Get filename of file or directory
                        String filename = children;
                        if (filename.indexOf("_desc.")>=0)
                             // Open the file that is the first
                             // command line parameter
                             FileInputStream fstream = new FileInputStream(outputLocation+filename);
                             FileInputStream bis = new FileInputStream(fstream);
                                  BufferedReader in = new BufferedReader(new InputStreamReader("bis.in"));
                             //      Continue to read lines while there are still some left to read
                             while (in.available() !=0)
                                  String temp = in.readLine();
                                  System.out.println(temp);
                                  // check for report name
                                  if (temp.indexOf("report[@name=")>0)
                                       // get beginning of name
                                       int startIndex = temp.indexOf("report[@name=&apos;");
                                       String startString;
                                       int endIndex = 0;
                                       if (startIndex > 0)
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("&apos;") + 5; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("&apos;");
                                       else
                                            startIndex = temp.indexOf("report[@name=");
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("@name=") + 6; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("]");
                                       // get report name
                                       reportName = startString.substring(startIndex+1, endIndex);
                                       //System.out.println("Found report name - " + reportName);
                                  else if (temp.indexOf("reportView[@name=")>0)
                                       // get beginning of name
                                       int startIndex = temp.indexOf("reportView[@name=&apos;");
                                       String startString;
                                       int endIndex = 0;
                                       if (startIndex > 0)
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("&apos;") + 5; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("&apos;");
                                       else
                                            startIndex = temp.indexOf("reportView[@name=");
                                            startString = temp.substring(startIndex);
                                            startIndex = startString.indexOf("@name=") + 6; //&apos; 6 characters
                                            endIndex = startString.lastIndexOf("]");
                                       // get report name
                                       reportViewName = startString.substring(startIndex+1, endIndex);
                                       //System.out.println("Found reportView name - " + reportViewName);
                                  else if (temp.indexOf("</fileName>")>0) //check for default name
                                       defName = temp.substring(temp.indexOf(">")+1, temp.lastIndexOf("<"));
                                  else if (temp.indexOf("asOfTime")>=0) // get the time to assure uniqueness when saving
                                       ofTime = temp.substring(temp.indexOf(">")+1, temp.lastIndexOf("<"));
                                       // clean colons from time
                                       ofTime = ofTime.replaceAll(":","_");
                                  else if (temp.indexOf("</burstKey>")>=0)
                                       burstKey = temp.substring(temp.indexOf(">")+1, temp.lastIndexOf("<"));
                             in.close();
                             if (reportName.length() == 0)
                                  reportName = reportViewName;
                                  //System.out.println("Renaming using view name - no report name found");
                                       String format = defName.substring(defName.length()-3, defName.length());
                             // new description xml file
                                       File file = new File(outputLocation+filename);
                             File newDescFile = new File(outputLocation + reportName+"_"+burstKey+"_"+ofTime+"DESC_" + format+ ".xml");
                                       // new renamed specific format file.
                             File file3 = new File(outputLocation+defName);
                             File newDefFile = new File(outputLocation + reportName+"_"+burstKey+"_"+ofTime+"."+format);
                             boolean success = file3.renameTo(newDefFile);
                             if (!success)
                                  // File was not successfully renamed
                                  System.out.println("ERROR attempting to rename - " + file3.getAbsolutePath() + " to \n\t\t" +
                                            newDefFile.getAbsolutePath());
                             else
                                  countRenamed++;
                                  // File was successfully renamed
                                  System.out.println(countRenamed +") Renamed - " + file3.getAbsolutePath() + " to \n\t\t" +
                                            newDefFile.getAbsolutePath());
                             // Rename file (or directory)
                             success = file.renameTo(newDescFile);
                             if (!success)
                                  // File was not successfully renamed
                                  System.out.println("ERROR attempting to rename - " + file.getAbsolutePath() + " to \n\t\t" +
                                            newDescFile.getAbsolutePath());
                             else
                                  // File was successfully renamed
                                  System.out.println(" - " + file.getAbsolutePath() + " to \n\t\t" +
                                            newDescFile.getAbsolutePath());
                   catch (Exception e)
                        System.err.println("File input error " + e.getMessage()) ;
         System.out.println("Complete.");
    Thanks,
    Nick
    Edited by: nickmills on Aug 31, 2008 5:05 PM

    First, you only need to create the FileInputStream once. Then that's what you pass to the InputStreamReader constructor. Your code for reading from the BufferedReader is also wrong.FileInputStream fstream = new FileInputStream(outputLocation+filename);
    // FileInputStream bis = new FileInputStream(fstream);  <-- remove this line
    BufferedReader in = new BufferedReader(new InputStreamReader(fstream));
    // available() doesn't do what you think it does; forget about it.
    // Here's the standard way to use a BufferedReader
    String line = null;
    while ((line = in.readLine()) != null)
      // process 'line'
    } There are probably other errors in the code, but reading all that unformatted code is too much of a hassle. In future, please use &#x7B;code} tags when posting source code.

  • Cannot resolve symbol when the classes are in the same package

    i have one interface and two classes all in the same package. am getting " cannot resolve symbol", when the code refers to the interface or the class .
    the package name is collections.impl and
    the directory i used to store all the java files:
    c:\jdk\bin\collections\impl.
    isthere any othe option other than compiling all the files from the comand line at the same time?
    please help - i m new to java.

    If you have:
    I.java:
    package some;
    public interface I {
        void method();
    }A.java:
    package some;
    public class A implements I {
        public void method() {
            new B();
    }B.java:
    package some;
    public class B implements I {
        public void method() {
            new A();
    }in c:/temp/some for example
    you can compile your files with
    javac c:/temp/some/*.java
    It seems that you have errors in your code.
    Recheck it twice or use NetBeans IDE(http://www.netbeans.org) it will do this for you ;)

  • "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));

Maybe you are looking for

  • [SOLVED]Installing X

    After trying to install X with the command: # pacman -S xorg-server xorg-xinit xorg-server-utils I get the error message: error: xorg-xset: signature from "jan de groot <[email protected]>" is invalid error: failed to commit transaction (invalid or c

  • Removing secondary tile without confirmation

    I can understand the fact that adding a secondary tile requires the end-user to approve the request... But the removing process should provide a way to remove a tile without user interaction since sometimes the tile may refer to a file in my particul

  • Measures in the fact table

    Hello, Can i have measures in the fact table in business layer? I am using obiee 11g. like i have a fact table where i have a user i applied aggregation rule of count distinct. Now i would like to add a lower function to it like count (distinct(lower

  • Itunes not openin it says"the foldr itunes is in a lockd disc.....dont hav wite....."pls help"

    pls help

  • Order settlement - Account substitution

    Hi SAP community, We need to create an substitution rule for the account number at the moment of the order settlement. We have some maintenance orders and service orders that we need to do the account reclassification when we do the settlement to cos