• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem to line  RSS feed

 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How to resolve
Description Resource Path Location Type
InvalidFormatException cannot be resolved to a type ReadFile.java /ReadExcel_0/src line 222 Java Problem

due to line below

 
M Khalid
Ranch Hand
Posts: 57
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen wrote:Hi,
How to resolve



Could you paste the whole code snippet, so that it will be easy for analyzing the error.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is most probably because, as on previous occasions, you are not importing that exception class correctly.
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the event
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably need to add an import statement to import the class InvalidFormatException.
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact name to do the import?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have been told several times. Look at the Java® Language Specification (beware: that can be difficult to understand). Look in the Java™ Tutorials (that is the IO section; the examples should have import declarations for you to read). Look up that exception class in the J2SE API documentation, and you won't find it. In your previous threads, did you have standard API classes or POI classes which you couldn't import? You appear to have both sorts, including that same Exception, IOException and Workbook in different places. Start by reading the links you have been given, and run the program from the command line, not Eclipse. The option you showed a screenshot of does not import packages or .jars or anything. Show us how you are importing classes, whether you have a POI .jar anywhere, and how you are adding it to your CLASSPATH.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're using Apache POI, so you'd need to import this https://poi.apache.org/apidocs/org/apache/poi/openxml4j/exceptions/InvalidFormatException.html
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu,
I am using POI. What should be the name to import, as I cannot find it out per your given URL?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't look hard enough. The information you need to figure out what to import is all there. Please learn how to help yourself.
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not
import InvalidFormatException;

or

import OpenXML4JException;

what should it be?
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear, we're not trying to be difficult, we just don't like to spoon feed people here at the Ranch. You can learn how to do imports here: https://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also your other threads with this same problem: https://coderanch.com/t/669763/java/java/correct-codes
and https://coderanch.com/t/669718/java/java/FileInputStream
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen: We realize that all this stuff can be confusing for a beginner but we also think this is a very basic concept that has been explained pretty clearly in the tutorials and other links you have been given.  However, since you don't appear to understand those and assuming you did read through the material that was cited, I will give you about as close to spoonfeeding as we can get without taking the opportunity for you to do some self-help from you.

If, for example, I wanted to use the standard ArrayList, I must declare it in an import.  Looking at the API documentation for ArrayList, I see that it's in the java.util package.  There are two ways I can write the import statement here:


Now, go back to the API documentation for the class you need to import, find the package name and use one of the examples above to figure out the appropriate import statement you need to write to get rid of your compiler error.

Good luck.
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're using Apache POI, so you'd need to import this https://poi.apache.org/apidocs/org/apache/poi/openxml4j/exceptions/InvalidFormatException.html


I checked that I already had these
import java.lang.*;
import java.lang.annotation.*;
import java.lang.instrument.*;
import java.lang.invoke.*;
import java.lang.management.*;
import java.lang.ref.*;
import java.lang.reflect.*;

but why did the error happen?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen wrote:
but why did the error happen?


If you click on the link that you provided, you will see that the class is in none of the packages that you imported. You need to import the package/class mentioned in the link.

Henry
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried



which are not correct. Which should it be?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen wrote:I triedwhich are not correct. Which should it be?


Well, you did get the package correct -- but for some reason, for the class, you decided to import its superclass, and not the class in the link. Why?

Henry
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which should it be?
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the name of the class and what package is the class in?
The import statement should be something like this:
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen wrote:
I checked that I already had these
import java.lang.*;
...
(snip)


There is never any need to import classes under java.lang.
They're accessible by default.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only import classes (or their public static members) not packages.
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell/Dave,
Can you please make life easier and which name should I import?
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is:
InvalidFormatException cannot be resolved to a type

So you need to find the full package for the class InvalidFormatException and import that:
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen wrote:. . .
I checked that I already had these
import java.lang.*;
import java.lang.annotation.*;
import java.lang.instrument.*;
import java.lang.invoke.*;
import java.lang.management.*;
import java.lang.ref.*;
import java.lang.reflect.*;
. . .
Why? You are probably not using most of those imports. I have already told you to find the .jar with the invalid format exception in and find which package it is in. You have already been given a link with its package name in. You also need to add that .jar to your CLASSPATH.
 
Liutauras Vilda
Sheriff
Posts: 4930
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen wrote:...
Can you please make life easier and which name should I import?

1. The keyword for importing is

2. The class you're about to import appears in the package named

3. The exact class name you need to import is

4. Import statement as any statement in Java needs to end with semicolon

Note: combine all those 4 parts in the order I specified and it should work.
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to resolve

Description Resource Path Location Type
The import org.apache cannot be resolved ReadFile.java /ReadExcel_0/src line 2 Java Problem

due to


 
Liutauras Vilda
Sheriff
Posts: 4930
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Please stop asking those "how to resolve".
2. Better provide us with more details.
2.1. Did you download Apache POI library?
2.2. Did you add that library to your classpath?
2.3. Give us exact error message you get: copy & paste.
 
HuaMin chen
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I downloaded Apache POI and have attached relevant JAR file as library to the project. The error is shown in above.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your import line now looks correct, so if the Java compiler or your IDE is still complaining that it doesn't know what "org.apache" is, then you've most likely not added the library to your project in the correct way.
 
Liutauras Vilda
Sheriff
Posts: 4930
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HuaMin chen wrote:Yes, I downloaded Apache POI and have attached relevant JAR file as library to the project. The error is shown in above.
Do quick thing.

1. Close all projects opened in your IDE
2. Create new one
3. Add Apache POI library
4. Add same import statement you have
5. Compile
6. Tell us what happens
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!