Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes IDEs, Version Control and other tools and the fly likes System.exit(1) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "System.exit(1)" Watch "System.exit(1)" New topic
Author

System.exit(1)

Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
Hi,

Up until yesterday my application had no errors but now weirdly i get an error on System.exit(1). Error says: "The method exit(int) is undefined for the type System". I have tried googling but no had much luck, you guys have any idea as to what is causing this? System.exit(1) has always worked for me but now all of sudden its stopped.

Thank You
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3179
    
  49

What I can guess here is, you might have defined your own class, variable, enum, or something like that with 'System' as the identifier name, and so java.lang.System class is hidden. Can you access System.out.println() either?


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
I have used terms such as AsdaSystem and systemBean but not specifically "System". System.out.println is not working either, it cannot be resolved is the error i get.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18916
    
  40

Mayur Gosalia wrote:System.out.println is not working either, it cannot be resolved is the error i get.


If it is not working, then Devaka's speculation is likely correct. Take a look at your file system, to see if you have a System.class file. If you have a classpath, then you need to search them as well. Also see if you have an import System in your class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
Ok i have a System.class file. I dont have an import system in my class. and i have searched the relative files and none of them have anything like system within them. When you say classpath what do you exactly mean?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18916
    
  40

Mayur Gosalia wrote:Ok i have a System.class file. I dont have an import system in my class. and i have searched the relative files and none of them have anything like system within them.



If you have a System.class file, then that is your cause. Don't worry about the import. And no need to search the rest of the class path.

You definitely have or had something that created it. So you definitely have something in your files, or the System.class file would not have been created. If you believe, that you don't anymore, then delete the System.class file and recompile.

Henry

Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
Absolute legend. that works!

Thank you very much guys!
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
Right sorry to repost in this topic. I deleted the system.class file and now system.exit(1) works. So i try to recreate my jar file and it fails with the following.

JAR creation failed. See details for additional information.
Exported with compile warnings: Java System/src/AsdaSystem.java
File not found: L:\Mayur\SHU\Final Year\Project\Program\Java System\bin\System.class.
L:\Mayur\SHU\Final Year\Project\Program\Java System\bin\System.class (The system cannot find the file specified)
Exported with compile warnings: Java System/src/systemBeans/SystemBean.java
Resource is out of sync with the file system: '/Java System/src/AsdaSystem.ldb'.

For some reason it wants that System.class or it is referring to it. I have double checked/triple checked i havent used System anywhere in the app, i dont know what causing the Jar file creation to fail like this.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

How do you try to create this JAR? And you may want to refresh your workspace, the AsdaSystem.ldb file is out-of-sync. That means that the IDE you are using has a cached version that is older than the actual file. This could perhaps even be the cause of the issue.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
Ok refreshing the workspace has solved the out of sync error. I am trying to create this jar file using the export wizard in eclipse. I managed to create it before using the same procedure but now that System.exit is working, i try to do the same and it doesnt work. I m doing following:

File - Export - Jar File. Then click next
From the src folder select the file and resources i want in jar file and tick the export generated class file resources. Then next
Then in handling problems tick both the boxes at top. click next
Then create a manifest and select main class then finish.

That worked before i deleted the System.class file, which had to be done to solve the initial problem. Error message now reads:

JAR creation failed. See details for additional information.
Exported with compile warnings: Java System/src/AsdaSystem.java
File not found: L:\Mayur\SHU\Final Year\Project\Program\Java System\bin\System.class.
L:\Mayur\SHU\Final Year\Project\Program\Java System\bin\System.class (The system cannot find the file specified)
Exported with compile warnings: Java System/src/systemBeans/SystemBean.java
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

That makes it now an Eclipse problem. I will move this thread to our IDEs forum.
Mayur Gosalia
Ranch Hand

Joined: Jan 03, 2010
Posts: 54
i have solved this. I recreated the entire workspace again and reinstall eclipse on my machine. I dont know what caused the issue but its now solved. Thank you guys
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: System.exit(1)