Forums Register Login

cannot resolve symbol error when a class is imported from another project

+Pie Number of slices to send: Send
I have created a Web Project. I already have a simple java project, that has a public class A.

I have included this java project in the classpath of this web project. In the welcome jsp of this project, i have imported this class through the page directive and then in the scriptlet i create an instance of this class.

When i execute the application, i get cannot resolve symbol A. What could be the problem?
+Pie Number of slices to send: Send
Can you post your JSP and error message here?
+Pie Number of slices to send: Send
This is the jsp:



The error messsage:

test_project.war\_test1.java:4: '.' expected import A; ^ An error occurred between lines: 22 and 27 in the jsp file: /test1.jsp Generated servlet error:

cannot resolve symbol symbol : class A location: class org.apache.jsp._test1 A ab = new A(); ^ An error occurred between lines: 22 and 27 in the jsp file: /test1.jsp Generated servlet error:

test_project.war\_test1.java:78: cannot resolve symbol symbol : class A location: class org.apache.jsp._test1 A ab = new A(); ^ 3 errors



Note: Class A is just a empty class in the simple java project.There are no compilation errors, and this is the runtime error.
+Pie Number of slices to send: Send
Put class A in a package and correctly import the package into the JSP.
When classes dont have an explicit package the JVM looks in the "current" directory - something you have no control over in the servlet/jsp environment.
ALL classes used in servlets/jsp should be in packages to avoid hard to understand bugs.
Bill
+Pie Number of slices to send: Send
This is a very common question here so we've written a FAQ entry for it.
See:
http://faq.javaranch.com/view?BeansNotFound
and
http://faq.javaranch.com/view?PackageYourBeans
+Pie Number of slices to send: Send
I had tested putting Class A in a package 'tutorial.databeans'(in the simple java project). And i get the same error.

What i noticed is that the class in the default package appears in the WEB-INF/classes folder of the web project, whereas i could not find the class in the package. Why could this be?
+Pie Number of slices to send: Send
 

Originally posted by geetu lalchandani:
I had tested putting Class A in a package 'tutorial.databeans'(in the simple java project). And i get the same error.

What i noticed is that the class in the default package appears in the WEB-INF/classes folder of the web project, whereas i could not find the class in the package. Why could this be?



Did you compile your class?
+Pie Number of slices to send: Send
and did you change the following:

<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="tutorial.databeans.A"
%>
+Pie Number of slices to send: Send
Please send the directory structure where your class file resides.
+Pie Number of slices to send: Send
yes , i have done both. Compiled the class and well as changed the import as.
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="tutorial.databeans.A"
%>
My cellmate was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2049 times.
Similar Threads
SecureServer error
Pass by ref- pgm err
JDBC problem in Java RMI
Please help me out with this
package javax.faces.component does not exist
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:15:09.