#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    28
    Rep Power
    0

    Java - problems with a program that's supposed to read a file


    Trying to run this program from Teach Yourself Java in 21 Days and not having much luck. I'm trying to compile and run it in Netbeans 7.2:

    Code:
    import java.io.*;
    
    public class ByteReader {
       public static void main(String[] arguments) {
          try {
             FileInputStream file = new
                FileInputStream("class.dat");
             boolean eof = false;
             int count = 0;
             while (!eof) {
                int input = file.read();
                System.out.print(input + " ");
                if (input == -1)
                   eof = true;
                else
                   count++;
             }
             file.close();
             System.out.println("\nBytes read: " + count);
          } catch (IOException e) {
             System.out.println("Error - " + e.toString());
          }
       }
    }
    Here's the error message I'm getting. I've got a file called "class.dat" in the same folder as the java program.

    run:
    java.lang.VerifyError: Constructor must call super() or this() before return in method ByteReader.<init>()V at offset 0
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:492)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:484)
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

    Any tips on where I'm going wrong with this? Almost complete Java noob here. Sorry! :/
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    When run on the command line (not through an IDE) it works fine. The error is confusing as you're not extending anything.

    Try to "clean" and run again. I'm not familiar with NetBeans but there has to be a way to force a recompile.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    28
    Rep Power
    0
    Stupid Netbeans!!!

IMN logo majestic logo threadwatch logo seochat tools logo