Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gnaz Kull
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Tony Docherty
Bartender
Posts: 2943
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic