Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot be resolved to a type (jsp + eclipse)

I have a jsp proyect as a presentation layer to show the result (a simple string) from a function from a java class. This class is in the src directory.

When I try to run I get this errors:

org.apache.jasper.JasperException: Unable to compile class for JSP:

and then:

parser cannot be resolved to a type

My jsp code is:

<%
        String input="ebnf a{non terminal A;}";
        Symbol tree=null;
        parser p=null;
        InputStream entrada=null;
        analex analizador;
        try{
            entrada=new ByteArrayInputStream(input.getBytes("UTF-8"));
            analizador=new analex(entrada);
            p=new parser(analizador);
            tree=p.parse();
        }catch(Exception e){
            out.println("ERROR");
        }
        finally{}
        out.println("CORRECTO");
        ConDiaCClass cdc=Singleton.getInstance();
        out.println(cdc);
%>

Actually I get the same problem with ConDiaCClass and analex classes too.

I have not created these class with Eclipse. They are from another project but they both are placed in the src directory (where the java classes are suposed to be). It seems that the jsp cannot recognize them.

like image 482
AegLos Avatar asked May 21 '12 03:05

AegLos


People also ask

What is Cannot be resolved to a type?

This means that your project isn't setup to include the JUnit libraries when it compiles; JUnit is not included in the Java runtime libraries (JRE System Library) so you have to add it to the build path.

What does Cannot be resolved to a type mean in Java?

"cannot be resolved to a type" means that the compiler has decided that, according to the syntax of the language, what it found at this place in the code has to be type, which means either a class, an interface, or a primitive tpye, but cannot find the definition of any type with that name.


2 Answers

You should add the necessary import statements at the beginning of the jsp. A sample:

<%@ page import="java.util.List" %>
<%@ page import="yourpackage.parser, yourpackage.analex" %> //and on

An advice: make your classes follow the Java Code Conventions proposed by Oracle. It is a good guide to help other people to read easily your code (it will help yourself when you want to review/improve the code).

like image 82
Luiggi Mendoza Avatar answered Nov 10 '22 04:11

Luiggi Mendoza


Clean the project,and reload the JRE as follows: Java Build Path -> Libraries -> Add Library -> JRE System Library

like image 29
Burt Avatar answered Nov 10 '22 04:11

Burt