This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Problem to line

 
Ranch Hand
Posts: 62
  • 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

 
Ranch Hand
Posts: 86
2
Python Spring 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.
 
Marshal
Posts: 66237
250
  • 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
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the event
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact name to do the import?
 
Campbell Ritchie
Marshal
Posts: 66237
250
  • 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.
 
Marshal
Posts: 14377
240
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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
Ranch Hand
Posts: 62
  • 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
Marshal
Posts: 14377
240
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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
Ranch Hand
Posts: 62
  • 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
Marshal
Posts: 14377
240
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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
 
Rancher
Posts: 3524
33
  • 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
Marshal
Posts: 14377
240
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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
Ranch Hand
Posts: 62
  • 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?
 
author
Posts: 23843
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried



which are not correct. Which should it be?
 
Henry Wong
author
Posts: 23843
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which should it be?
 
Norm Radder
Rancher
Posts: 3524
33
  • 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:
 
Rancher
Posts: 4325
47
  • 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: 66237
250
  • 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
Ranch Hand
Posts: 62
  • 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
Rancher
Posts: 4325
47
  • 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: 66237
250
  • 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.
 
Marshal
Posts: 7271
492
Mac OS X VI Editor BSD Linux
  • 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
Ranch Hand
Posts: 62
  • 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
Marshal
Posts: 7271
492
Mac OS X VI Editor BSD Linux
  • 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
Ranch Hand
Posts: 62
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
Marshal
Posts: 7271
492
Mac OS X VI Editor BSD Linux
  • 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
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!