Problem using PixelGrabber ( cannot resolve symbol ) - newbie
Hi All,
I have a problem with my short program because the compiler write this (jdk1.4) :
img.java:17: cannot resolve symbol
symbol : constructor PixelGrabber (java.awt.Image,int,int,int,int,int[],int)
location: class java.awt.image.PixelGrabber
PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this
),image.getHeight(this),pixels,0);
^
1 error
... And I wrote that in my code :
( all is OK, the bug is only when I uncomment the line where the PixelGrabber object
is needed in my program ).
Thanks if you have any idea of solution to solve this problem or a doc,
( I don't find the answer to my problem in http://java.sun.com/j2se/1.4/docs/api/java/awt/image/PixelGrabber.html ),
import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.awt.image.PixelGrabber;
public class img extends Applet {
Image image;
int pixels[];
public void init() {
image = getImage(getDocumentBase(), "rouge.jpg");
pixels = new int[image.getWidth(this) * image.getHeight(this)];
PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
pg.grabPixels();
public void paint(Graphics g) {
String s = Integer.toString(pixels[5], 16);
g.drawString(s, 50, 50);
Hi,
PixelGrabber needs one more parameter scansize (width).
change this line;
PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
to:
PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0, image.getWidth(this)
);
Similar Messages
-
Help!!! error: cannot resolve symbol
can anyone tell me how to solve the following problem
thank you
cannot resolve symbol
symbol : method decode (java.lang.String)
location: class java.lang.Short
Short psmShort = Short.decode(psmString);
^
Long bdAddrLong = Long.decode("0x" + bdAddrString);
^that is because these methods does not exist. What you can use instead is parseShort(String) or parseLong.
Maybe reading the javadoc could help you next time ;-)
hth
Kay -
Hello, say i have a class
A
that contains an object of class B.
Now there's class X...
It's all fine and dandy trying to compile them both until i try to set the classpath for junit, by doing:
set classpath=%classpath%;C:\junit3.8.1\junit.jar
i'm pretty sure it's correct...
well once i type in this line into my command prompt (win 2k), the junit package now seems to be recognized by class X, which is my testing class that contains an object of class A.
but NOW class A can't find class B and i get a cannot resolve symbol error. Same goes for class X not being able to find class A.
Anyone have any suggestions? I'm a newb to this :( . Thanks.nevermind! noob mistake.
-
Newbie problem: "cannot resolve symbol"
I'm working through some tutorials but I get errors even if i get the code CORRECT or I should say identical to the source code displayed on the web. For instance i get this:
E:\Java\New>javac SwingUI.java
SwingUI.java:41: not a statement
WindowListener 1 = new WindowAdapter() {
^
SwingUI.java:41: ';' expected
WindowListener 1 = new WindowAdapter() {
^
SwingUI.java:4: cannot resolve symbol
symbol : class ActionListener
location: class SwingUI
class SwingUI extends JFrame implements ActionListener {
^
SwingUI.java:25: cannot resolve symbol
symbol : class ActionEvent
location: class SwingUI
public void actionPerformed(ActionEvent event){
^
SwingUI.java:15: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (SwingUI)
button.addActionListener(this);
^
SwingUI.java:18: cannot resolve symbol
symbol : class Borderlayout
location: class SwingUI
panel.setLayout(new Borderlayout());
^
SwingUI.java:46: addWindowListener(java.awt.event.WindowListener) in java.awt.Window cannot be applied to (int)
frame.addWindowListener(1);
^
SwingUI.java:48: cannot resolve symbol
symbol : variable set
location: class SwingUI
frame.set.Visible(true);
^
8 errors
The beginning of the code is:
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
class SwingUI extends JFrame implements ActionListener {
JLabel text, clicked;
JButton button, clickButton;
JPanel panel;
private boolean _clickMeMode = true;
SwingUI(){
text=new JLabel("I'm a simple program");
button= new JButton("Click here!");
button.addActionListener(this);
panel =new JPanel();
panel.setLayout(new Borderlayout());
panel.setBackground(Color.white);
getContentPane().add(panel);
panel.add(BorderLayout.CENTER, text);
panel.add(BorderLayout.SOUTH, button);
To me it seems as if there is a problem with my environmental settings and/or with the "import" files, but wouldn't that yield different error messages?
I'm running j2sdk1.4.0_01 on windows2000 professional
I should say that simple programs compile without errors.
thx
/HansThe letter 'l' is very similar to the number 1 in certain fonts unfortunately.
/Hans -
When i try to use max() & pow() in jdbc i get error "cannot resolve symbol"
hi,
when i tried to use pow() & max() in my jdbc programme i got compilation error "cannot resolve symbol".
even i have imorted java.math
this is the sample.
pr1= (fy/(L*B*pow(10.0,-6.0))+((6*mx)/(L*B*B*pow(10.0,-6.0)))+((6*mz)/(B*L*L*pow(10.0,-6.0))));
all of above are double.
and with max();
pr=max(pr1,pr2);
all of above are double.
please help.
thanks in advance.
satishhi
Hartmut
thanks hartmut;
i am new in java so i have some problems, but thanks for helping me.
please help me again.
as i have already posted another probleme which i have with selecting 1000 rows 1 by 1 from a table & manipulate 1 by 1 on that and then store all manipulated row to another table.
when i tried to do so i am able to select only 600 rows and manipulate them & store them.
i did not get any exception or any error.
can this possible that microsoft access driver has not that much capacity to provide 1000 rows or it is problem with jdbc.
please help.
satish
thanks again. -
Compilation problem (cannot resolve symbol)
I have searched the Forums for "cannot resolve symbol" and as usual, many posts with no answers or just advise that noone ever comes back to say works. I am trying to compile this code:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import org.acme.*;
public class HelloOpenEJB extends HttpServlet {
String factory = "org.openejb.client.LocalInitialContextFactory";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
PrintWriter out = response.getWriter();
try{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, factory );
InitialContext ctx = new InitialContext( p );
//Lookup the bean using it's deployment id
Object obj = ctx.lookup("/Hello");
HelloHome ejbHome = (HelloHome) obj;
//Use the HelloHome to create a HelloObject
HelloHome ejbHome = (HelloHome)
PortableRemoteObject.narrow(obj, HelloHome.class);
//The part we've all been wainting for...
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>"+ ejbObject.sayHello() +"</h1>");
out.println("</body>");
out.println("</html>");
} catch (Exception e){
response.setContentType("text/plain");
e.printStackTrace(out);
I'm running this on a Linux box. When I compile, I get this:
HelloOpenEJB.java:28: ejbHome is already defined in doGet(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
HelloHome ejbHome = (HelloHome)
^
HelloOpenEJB.java:29: cannot resolve symbol
symbol : variable PortableRemoteObject
location: class HelloOpenEJB
PortableRemoteObject.narrow(obj, HelloHome.class);
^
HelloOpenEJB.java:38: cannot resolve symbol
symbol : variable ejbObject
location: class HelloOpenEJB
out.println(""+ ejbObject.sayHello() +"");
^
3 errors
I don't know why any of these errors are occuring, besides the obvious responses given back from javac, so can someone help? Thanks, JeremyThe error message "x already defined in y" means that you're trying to use a name that already exists in the current scope. In your case you have:
HelloHome ejbHome = (HelloHome) obj;
//Use the HelloHome to create a HelloObject
HelloHome ejbHome = (HelloHome)
PortableRemoteObject.narrow(obj, HelloHome.class);Here you are trying to declare two instances of HelloHome with the same name.
The reason that you would get "cannot resolve symbol" is that you are trying to access a variable or class that you haven't declared or imported. -
Cannot resolve symbol-- data access problem
hi, everyone, i am new to java... thx for helping me.
i have two files
1) dls.java
2) SliderDemo.java
in the dls.java i have the following coding:
JPanel slider = new SliderDemo(this);
slider.framesPerSecond(0);
and in the SliderDemo.java i have following coding:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class SliderDemo extends JPanel implements ActionListener {
//This label uses ImageIcon to show the doggy pictures.
JLabel picture;
dls mydls;
JSlider framesPerSecond;
int i;
public SliderDemo(dls mydls) {
this.mydls = mydls;
framesPerSecond = new JSlider(JSlider.HORIZONTAL, -10, 10, 0);
framesPerSecond.addChangeListener(new SliderListener());
//Turn on labels at major tick marks.
framesPerSecond.setMajorTickSpacing(10);
framesPerSecond.setMinorTickSpacing(1);
framesPerSecond.setPaintTicks(true);
framesPerSecond.setPaintLabels(true);
framesPerSecond.setBorder( BorderFactory.createEmptyBorder(0,0,10,0));
.....etc
when i compile the dls.java
it told me cannot resolve symbol , framePerSecond...
help!!!why i can't resolve the symbol?
thx all experts.
yours,
Terrycannot resolve symbol , framePerSecondPerhaps because you declared a variable whose name is "framesPerSecond" and then you tried to use "framePerSecond" instead of that?
-
JSP Compilation Problem - Cannot Resolve Symbol
I cannot see the problem. Maybe I am not sober at 2:30 am.
<%
Collection postBeans = ( Collection )request.getAttribute( "PostBeans" );
Iterator iterator = postBeans.iterator();
int i = 0;
while( iterator.hasNext() )
PostBean postBean = (PostBean)iterator.next();
i++;
String background;
if ( postBean.getParentPostID() == 0 )
background = "#FFCE9C";
else
if ( ( i%2 ) != 0 )
background = "#EEEEEE";
else
background = "#FFFFFF";
%>
<table width="95%" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#999999">
<tr bgColor=<%=background%>>
</tr>
</table>I got compilation error: cannot resolve symbol
symbol: backgroundI put the variable 'background' outside the while loop. The 'cannot resolve symbol' problem is gone. But, I got another compilation error:
>
unexpected type
required: variable
found : value
out.write("\r\n }\r\n i++;\r\n if ( postBean.getParentPostID() == 0 ) \r\n {\r\n background = \"#FFCE9C\";\r\n }\r\n else \r\n {\r\n if ((i%2) != 0) \r\n {\r\n background = \"#EEEEEE\";\r\n } \r\n else \r\n {\r\n background = \"#FFFFFF\";\r\n }\r\n }\r\n%>\r\n");
The code looks like:
<%
String background;
Collection postBeans = ( Collection )request.getAttribute( "PostBeans" );
Iterator iterator = postBeans.iterator();
int i = 0;
while( iterator.hasNext() )
PostBean postBean = (PostBean)iterator.next();
i++;
if ( postBean.getParentPostID() == 0 )
background = "#FFCE9C";
else
if ( ( i%2 ) != 0 )
background = "#EEEEEE";
else
background = "#FFFFFF";
%>
<table width="95%" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#999999">
<tr bgColor=<%=background%>>
</tr>
</table> -
Cannot resolve symbol - attempt to use System.out.printf
Hi All,
I adapted a HelloWorld program to use
System.out.printf instead of System.out.println (just for a test)
The println comand compiles fine with no errors, but for some reason the printf generates compile time error. Please let me know what am doing wrong.
Below is the error:
d:\j2sdk1.4.1_05\bin>javac HelloWorld.java
HelloWorld.java:6: cannot resolve symbol
symbol : method Printf (java.lang.String,java.lang.String)
location: class java.io.PrintStream
System.out.printf("%s","Hello, world!");
^
1 error
code:
public class HelloWorld {
public static void main (String[] args) {
System.out.printf("%s","Hello, world!");
}If you check the documentation you can see this method was added in version 1.5
http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html#printf(java.util.Locale,%20java.lang.String,%20java.lang.Object...)
BTW: I suggest you use a current version of java, either 1.4.2_09 or 1.5.0_04 -
"cannot resolve symbol" error when using super.paintComponent
I am trying to override the paintComponent method in a class extending a JFrame, but when I call super.paintComponent(g) from inside the overridden method I get the error
QubicGUI.java:63: cannot resolve symbol
symbol : method paintComponent (java.awt.Graphics)
location: class javax.swing.JFrame
super.paintComponent(g);
^
1 error
I can't see where I am deviating from examples I know work. It is a very small program, so I have included it here:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.net.URL;
class QubicGUI extends JFrame
private int width;
private int height;
private Image background;
public int getWidth()
{ return width; }
public int getHeight()
{ return height; }
public boolean isOpaque()
return true;
public QubicGUI()
super("Qubic"); //set title
// The following gets the default screen device for the purpose of finding the
// current settings of height and width of the screen
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = environment.getDefaultScreenDevice();
DisplayMode display = device.getDisplayMode();
width = display.getWidth();
height = display.getHeight();
// Here we set the window to cover the entire screen with a black background, and
// remove the decorations. (This includes the title bar and close, minimize and
// maximize buttons and the border)
setUndecorated(false);
setVisible(true);
setSize(width,height);
setResizable(false);
setBackground(Color.black);
// Initializes the background Image
Image background = Toolkit.getDefaultToolkit().getImage("background.gif");
// This is included for debugging with a decorated window.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} // end constructor
public void paintComponent(Graphics g)
super.paintComponent(g);
} // end paintComponenet
} // end QubicGUITwo things I want to know:
1. I was trying to access a variable as JLabel
myLabel; defined in the constructor of a class from
the constructor of another class. I got this error
message - "Cannot access non-static variable from a
static context". Why(When both are non-static am I
getting the message as static context)?Post some code. It's hard to pinpoint a syntax error like that without seeing the code.
Also, there may be cleaner ways of doing what you want without having classes sharing labels.
2. I am using a map to set the attributes of a font.
One of the key-value pair of the map is
TextAttributesHashMap.put(TextAttribute.FOREGROUND,Colo
.BLUE);
But when I using the statement g.drawString("First
line of the address", 40, 200); the text being
displayed is in black and not blue. Why?You need to use the drawString that takes an AttributedCharacterIterator:
import java.awt.*;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
public class Example extends JPanel {
public static void main(String[] args) {
JFrame f = new JFrame("Example");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = f.getContentPane();
cp.add(new Example());
f.setSize(400,300);
f.setLocationRelativeTo(null);
f.setVisible(true);
protected void paintComponent(Graphics g) {
super.paintComponent(g);
String text = "Every good boy does fine always";
AttributedString as = new AttributedString(text);
as.addAttribute(TextAttribute.FAMILY, "Lucida Bright");
as.addAttribute(TextAttribute.SIZE, new Float(16));
as.addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 5);
as.addAttribute(TextAttribute.FOREGROUND, Color.GREEN, 6, 10);
as.addAttribute(TextAttribute.FOREGROUND, Color.RED, 11, 14);
as.addAttribute(TextAttribute.FOREGROUND, Color.YELLOW, 15, 19);
as.addAttribute(TextAttribute.FOREGROUND, Color.MAGENTA, 20, 24);
as.addAttribute(TextAttribute.FOREGROUND, Color.CYAN, 25, 31);
g.drawString(as.getIterator(), 10, 20); -
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 -
JSP page "cannot resolve symbol"
Hi,
I'm using j2sdk1.4.2_01 and tomcat-5.0.13. I'm developing within Eclipse 3.0.0 with the Tomcat plugin.
In my project ("Agenda2") i only created one class ("Persona"), that is correctely compiled (%TOMCAT_HOME%\webapps\Agenda2\WEB-INF\src\Persona.java results in %TOMCAT_HOME%\webapps\Agenda2\WEB-INF\classes\Persona.class, and 0 problems are shown in the Problems list.
In %TOMCAT_HOME%\webapps\Agenda2 i have my Edit.jsp, that begins with these lines:
<%@ page language="java" contentType="text/html" %>
<HTML>
<HEAD>
<TITLE>Edit</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="personaAtt" class="Persona">
<jsp:setProperty name="personaAtt" property="*" />
</jsp:useBean>
....When i call the JSP from the browser, i get this error:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 8 in the jsp file: /Edit.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Programmi\Java\tomcat-5.0.13\webapps\Agenda2\work\org\apache\jsp\Edit_jsp.java:48: cannot resolve symbol
symbol : class Persona
location: class org.apache.jsp.Edit_jsp
Persona personaAtt = null;
^The error message mentions line 8, which is the one following <BODY>, that is
<jsp:useBean id="personaAtt" class="Persona">My impression is that there is some path problem, but despite my tries i can't get it.
The folders tree under %TOMCAT_HOME%\webapps\Agenda2\ is:
-WEB-INF
--classes
--lib
--src
-work
--org
---apache
----jspDoes anybody can see the problem ?Thanks! I'm going to try to put the class into a package as both you have suggested, and i'll post here the result.
In the meantime i have a related newbie question:
putting the class into a package, is this kind of a workaround, or it's the "normal thing" ?
I mean, is it mandatory to put classes into a package in order to import them from JSP pages ?
It was my understanding that it isn't mandatory, but - from your replies and many other posts in this forum - i'm starting to think that i'm wrong. -
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. -
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='");
String startString;
int endIndex = 0;
if (startIndex > 0)
startString = temp.substring(startIndex);
startIndex = startString.indexOf("'") + 5; //' 6 characters
endIndex = startString.lastIndexOf("'");
else
startIndex = temp.indexOf("report[@name=");
startString = temp.substring(startIndex);
startIndex = startString.indexOf("@name=") + 6; //' 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='");
String startString;
int endIndex = 0;
if (startIndex > 0)
startString = temp.substring(startIndex);
startIndex = startString.indexOf("'") + 5; //' 6 characters
endIndex = startString.lastIndexOf("'");
else
startIndex = temp.indexOf("reportView[@name=");
startString = temp.substring(startIndex);
startIndex = startString.indexOf("@name=") + 6; //' 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 PMFirst, 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 {code} tags when posting source code. -
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.
Maybe you are looking for
-
Object Size and Position values not being retained
Hi, I'm trying to set the size and position of a picture object in a report. This logo, should appear on the top right corner of the report. The margins of the report are Left - .79 in, Right - 0.79 in, Top - 0.79 in and Bottom - 0.39 in. The
-
Applet hangs web server when upgrading from 1.6 to 1.7
I've got a client-side printing application which works fine on 1.6 and fails on 1.7 where it essentially hang the server on the connect option to the server and loading the jar file. Specifics: PC Client running windows 7 x64 Browser versions IE9, I
-
I have authorised a new comuter when I plug in my iphone, not all the songs in the iphone show up in the music library on the computer - nor my playlists How do I get all my songs and playlists from my iphone to my newly authorised computer?
-
Categories in a Shared Mailbox
Hi, I've just had to delete the OST of a user that has her own mailbox and access to a shared mailbox. When this was recreated, she lost all her categories on the shared mailbox. My question is, are the categories stored by default locally (in an Ou
-
Upgrade from Solaris 8 to Solaris 9... it sort of worked
I upgraded a V440 from solaris 8 to solaris 9 last night and it sort of worked. I tried installing off of disk1 instead of the install disk and it wouldn't mount the cd. So I just installed off of the install disk. All seemed to go well but after the