Cannot resolve import statements
I recently decided to start messing around with some Java3d. I tried to get an example program to try to dissect but I can't even get past compilation. The main problem is the fact that the import statements cannot be resolved. I thought maybe I was using an outdated example program but upon further inspection of Oracle's own Java3d tutorials I saw the same import statements. I downloaded java3d 1.5.1 because I thought perhaps it wasn't included in the java core classes. This did not help me at all. So maybe it is a problem with the IDE (eclipse) not recognizing them. However, I have had no such success with Google thus far. I realize that this is more than likely a horribly simple mistake that anyone over a novice understanding of Java would be able to spot. But if anyone could help me figure out why I can't compile it would be much appreciated.
Regards,
Corey
Import statements that would not resolve
import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.*;
import javax.vecmath.*;Full program
import java.awt.Color;
import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;
import com.sun.j3d.utils.universe.SimpleUniverse;
import javax.media.j3d.*;
import javax.vecmath.*;
// An Egyptian pyramid
// Base divided into two triangles
public class PyramidExample {
public static void main(String[] args) {
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
Point3f e = new Point3f(1.0f, 0.0f, 0.0f); // east
Point3f s = new Point3f(0.0f, 0.0f, 1.0f); // south
Point3f w = new Point3f(-1.0f, 0.0f, 0.0f); // west
Point3f n = new Point3f(0.0f, 0.0f, -1.0f); // north
Point3f t = new Point3f(0.0f, 0.721f, 0.0f); // top
TriangleArray pyramidGeometry = new TriangleArray(18,
TriangleArray.COORDINATES);
pyramidGeometry.setCoordinate(0, e);
pyramidGeometry.setCoordinate(1, t);
pyramidGeometry.setCoordinate(2, s);
pyramidGeometry.setCoordinate(3, s);
pyramidGeometry.setCoordinate(4, t);
pyramidGeometry.setCoordinate(5, w);
pyramidGeometry.setCoordinate(6, w);
pyramidGeometry.setCoordinate(7, t);
pyramidGeometry.setCoordinate(8, n);
pyramidGeometry.setCoordinate(9, n);
pyramidGeometry.setCoordinate(10, t);
pyramidGeometry.setCoordinate(11, e);
pyramidGeometry.setCoordinate(12, e);
pyramidGeometry.setCoordinate(13, s);
pyramidGeometry.setCoordinate(14, w);
pyramidGeometry.setCoordinate(15, w);
pyramidGeometry.setCoordinate(16, n);
pyramidGeometry.setCoordinate(17, e);
GeometryInfo geometryInfo = new GeometryInfo(pyramidGeometry);
NormalGenerator ng = new NormalGenerator();
ng.generateNormals(geometryInfo);
GeometryArray result = geometryInfo.getGeometryArray();
// yellow appearance
Appearance appearance = new Appearance();
Color3f color = new Color3f(Color.yellow);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Texture texture = new Texture2D();
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
Material mat = new Material(color, black, color, white, 70f);
appearance.setTextureAttributes(texAttr);
appearance.setMaterial(mat);
appearance.setTexture(texture);
Shape3D shape = new Shape3D(result, appearance);
group.addChild(shape);
// above pyramid
Vector3f viewTranslation = new Vector3f();
viewTranslation.z = 3;
viewTranslation.x = 0f;
viewTranslation.y = .3f;
Transform3D viewTransform = new Transform3D();
viewTransform.setTranslation(viewTranslation);
Transform3D rotation = new Transform3D();
rotation.rotX(-Math.PI / 12.0d);
rotation.mul(viewTransform);
universe.getViewingPlatform().getViewPlatformTransform().setTransform(
rotation);
universe.getViewingPlatform().getViewPlatformTransform().getTransform(
viewTransform);
// lights
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
1000.0);
Color3f light1Color = new Color3f(.7f, .7f, .7f);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
Color3f ambientColor = new Color3f(.4f, .4f, .4f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
group.addChild(ambientLightNode);
universe.addBranchGraph(group);
}
Hi,
- The latest Java 3D release is *1.5.2*. Uninstall older versions.
- Java 3D home: http://java3d.java.net/
- Java 3D project: http://java.net/projects/java3d
- Java 3D downloads: http://java3d.java.net/binary-builds.html
- Start with one of the Java 3D examples from "j3d-examples-1_5_2-src.zip"
- Use eclipse *3.6.2*, it should recognize Java 3D's jars if they are installed in '..\jre\lib\ext\'. See also Java3D + Newer Eclipse Version -> Access Restriction (solution + question)
August
Similar Messages
-
Import statements cannot be resolved
I couldnt able to import the following statements,
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
import weblogic.ejb.GenericEntityBean;
import weblogic.ejbgen.;*
Do we need to set any properties..
I have set the classpath,path .. but still weblogic,javax.ejb is not resolving in import statement
Do we need to make anything in weblogic settings
Thanks well in advanceGuess you are getting some errors related to class not found..
Did you set weblogic.jar in the classpath ? -
"Cannot resolve symbol" error when importing a package
I'm new to Java and have been trying to make use of a toolikt which uses an imported package. Basically my problem is that I've been trying to compile a file called CookBook.java which contains the following import statements at the top of the file:
package gate;
import java.util.*;
import java.net.*;
import java.io.*;
import junit.framework.*;
import gate.*;
import gate.util.*;
import gate.creole.*;
import gate.creole.nerc.*;
I then compile this using the following command line:
/cygdrive/c/jdk1.3.1_01/bin/javac.exe \
-classpath "C:\cygwin\home\stevens1\gate_src\gate\build\gate.jar" \
-extdirs "C:\cygwin\home\stevens1\gate_src\gate\lib\ext" \
-d . CookBook.java
(The extdirs command is required, acording to the manual, because the toolkit is implemented as two files for security reasons: gate.jar and guk.jar) These two flags should point to all the .jar files required by the application.
However, that command produces the following errors:
CookBook.java:140: cannot resolve symbol
symbol : method assertTrue (java.lang.String,boolean)
location: class gate.CookBook
assertTrue(
^
CookBook.java:146: cannot resolve symbol
symbol : variable GateConstants
location: class gate.CookBook
GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
^
CookBook.java:152: cannot resolve symbol
symbol : method assertTrue (java.lang.String,boolean)
location: class gate.CookBook
assertTrue(
^
One thing I've not been clear on is whether the files (CookBook.java) need to be in a directory with a special name. I've tried playing about with different ones but without much success.
Any suggestions to help a completely confused Java rookie would really be apreciated!
thanks in advance
markI then compile this using the following command line:
/cygdrive/c/jdk1.3.1_01/bin/javac.exe \
-classpath "C:\cygwin\home\stevens\gate_src\gate\build\gate.jar" \
-extdirs "C:\cygwin\home\stevens1\gate_src\gate\lib\ext" \
-d . CookBook.javaThere are a couple of issues with your compile...
Most notably, by setting the classpath to your build jar, you are compiling against old classes. If you set your classpath rather to the base of your package hierarchy, then javac will to some degree review and recompile dependencies, against your current source files. If you specify a target directory with -d, class files will be examined in this location if they aren't in the class path (And their source file is not in the compile-path)
Also, if you are compiling packages, I've found a good practice to be to compile from the base of the package structure, so your command will be more likejavac \
-classpath . \
-extdirs "C:\cygwin\home\stevens1\gate_src\gate\lib\ext" \
gate\\CookBook.javaIt seems to make it easier for the compiler to 'correctly' look up dependencies.
Hope that helps, at least a little,
-Troy -
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 : import
I've never had this type of error while doing a compile before.
Does this mean that java doesn't know where to find my org.nipr.gateway_ws.utils.ConnectionPoolSingleton?
[javac] Compiling 1 source file to C:\Data\StateProcessWebService\Server\build\war\WEB-INF\classes
[javac] C:\Data\StateProcessWebService\Server\src\org\nipr\StateProcess\impl\StateProcessImpl.java:20: cannot resolve symbol
[javac] symbol : class ConnectionPoolSingleton
[javac] location: package utils
[javac] import org.nipr.gateway_ws.utils.ConnectionPoolSingleton;
[javac] ^
[javac] C:\Data\StateProcessWebService\Server\src\org\nipr\StateProcess\impl\StateProcessImpl.java:265: cannot resolve symbol
[javac] symbol : variable ConnectionPoolSingleton
[javac] location: class org.nipr.StateProcess.impl.StateProcessImpl
[javac] ConnectionPooler pool = ConnectionPoolSingleton.instance( "stateProcess" );
[javac] ^Cool. Thanks.
I freaked when I first saw that. I added the missing java file and it compiled just fine. -
Import javax.ejb.EJBHome; cannot resolve symbol
Hi i wonder if anyone can help me. I have read alot of the posts regarding this issue and have tried everything to do with the paths and environmental variables and even reinstalled everything.
import javax.ejb.EJBHome; cannot resolve symbol
This is the problem i keep getting and here are the paths that i set:
SET PATH=c:\j2sdkee1.3\bin;c:\jdk1.3.1_01\bin;c:\jakarta-ant-1.3\bin
SET ANT_HOME=c:\jakarta-ant-1.3
SET JAVA_HOME=c:\jdk1.3.1_01
SET J2EE_HOME=c:\j2sdkee1.3
SET CLASSPATH=c:\j2sdkee1.3\lib\j2ee.jar;c:\jakarta-ant-1.3\lib\ant.jar;c:\jdk1.3.1_01\lib\tools.jar
What am i doing wrong???Im not sure, everything looks ok to me, but here is what i tried:
I wrote this little test class, and compiled it
import javax.ejb.EJBHome;
public class test
public test()
I got the same error you did (or similar)
D:\>javac test.java
test.java:1: package javax.ejb does not exist
import javax.ejb.EJBHome;
^
1 error
then I added the j2ee.jar to my classpath and everything worked fine.
here are my env vars:
JAVA_HOME=d:\dev\jdk
J2EE_HOME=d:\dev\j2sdkee
CLASSPATH=...;%J2EE_HOME%\lib\j2ee.jar
If I were you I would double check all the paths you have set up then try a simple case like the one above. If your running NT/2000 make sure the JAVA_HOME, J2EE_HOME and CLASSPATH are system variables not user variables. Another thing you can try is adding the j2ee.jar to the classpath with the -classpath compiler switch.
javac -classpath %CLASSPATH%;d:\dev\j2sdkee\lib\j2ee.jar test.java
Other than those things I'm not sure
Good Luck -
'Cannot Resolve Symbol' error when importing custom class
I get this error...
c:\mydocu~1\n307\auto.java:14: cannot resolve symbol
symbol: class Box
import Box;
^
when I try to compile auto.java, the applet that's supposed to import the class Box, which I built to be like a message box in VB. Here is the code for Box...
import java.awt.*;
import java.awt.event.*;
public class Box extends Window{
Label lblMsg = new Label();
Button cmdOk = new Button("OK");
Panel pnlSouth = new Panel();
EventHandler ehdlr=new EventHandler(this);
public Box(Frame parent){
super(parent);
setLayout(new BorderLayout());
add(lblMsg, BorderLayout.NORTH);
add(pnlSouth, BorderLayout.SOUTH);
pnlSouth.setLayout(new FlowLayout());
pnlSouth.add(cmdOk);
cmdOk.addActionListener(ehdlr);
this.addWindowListener(ehdlr);
public void speak(String msg){
lblMsg.setText(msg);
this.setLocation(200,200);
this.setSize(200,200);
this.setVisible(true);
private class EventHandler extends WindowAdapter
implements ActionListener{
Window theWindow;
public EventHandler(Window a){
theWindow=a;
public void actionPerformed(ActionEvent e){
theWindow.setVisible(false);
AND HERE IS THE CODE FOR AUTO...
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import Box;
public class auto extends Applet implements ActionListener{
Panel pnlCenter=new Panel();
Panel pnlSouth=new Panel();
Panel pnlNorth=new Panel();
Panel pnlCenterleft=new Panel();
Panel pnlCenterright=new Panel();
Button cmdSubmit=new Button("Submit");
Button cmdNext=new Button("Next");
Button cmdPrev=new Button("Previous");
Label lblLoc=new Label("LOCATION:");
Label lblDate=new Label("DATE:");
Label lblMile=new Label("MILEAGE:");
Label lblCost=new Label("COST:");
Label lblDesc=new Label("DESCRIPTION:");
Label lblFind=new Label("FIND LOCATION:");
Label lblDisp=new Label();
TextField txtLoc=new TextField();
TextField txtDate=new TextField();
TextField txtMile=new TextField();
TextField txtCost=new TextField();
TextArea txtDesc=new TextArea();
TextField txtFind=new TextField();
Box bxOne = new Box((Frame(this).getParent()));
/*by declaring these four variables here, they are instance level, meaning they are
available to the whole applet*/
String textFile="auto.txt";
String list[] = new String[100];
String sort[] = new String[100];
int counter=0;
int count=0;
String currentLine="";
int i;
int sortcount;
public void init(){
this.setLayout(new BorderLayout());
this.add(pnlNorth, BorderLayout.NORTH);
this.add(pnlCenter, BorderLayout.CENTER);
this.add(pnlSouth, BorderLayout.SOUTH);
pnlNorth.setLayout(new FlowLayout());
pnlNorth.add(new Label("VIEW RECORDS"));
pnlCenter.setLayout(new GridLayout(1,2));
pnlCenter.add(pnlCenterleft);
pnlCenter.add(pnlCenterright);
pnlCenterleft.setLayout(new GridLayout(0,1));
pnlCenterleft.add(lblLoc);
pnlCenterleft.add(lblDate);
pnlCenterleft.add(lblMile);
pnlCenterleft.add(lblCost);
pnlCenterleft.add(lblDesc);
pnlCenterleft.add(lblFind);
pnlCenterright.setLayout(new GridLayout(0,1));
pnlCenterright.add(txtLoc);
pnlCenterright.add(txtDate);
pnlCenterright.add(txtMile);
pnlCenterright.add(txtCost);
pnlCenterright.add(txtDesc);
pnlCenterright.add(txtFind);
pnlSouth.setLayout(new FlowLayout());
pnlSouth.add(cmdPrev);
pnlSouth.add(lblDisp);
pnlSouth.add(cmdSubmit);
pnlSouth.add(cmdNext);
lblDisp.setText("0 of 0");
cmdPrev.addActionListener(this);
cmdNext.addActionListener(this);
cmdSubmit.addActionListener(this);
public void actionPerformed(ActionEvent e){
String command=e.getActionCommand();
if (command.equals("Next")){
if(txtLoc.getText().equals("")){
reader();
transfer();
writer();
bxOne.speak("Viewing all records");
}else{
if(counter<count-2){
counter++;
writer();
}else{
//don't move
} else if (command.equals("Previous")){
if(txtLoc.getText().equals("")){
//do nothing
}else{
if(counter>0){
counter--;
writer();
}else{
//don't move
} else {
txtLoc.setText("");
txtDate.setText("");
txtMile.setText("");
txtCost.setText("");
txtDesc.setText("");
reader();
sorter();
writer();
private void writer(){
StringTokenizer stCurrent=new StringTokenizer(sort[counter], "\t");
txtLoc.setText(stCurrent.nextToken());
txtDate.setText(stCurrent.nextToken());
txtMile.setText(stCurrent.nextToken());
txtCost.setText(stCurrent.nextToken());
txtDesc.setText(stCurrent.nextToken());
lblDisp.setText(String.valueOf(counter+1) + " of " + String.valueOf(count-1));
private void reader(){
try{
URL textURL=new URL(getDocumentBase(), textFile);
InputStream issIn=textURL.openStream();
InputStreamReader isrIn=new InputStreamReader(issIn);
BufferedReader brIn=new BufferedReader(isrIn);
while(currentLine!=null){
currentLine=brIn.readLine();
list[count]=currentLine;
count++;
}catch(MalformedURLException exc){
System.out.println("MalformedURLException Error");
}catch(IOException exc){
System.out.println("IOException Error");
}catch(NullPointerException exc){
System.out.println("NullPointerException Error");
private void transfer(){
for(i=0;i<count;i++){
sort=list[i];
private void sorter(){
sortcount=0;
String find=txtFind.getText();
System.out.println(String.valueOf(count));
for(i=0;i<count-1;i++){
StringTokenizer st=new StringTokenizer(list[i], "\t");
String next=st.nextToken();
if (find.equals(next)){
sort[sortcount]=list[i];
sortcount++;
count=sortcount+1;
Any help is greatly appreciated.
2Willis4Hi agian,
I looked closer at your code, I think if you play around with directories and paths, you'll get it, and I think also when you import, you have to have put the class in a package...? Maybe? Blind leading the blind here! So at the top of your box class you have to say something like
package org.blah.lala
and you have to have that directory structure for the class files org/blah/lala/Box.class
Does that make sense?
And then when you import you say:
import org.blah.lala.Box
(I think)
I cna only imagine that this 'help' I am giving you would be hilarious to a more experienced programmer!
Anyway, best of luck. -
Import java.util.Formatter - cannot resolve symbol
I use j2sdk1.4.2_04
when I try to compile my program using Formatter, it response error "cannot resolve symbol"
Pls help!Where did you get this java.util.Formatter from? If you check the official 1.4.2 API for Java, that class does not exisit! However, java.util.logging.Formatter, does exisit...
http://java.sun.com/j2se/1.4.2/docs/api/
If you ment: java.util.logging.Formatter have you checked the API to make sure you are using it correctly???
HTH. -
Hey, I got confused with all import statement with jsp.
Here is my problem.
Folder structure:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\webapps\ROOT\WEB\S\A
This folder contains a.jsp.
JSP code:
<%@ page
language="java"
import="java.sql.*, MyPackage.DataBase"
errorPage=". . ."
contentType="text/html; charset=windows-1251"
%>
<%
Connection connection = null;
Statement statement = null;
DataBase dataBase = new DataBase( connection, statement );
%>
...Error message that I get:
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\work\Catalina\localhost\_\org\apache\jsp\WEB\S\A\a_jsp.java:7: package MyPackage does not exist
import MyPackage.DataBase;
^
An error occurred at line: 104 in the jsp file: /WEB/S/A/a.jsp
Generated servlet error:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\work\Catalina\localhost\_\org\apache\jsp\WEB\S\A\a100_jsp.java:147: cannot resolve symbol
symbol : class DataBase
location: class org.apache.jsp.WEB.S.A.a_jsp
DataBase dataBase = new DataBase( connection, statement );
^
...How do I import that class so I can use it?
Do I need to use useBean?
What do I need to do?
ThanksDataBase class does not extend java.sql.
I put this into my jsp page
import="java.sql.*;"
import="MyPackage.DataBase;" Here is the error message
Generated servlet error:
C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat-5.5.7\work\Catalina\localhost\_\org\apache\jsp\WEB\S\A\a_jsp.java:7: 'class' or 'interface' expected
import MyPackage.DataBase;;
^
1 error
... -
Class error - cannot resolve symbol "MyDocumentListener"
Hello,
this is a groaner I'm sure, but I don't see the problem.
Newbie-itis probably ...
I'm not concerned with what the class does, but it would be nice for the silly thing to compile!
What the heck am I missing for "MyDocumentListener" ?
C:\divelog>javac -classpath C:\ CenterPanel.java
CenterPanel.java:53: cannot resolve symbol
symbol : class MyDocumentListener
location: class divelog.CenterPanel
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
^
CenterPanel.java:53: cannot resolve symbol
symbol : class MyDocumentListener
location: class divelog.CenterPanel
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
^
2 errors
package divelog;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
import javax.swing.text.*;
public class CenterPanel extends JPanel implements ActionListener
{ // Opens class
static private final String newline = "\n";
private JTextArea comments;
private JScrollPane scrollpane;
private JButton saveButton, openButton;
private JLabel whiteshark;
private Box box;
private BufferedReader br ;
private String str;
private JTextArea instruct;
private File defaultDirectory = new File("C://divelog");
private File fileDirectory = null;
private File currentFile= null;
public CenterPanel()
{ // open constructor CenterPanel
setBackground(Color.white);
comments = new JTextArea("Enter comments, such as " +
"location, water conditions, sea life you observed," +
" and problems you may have encountered.", 15, 10);
comments.setLineWrap(true);
comments.setWrapStyleWord(true);
comments.setEditable(true);
comments.setFont(new Font("Times-Roman", Font.PLAIN, 14));
// add a document listener for changes to the text,
// query before opening a new file to decide if we need to save changes.
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
comments.getDocument().addDocumentListener(myDocumentListener); // create the reference for the class
// ------ Document listener class -----------
class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
Calculate(e);
public void removeUpdate(DocumentEvent e) {
Calculate(e);
public void changedUpdate(DocumentEvent e) {
private void Calculate(DocumentEvent e) {
// do something here
scrollpane = new JScrollPane(comments);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
saveButton = new JButton("Save Comments", new ImageIcon("images/Save16.gif"));
saveButton.addActionListener( this );
saveButton.setToolTipText("Click this button to save the current file.");
openButton = new JButton("Open File...", new ImageIcon("images/Open16.gif"));
openButton.addActionListener( this );
openButton.setToolTipText("Click this button to open a file.");
whiteshark = new JLabel("", new ImageIcon("images/gwhite.gif"), JLabel.CENTER);
Box boxH;
boxH = Box.createHorizontalBox();
boxH.add(openButton);
boxH.add(Box.createHorizontalStrut(15));
boxH.add(saveButton);
box = Box.createVerticalBox();
box.add(scrollpane);
box.add(Box.createVerticalStrut(10));
box.add(boxH);
box.add(Box.createVerticalStrut(15));
box.add(whiteshark);
add(box);
} // closes constructor CenterPanel
public void actionPerformed( ActionEvent evt )
{ // open method actionPerformed
JFileChooser jfc = new JFileChooser();
// these do not work !!
// -- set the file types to view --
// ExtensionFileFilter filter = new ExtensionFileFilter();
// FileFilter filter = new FileFilter();
//filter.addExtension("java");
//filter.addExtension("txt");
//filter.setDescription("Text & Java Files");
//jfc.setFileFilter(filter);
//Add a custom file filter and disable the default "Accept All" file filter.
jfc.addChoosableFileFilter(new JTFilter());
jfc.setAcceptAllFileFilterUsed(false);
// -- open the default directory --
// public void setCurrentDirectory(File dir)
// jfc.setCurrentDirectory(new File("C://divelog"));
jfc.setCurrentDirectory(defaultDirectory);
jfc.setSize(400, 300);
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
Container parent = saveButton.getParent();
//========================= Test Button Actions ================================
//========================= Open Button ================================
if (evt.getSource() == openButton)
int choice = jfc.showOpenDialog(CenterPanel.this);
File file = jfc.getSelectedFile();
/* a: */
if (file != null && choice == JFileChooser.APPROVE_OPTION)
String filename = jfc.getSelectedFile().getAbsolutePath();
// -- compare the currentFile to the file chosen, alert of loosing any changes to currentFile --
// If (currentFile != filename)
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
try
{ //opens try
comments.getLineCount( );
// -- clear the old data before importing the new file --
comments.selectAll();
comments.replaceSelection("");
// -- get the new data ---
br = new BufferedReader (new FileReader(file));
while ((str = br.readLine()) != null)
{//opens while
comments.append(str);
} //closes while
} // close try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Open command not successful:" + ioe + newline);
} // close catch
// ---- display the values of the directory variables -----------------------
comments.append(
newline + "The f directory variable contains: " + f +
newline + "The fileDirectory variable contains: " + fileDirectory +
newline + "The defaultDirectory variable contains: " + defaultDirectory );
else
comments.append("Open command cancelled by user." + newline);
} //close if statement /* a: */
//========================= Save Button ================================
} else if (evt.getSource() == saveButton)
int choice = jfc.showSaveDialog(CenterPanel.this);
if (choice == JFileChooser.APPROVE_OPTION)
File fileName = jfc.getSelectedFile();
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
//check for existing files. Warn users & ask if they want to overwrite
for(int i = 0; i < fileName.length(); i ++) {
File tmp = null;
tmp = (fileName);
if (tmp.exists()) // display pop-up alert
//public static int showConfirmDialog( Component parentComponent,
// Object message,
// String title,
// int optionType,
// int messageType,
// Icon icon);
int confirm = JOptionPane.showConfirmDialog(null,
fileName + " already exists on " + fileDirectory
+ "\n \nContinue?", // msg
"Warning! Overwrite File!", // title
JOptionPane.OK_CANCEL_OPTION, // buttons displayed
// JOptionPane.ERROR_MESSAGE
// JOptionPane.INFORMATION_MESSAGE
// JOptionPane.PLAIN_MESSAGE
// JOptionPane.QUESTION_MESSAGE
JOptionPane.WARNING_MESSAGE,
null);
if (confirm != JOptionPane.YES_OPTION)
{ //user cancels the file overwrite.
try {
jfc.cancelSelection();
break;
catch(Exception e) {}
// ----- Save the file if everything is OK ----------------------------
try
{ // opens try
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
bw.write(comments.getText());
bw.flush();
bw.close();
comments.append( newline + newline + "Saving: " + fileName.getName() + "." + newline);
break;
} // closes try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Save command unsuccessful:" + ioe + newline);
} // close catch
} // if exists
} //close for loop
else
comments.append("Save command cancelled by user." + newline);
} // end-if save button
} // close method actionPerformed
} //close constructor CenterPanel
} // Closes class CenterPanelThere is no way to be able to see MyDocumentListener class in the way you wrote. The reason is because MyDocumentListener class inside the constructor itself. MyDocumentListener class is an inner class, not suppose to be inside a constructor or a method. What you need to do is simple thing, just move it from inside the constructor and place it between two methods.
that's all folks
Qusay -
PLEASE HELP: cannot resolve symbol class
it's showing me the error on the following lines 7 and 9
it says cannot resolve symbol class Name and cannot resolve symbol class Phone
I also have a package name addressBook and it contains two files Entry.java and Address.java
Here is the code:
import java.io.*;
import addressBook.*;
public class AddressDr
public static void main(String[] args)throws IOException
Name name;
Address address;
Phone phone;
Entry entry;
String first, last, middle, street, city, state, zip;
int areaCode, number;
BufferedReader in;
in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outFile;
outFile=new PrintWriter(new FileWriter("Entries"));
System.out.println("Quit entered fot the first name ends the " + "application.");
System.out.print("Enter first name: ");
first=in.readLine();
while (first.compareTo("Quit") !=0)
System.out.print("Enter last name: ");
last=in.readLine();
System.out.print("Enter middle name: ");
middle=in.readLine();
name=new Name(first, last, middle);
System.out.print("Enter street address: ");
street=in.readLine();
System.out.print("Enter city: ");
city=in.readLine();
System.out.print("Enter state: ");
state=in.readLine();
System.out.print("Enter ZIP code: ");
zip=in.readLine();
address=new Address(street, city, state, zip);
System.out.print("Enter areaCode: ");
areaCode = Integer.parseInt(in.readLine());
System.out.print("Enter number: ");
number=Integer.parseInt(in.readLine());
phone=new Phone(areaCode, number);
entry= new Entry(name, address, phone);
entry.writeToFile(outFile);
System.out.print("Enter first name: ");
first=in.readLine();
outFile.close();
}OK. Here is how I did it.
I have AddressDr which is Address driver.
I have two files Address and Entry which in package addressBook.
AddressDr:
import java.io.*;
import addressBook.*;
public class AddressDr
public static void main(String[] args)throws IOException
Name name;
Address address;
Phone phone;
Entry entry;
String first, last, middle, street, city, state, zip;
int areaCode, number;
BufferedReader in;
in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter outFile;
outFile=new PrintWriter(new FileWriter("Entries"));
System.out.println("Quit entered fot the first name ends the " + "application.");
System.out.print("Enter first name: ");
first=in.readLine();
while (first.compareTo("Quit") !=0)
System.out.print("Enter last name: ");
last=in.readLine();
System.out.print("Enter middle name: ");
middle=in.readLine();
name=new Name(first, last, middle);
System.out.print("Enter street address: ");
street=in.readLine();
System.out.print("Enter city: ");
city=in.readLine();
System.out.print("Enter state: ");
state=in.readLine();
System.out.print("Enter ZIP code: ");
zip=in.readLine();
address=new Address(street, city, state, zip);
System.out.print("Enter areaCode: ");
areaCode = Integer.parseInt(in.readLine());
System.out.print("Enter number: ");
number=Integer.parseInt(in.readLine());
phone=new Phone(areaCode, number);
entry= new Entry(name, address, phone);
entry.writeToFile(outFile);
System.out.print("Enter first name: ");
first=in.readLine();
outFile.close();
Entry:
package addressBook;
import java.io.*;
public class Entry
Name name;
Address address;
Phone phone;
public Entry(Name newName, Address newAddress, Phone phoneNumber)
name = newName;
address = newAddress;
phone = phoneNumber;
public Name knowName()
return name;
public Address knowAddress()
return address;
public Phone knowPhone()
return phone;
public void writeToFile(PrintWriter outFile)
outFile.println(name.knowFirstName());
outFile.println(name.knowLastName());
outFile.println(name.knowMiddleName());
oufFile.println(address.knowStreet());
outFile.println(address.knowState());
outFile.println(address.knowCity());
outFile.println(address.knowZip());
outFile.println(phone.knowAreaCode());
outFile.println(phone.knowDigits());
Address:
package addressBook;
public class Address
String street;
String city;
String state;
String zipCode;
public Address(String newStreet, String newCity, String newState, String zip)
street=newStreet;
city=newCity;
state=newState;
zipCode=zip;
public String knowStreet()
return street;
public String knowCity()
return city;
public String knowState()
return state;
public String knowZip()
return zipCode;
} -
Recieving cannot resolve symbol symbol : class Serializable
I'm receiving the error:
cannot resolve symbol symbol : class Serializable
The class is as follows:
//package cscie160.hw5;
import java.io.Serializable
* @author Eddie Brodie
* @version %I%, %G%
public class AccountInfo implements Serializable
public int _accountNumber;
public int _pin;
public AccountInfo(int accountNumber, int pin)
_accountNumber = accountNumber;
_pin = pin;
I've tried importing java.*
I've also checked my classpath.
Any ideas?Try taking the import statement out of the comment block; that might help
-
Cannot resolve symbol : class odbc ERROR
Hi Helper
I am trying to compile a the following and I am getting the error
C:\jdk\websiter>javac MainServlet.java
MainServlet.java:86: cannot resolve symbol
symbol : class odbc
location: package jdbc
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;
* This is the servlet to send the user the names of all the sites present in the database
public class MainServlet extends HttpServlet implements ServletConstants
Connection m_con;
PreparedStatement m_pstmt;
ResultSet m_res;
Vector m_vecsiteName;
public void Init(ServletConfig config) throws ServletException {
super.init(config);
}// end of init()
public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
m_vecsiteName = new Vector();
try {
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
m_con = DriverManager.getConnection("jdbc:odbc:sitewd", "", "");
How can i fix it? thanks
VTReplace the Statement
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
as
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); -
Oracle jdbc drivers - cannot resolve symbol
while i'm not new to java, i am new to jdbc. need to connect a java app to an oracle database (hosted by a 3rd party). i have all the connection info. i've crafted a test program, but cannot get it to compile.
here's the code:
import java.sql.*;
public class SimpleJDBC
public static void main(String[] args) throws SQLException, ClassNotFoundException
Class.forName(oracle.jdbc.driver.OracleDriver);
System.out.println("Driver loaded");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@database.host:1521:class"); //, "username", "password");
System.out.println("Database connected");
Statement statement = conn.createStatement();
ResultSet results = statement.executeQuery("select first_name, last_name from user_tbl where last_name = 'Kendall'");
while(results.next())
System.out.println(results.getString(1) + "\t" + results.getString(2));
conn.close();
}i've set the classpath to the location of the ojdbc14.jar, and it shows in the classpath when i do a "set" on the cmd line. i've tried it in netbeans, eclipse, and straight cmd line.
i always come up with the same message (cannot resolve symbol) on the line where i call Class.forName(oracle.jdbc.driver.OracleDriver);.
i've tried compiling and setting the classpath at the same time. i added the ojdbc14.jar to the compile/build paths in both the ides. i even tried using the old classes12.jar. nothing has worked.
i can't figure out what else there is. within the ides, the intellisense will actually let me put that line in (piece by piece), but then it shows an error.
any suggestions?Place the string name of the driver in quotes.
- Saish -
IntValue - ")" expected and Cannot Resolve Symbol
I used intValue to convert an Integer to primitive (see below) and ran into syntax errors.
LogDataBean lb = new LogDataBean();
lb.setLog_time( ( String )row.get( "LOG_TIME" ) );
lb.setLog_pid( intValue( Integer )row.get( "LOG_PID" )); //where syntax error occur
lb.setLog_user( ( String )row.get( "LOG_USER" ) );the row.get( "LOG_PID" ) gets the value of the column "LOG_PID" from a database table and returns an object. Therefore, I first cast the object to Integer and then try to use the intValue to convert it to a primitive int.
But, the statement resulted in compilation error: ")" expected.
When I modified the statement a little bit by adding a pair of parenthesis:
lb.setLog_pid( intValue( ( Integer )row.get( "LOG_PID" ) ) ); //where syntax error occurI got "Cannot Resolve Symbol: intValue". I have import java.lang.Integer in the beginning of the class.Integer.parseInt(row.get( "LOG_PID" ))
I'm assuming thats what you want to. Although you syntax is terribly wrong. Have a look at some tutorials.
Maybe you are looking for
-
Include a display value in HTML footer
hi guys, I am trying to make a report and i included a HTML footer in the report for signatues ,now i have a value in the same page i want it to be included in the report besides the "rceptionest Signautre"it can be ??can i include a value from the p
-
Certain Songs Stop--Nothing Else Running--Can I Re-Download?
New to Ipod/iTunes. Most songs on my new touch downloaded via the iTunes wifi store. Have about 6 songs so far that stop playing at exact the same point each time (varies by song). The touch moves to next song in playlist unless I catch it in time an
-
Link flash text to center frame
Hello, I generated a flash text with dreamweaver. This text should be a link that opens in the center target frame. The problem is that I cannot choose the center frame as target (only self, parent, blank, top).... . What can I do to make the link op
-
[SOLVED] Pacman broken, tried reinstalling
Hey all, I just installed Arch on my system. Tried to install new packages using pacman, but I got the errors that the 'extra' and 'community' databases don't exist. I tried to check in the conf file, but couldn't see any errors. Where do I have to c
-
Tried all Mike M's Install Flash tricks for Mac and still no luck?
I admit, I am a neophyte with computers...but I can follow a script. I have tried to install Adobe Flash on Macbook Pro Osx 10.8.5 over the course of the last 5 days. I have attempted with Safari and Firefox. Now that i did the un-install, I have NO