File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NetBeans - Doing a SaveAs breaks my code

 
Helend Smith
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm following a Java course using NetBeans and if I use SaveAs to make a backup of my code in case something goes wrong I find that I can then no longer run the code.

No change to the code has been made. I save the backup with a numbered suffix but stay using the original file. Yet I get reams of error codes when I try and run it after saving it.

Instead of a form reading a database as it's supposed to, I get this:

run:
java.lang.VerifyError: Constructor must call super() or this() before return in method Employees.Workers.<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)

Erm.... help?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to coderanch Helend!!

You must post your code here so others can check that and help you.
 
Helend Smith
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:Welcome to coderanch Helend!!

You must post your code here so others can check that and help you.


Ok, but there's nothing wrong with the code. One minute it worked fine. I do a SaveAs then ka-blooey! It's broken. :-(

It's from here, by the way:

http://www.homeandlearn.co.uk/java/databases_and_java_forms.html

I think I'll just go back and start this section again and this time I'll go into the directory and copy and paste to do my backups and never trust NetBeans again.

====================================================

Edit to snip. It's not the code that's at fault - see below.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly what name are you saving it as? You said you used a numeric suffix, but is that before or after the .java suffix? And exactly where are you saving it to? It could be that if you saved the file as, for example, Workers2.java in the same folder as Workers.java, that NetBeans got very confused.
 
Helend Smith
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Johnson wrote:Exactly what name are you saving it as? You said you used a numeric suffix, but is that before or after the .java suffix? And exactly where are you saving it to? It could be that if you saved the file as, for example, Workers2.java in the same folder as Workers.java, that NetBeans got very confused.


I saved "Workers.java" as "Workers - 02.java" in the same folder. When this made my code fail I tried deleting the 02 file but that didn't help.
 
Helend Smith
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think my problem is a bit simpler than the long listing I provided earlier.

I've just tried to run a smaller listing from an earlier lesson:

=========================================

package pkg05;

public class ThingsWithStrings {

public static void main(String[] args) {
String testChar=".com";
String addy="01234@someplace.com";

Boolean part=addy.endsWith(testChar);

System.out.println(part);
}
}

=================================

The output should, of course, be the Boolean "true". It ran fine while I was doing the lesson and it was still freshly typed in.
Now, in the light of my problem with SaveAs, I dig it out and try to run it I get this error:

run:
java.lang.VerifyError: Constructor must call super() or this() before return in method Employees.Workers.<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)


I normally run programs using F6 but doing that got me this error. Doing Run>Run Main Project also gets this error. Now I find that the only way to run it when I come back to it later is to go the Projects window, right click on the Package name and select Run from the context menu. Is this just NetBeans being a crap IDE or am I doing something wrong?
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you place this code in the Workers.java file? You need to make sure that the name of the file is the same as the name of the class. That's what keeps getting you into trouble. That and the fact that I think that NetBeans is trying to be helpful but instead is making things more confusing (by generating supposedly helpful code in the background). I strongly recommend that you forget about NetBeans for now, get yourself a decent text editor (Notepad++ in my favorite) and use it to do all of your editing and do all of your compiling from the command line. And only go back to NetBeans after you have mastered Java basics such a source file naming and correspondence between package names and directory names.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic