Skip to content
Advertisement

Java error: Only a type can be imported. XYZ resolves to a package

I get the error: “Only a type can be imported. XYZ resolves to a package.”

Someone has explained the cause here but I am not sure what I supposed to do to fix this. FYI: I am using Eclipse. I have added the code that does the importing below. The java.util.* import works fine.

 <%@ page import="java.util.*"%>
 <%@ page import="org.eresearch.knowledgeportal.model.Category"%>
 <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao"%>

 <% 
  CategoryDao catDao = new CategoryDao();
  ArrayList<Category> catList = catDao.selectCategory();

 //
 %>

Edit: the actual error is below:

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

 An error occurred at line: 7 in the generated java file
 Only a type can be imported. org.eresearch.knowledgeportal.model.Category resolves to a package

Advertisement

Answer

OK I just solved it. In the last import I added a “;” by copying other code examples. I guess it’s the standard line ending that is required.

So

<%@ page import="java.util.*" %>
<%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao" %>
<%@ page import="org.eresearch.knowledgeportal.model.Category" %>

became

 <%@ page import="java.util.*" %>
 <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao" %>
 <%@ page import="org.eresearch.knowledgeportal.model.Category;" %>
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement