• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

TextIO.java

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I'm fairly new to java and have been running into multiple issues regarding using TextIO.

Could i get some help regarding how to make it work. I have saved the code for TextIO in a new project in my eclipse IDE and tried running that and i usually end up with the following error messages:

"Error: Could not find or load main class TextIO"

"The archive: /TextIO/bin/MainPackage which is referenced by the classpath, does not exist."

"selection does not contain main type"

i really could use the help, thanks in advance.
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Could you post the code and the exact error message (with the stack trace)? Be sure to UseCodeTags (that's a link).
 
Talal Harmoush
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Knute, the error messages are exactly what i sent.

The code is that of TextIO.java and you can find it anywhere online.
 
Marshal
Posts: 3654
516
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Talal - the more details you provide, the more likely someone will want to and be able to help.

If you are referring to this TextIO.java, you will see that contains a collection of static methods for manipulating text -- it isn't runnable on its own. How are you using TextIO in your application?
 
Talal Harmoush
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, i copied and pasted the content of TextIO.java (the link you sent me is the one) into a new project in Eclipse and tried to run that.

The error messages i received are the ones mentioned in the first post.

Let me know if there is any more information i can provide.
 
Saloon Keeper
Posts: 8588
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Talal Harmoush wrote:Well, i copied and pasted the content of TextIO.java (the link you sent me is the one) into a new project in Eclipse and tried to run that.

The error messages i received are the ones mentioned in the first post.

Let me know if there is any more information i can provide.


Does the file contain a method with the signature

If not, then you can't run it. Period.
 
Talal Harmoush
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesnt contain that i think.

But how can i save the TextIO.java file so that i can use its class the same way i'd use Scanner?

 
Carey Brown
Saloon Keeper
Posts: 8588
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excerpt from http://math.hws.edu/javanotes/c2/s4.html
"To use the TextIO class, you must make sure that the class is available to your program. What this means depends on the Java programming environment that you are using. In general, you just have to add the source code file, TextIO.java, to the same directory that contains your main program. See Section 2.6 for information about how to use TextIO.

The input routines in the TextIO class are static member functions. (Static member functions were introduced in the previous section.) Let's suppose that you want your program to read an integer typed in by the user. The TextIO class contains a static member function named getlnInt that you can use for this purpose. Since this function is contained in the TextIO class, you have to refer to it in your program as TextIO.getlnInt. The function has no parameters, so a complete call to the function takes the form "TextIO.getlnInt()". This function call represents the int value typed by the user, and you have to do something with the returned value, such as assign it to a variable. For example, if userInput is a variable of type int (created with a declaration statement "int userInput;"), then you could use the assignment statement"

userInput = TextIO.getlnInt();

To call a class's static method, you specify the class name, dot (.), followed by the method name shown above.

Somewhere you must provide a class with a main() method and have that method call TextIO.getInInt(), either directly or indirectly.
 
Carey Brown
Saloon Keeper
Posts: 8588
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Talal Harmoush wrote:But how can i save the TextIO.java file so that i can use its class the same way i'd use Scanner?

I'm not understanding your problem with saving TextIO.java. You have the file "TextIO.java", right? You have a directory where all java files are being put for your project? Then copy the former into the latter. Done.
 
Carey Brown
Saloon Keeper
Posts: 8588
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TextIO does not work the same way Scanner works. With Scanner to have to create a new instance of a Scanner object and then use that instance to invoke the Scanner's methods. TextIO, on the other hand, contains nothing but static methods, therefore you don't need to instantiate an instance of TextIO, in fact, you can't.
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic