file - Need help implementing a class into another block of code and running a class java -


OK, so I'm working on this project for which file load is required. My teacher has written this code to load the file. I am trying to figure out how to take this class and use it in the second block of code. I have browsed around the internet but I am still quite confused. And a direct example would be great.
I have a second question about how I can run this class. When my teacher runs classes and such other files are run without problems, but when I try to run them despite using the same code, I will not be allowed to run it. Import java.io.FileNotFoundException; Import java.io.file; Import java.util.Scanner; Import java.util.ArrayList; Public class AltFileLoader {Private string path; Public AltFileLoader (string file_path) {path = file_path; } Public Array List & lt; String & gt; loadFile () FileNotFoundException throws {scanner infix = new scanner (new file (path)); ArrayList & LT; String & gt; AllTheLines = new ArrayList & lt; String & gt; (); While (inFile.hasNext ()) {allTheLines.add (inFile.next ()); } InFile.close (); Return all; }}

and for my hosting code, I have

  import java.io.file; Import java.util.Scanner; Import java.util.ArrayList; Import java.io.phileNotFoundException; Import java.util.Random; Square Hellman AltFileLoader {The public string extends allTheLines; String metallithlines () {return (allthelines); } Public static zero main (string [] args) {System.out.println ("If it prints, it works!"); }}   

So basically I'm trying to implement this class file. And then I'm going to work from there. Due to not being able to drag a text document, I actually have been paused on it

and I get an error when I try to run the class

error : The main method is not found in the class AltFileLoader, please define the main method: public static void main (String [] args)

The AltFileLoader in the Constructor AltFileLoader class can not be applied to the given types; Class Helen Expands AltFileLoader {^

And this is an error when I try to apply the class to the hangman code

To use this class, you can create an example of this, which passes into a string that represents a file path of interest then when If you want the ArrayList of your strings, then call off the LoadFile () method of your AltFileLoader instance. You have to handle the filenoutfound passage (as if your instructor is in your code of the law) by holding it in any way (as shown below) or by declaring the method as a method to throw this exception. : AltFileLoader altFileLoader = New AltFileLoader (filePath); ArrayList & LT; String & gt; StringList = Null; Try {stringList = altFileLoader.loadFile (); } Hold (FileNotFoundException e) {e.printStackTrace (); }


Edit
For the question:

And it is also thinking that Why not run for me

Unfortunately we do not know. You have to show how you tried to use it, and whatever error you are getting.


Edit 2

I see another major problem: Your Hellman class is expanding the AltFileLoader and it does not needed. You should instead have an example of AltFileLoader instead of an extension instead of Usage to your code. This is inappropriate use of heritage because the Hellman itself does not take the one-by-one test for the AltFileLoader - it is not a special type of AltFileLoader.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -