File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Why do i get errors in 6, but not 7? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why do i get errors in 6, but not 7? " Watch "Why do i get errors in 6, but not 7? " New topic
Author

Why do i get errors in 6, but not 7?

Gnaz Kull
Greenhorn

Joined: Mar 30, 2013
Posts: 6
Hi everyone. I'm coming to the end of my first year in college and have this assignment to finish by Friday. At this stage i'm quite happy with the program I wrote. However i done all the coding on my laptop and i have java 7 installed. However in the labs in college they use java 6. The program will compile and run fine both on my laptop and my friends who also has java 7. But in the labs i get errors. To me its quite strange behavior. The chance of it compiling successfully is 50/50. Sometimes its fine but others i get compile errors. Also the program will run on 6. but when i try to use any of the buttons in the GUI, errors.. I hope someone can point out why this is. Also is there anything i should change to make the program better in your opinion? Is there any better methods to something im doing?
Here is my code. I apologize if its all over the place. i tried to make it as short as possible to avoid stretching the screen too much


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Gnaz Kull wrote:i done all the coding on my laptop and i have java 7 installed. However in the labs in college they use java 6. The program will compile and run fine both on my laptop and my friends who also has java 7. But in the labs i get errors. To me its quite strange behavior.


If it compiles under 7 but not 6, then you must be using some feature that was not present in 6 but was added in 7. If you want a more specific answer than that, you'll need to TellTheDetails(←click).
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2584
    
    9

Further to what Jeff said, you can tell the compiler to compile source as v6 using the "-source" and "-target" flags. This should tell you what doesn't compile in v6.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

I use Java 6. It is showing the following compilation errors in eclipse:


The type JComboBox is not generic; it cannot be parameterized with arguments <String>


Are you having problems with the same line?




~ Mansukh
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2364
    
  50
The chance of it compiling successfully is 50/50. Sometimes its fine but others i get compile errors.

If you repeatedly compile the same code using the same compiler with the same compiler options you will always get the same result. It won't compile sometimes and not others.

but when i try to use any of the buttons in the GUI, errors..

What errors do you get? Please post the full error message and stack trace and explain what you were doing when the error occurred.

Also is there anything i should change to make the program better in your opinion?

Here's some of the things that leap out at me but this is by no means an exhaustive list:
Be consistent with your formatting - it makes the code easier to read.
Observe Java naming standards ie variable names start with a lower case letter etc?
Use a layout manger (or combination of) rather than absolute positioning of GUI components.
Don't use a common actionPerformed() method to handle events from multiple components unless the action to be performed is the same for each component.
Close streams in a finally clause and not in the body of the try clause.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18880
    
    8

Tony Docherty wrote:Close streams in a finally clause and not in the body of the try clause.


Or use Java 7's try-with-resources feature, since you're using Java 7.
Vineeth Menon
Ranch Hand

Joined: Aug 08, 2011
Posts: 71

I also noticed that you are using javax.swing.JComboBox. But before that you are using javax.swing.* . Since you are importing everything from the swing package it is not necessary to specify each and every component. Same goes to the awt.event package.


VM
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why do i get errors in 6, but not 7?