• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Another package does not exist error

 
Ranch Hand
Posts: 49
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done my homework on this one, and it still eludes me.

For fun, I am working through Javanotes by David J. Eick.  To ease the difficulty of text input at the beginning, he provides a class called TextIO that comes as a separate file.

After referring to some posts on Stack Exchange which were mostly over my head, and the Understanding the class path and package names documentation in the Oracle docs, I was still lost.

Finally I found a YouTube video where a guy resolved the problem I was having by changing the CLASSPATH, which I did, but I am still getting the error that the TextIO class does not exist.

The TextIO class file is in the same directory as the project that I am compiling, and I am in the correct directory when I try to compile.

After reading a post here on Code Ranch, I tried changing the CLASSPATH to the directory just above the one with the files, but I got the same error.

I'm using Sublime Text for my text editor, and am trying to compile via the command line in the Terminal window of an old MacBook Pro. Java Version 14.0.1.

Also, this is the first program that I haven't been able to get to compile and run, so things should be set up correctly.







 
Ranch Hand
Posts: 40
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The TextIO class needs to be in a directory called textio and this directory should be in the same directory as PrintSquare.
 
Ken Austin
Ranch Hand
Posts: 49
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That did it. Thank you.

In the YouTube video where the guy solved the issue, both of his files were in the same folder. I never would have thought to try this.

Is that a general rule that I will need to follow from now on? All imports that aren't part of Java will need to be in their own individual folders with the folders named for the files inside them?
 
Michael Oberleitner
Ranch Hand
Posts: 40
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is that a general rule that I will need to follow from now on? All imports that aren't part of Java will need to be in their own individual folders with the folders named for the files inside them?



Definitely not. It's because of the import statement.


textio is a java package and the compiler expects the TextIO class to be located in a package called textio, otherwise it wont't find it.
Ask google for 'java package' and full qualified names.
Also PrintSquare is not in a package, which is not recommended.

For example writing


in the first line of PrintSquare would change the name of PrintSquare to abc.xyz.PrintSquare.
Then the PrintSquare needs to be located in a directory called xyz and xyz in a directory called abc and abc next to the directory/package textio.
Try around with it and you will get it!

 
Marshal
Posts: 69411
276
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ken Austin wrote:. . . resolved the problem I was having by changing the CLASSPATH . . .

That implies that there was a dependency somewhere whose the JVM needed to “know”. In many cases, setting a CLASSPATH creates more problems than it solves.

TextIO class does not exist. . . .

Where does TextIO come from? Is this a Princeton exercise?

All classes have a package structure, as MO has shown you. You can read about it in the Java™ Tutorials: 1 2. (They may also be in modules, but modules were introduced after the Java™ Tutorials were last updated.) The package structure the XYZ.class file is in must match the package name. If you declared it with...you would have to put the XYZ.class file into a directory something/com/austin/ken/resources/textio and you can use it from the something directory without writing a CLASSPATH. If you omit the packkage declaration, then you are using the unnamed package and the XYZ.class file would go in the something directory. If you put any of those Something.class files elsewhere, then you would need to decclare a CLASSPATH.
 
Ken Austin
Ranch Hand
Posts: 49
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell,

Thanks for the further explanation. That helps.

The TextIO class comes from the free online Javanotes text book by David J. Eck. I really like the book.

TextIO is designed to make input and output easier for greenhorns.

Here's the link to the book's website:

http://math.hws.edu/javanotes/index.html

 
Campbell Ritchie
Marshal
Posts: 69411
276
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure I think I have seen that book before, but not read it properly.
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic