Question

This must be a super overasked question. Although here goes:

I have a java file for testing around (hworld.java) and am trying to import conio.jar, a JAR which is a wrapper of Conio. The JAR contains only one class file (conio.class) and META-INF. Trying to do import conio.* or import conio.conio shows me this:

C:\Documents and Settings\Nick\Desktop>javac -cp *.jar; hworld.java
hworld.java:3: error: package conio does not exist
import conio.*;
^
1 error

And compiling it like javac -cp conio.jar hworld.java still errors out while compiling. I even extracted the jar and had conio.class in the same directory as hworld.java but to no avail. The JAR is in the same directory as hworld.java, as well.

Anyone have any idea on how to fix this?

Was it helpful?

Solution

You don't mention whether conio.class is defined in package conio. If it is not, then simply use the class without importing it. Remove the import.

OTHER TIPS

It's actually not possible. You need to put the other class in a package if you want to import it.

What's the syntax to import a class in a default package in Java?

Find out what package Conio is in - an easy way to do this is to open the jar as a zip file, the package will correspond with the folder structure of the archive. For example if Conio is in x/y/z then import x.y.z.Conio and compile/run with conio.jar on the classmate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top