• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post your JSP and error message here?
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and did you change the following:

<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="tutorial.databeans.A"
%>
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please send the directory structure where your class file resides.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
%>
 
reply
    Bookmark Topic Watch Topic
  • New Topic