• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to solve unchecked or unsafe operation  RSS feed

 
adam harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i solve this problem Unchecked or unsafe operations error in java compile?
this my coding
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Adam, welcome to the Ranch!

When posting code it's recommended to UseCodeTags (<- click link) to make your code nice and easy to read. I added them for you this time, looks better already.

On what line of that code does the compiler say there's a problem?
 
adam harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you TIM.. sorry i'm newbie here.. actually used CMD to compiler. i didn't know what line the problem. actually i'm beginner in java. i have a problem to understand this coding.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler will tell you what line it is. Somewhere in the error message you'll get something like DataSample.java:45 which tells you that the error is on line 45. What number do you have in your error message?
 
adam harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the original code before i repair.. the problem start line from 3, 7 and 11
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
adam harris wrote:
the problem start line from 3, 7 and 11

First thing I notice is line 3 won't compile. It should use 0.0F. Because 0.0 by itself is a double, which you can't assign to a float..
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are probably getting warnings because you are using raw types - those are generic types which you are using without specifying a type parameter.

You are for example using Vector, but you don't specify the type parameter. Instead of

you should have used:


If you're unfamiliar with generics, see Lesson: Generics in Oracle's Java Tutorials.

Another thing (which is not the cause of the compiler warnings): class Vector is a legacy collection class. You should use the newer class ArrayList instead of Vector.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Another thing (which is not the cause of the compiler warnings): class Vector is a legacy collection class. You should use the newer class ArrayList instead of Vector.


I mentioned this a while ago, and somebody (Sorry, I forgot who) corrected me that Vector is still a viable option if you need a synchronized list. I've never needed it so far though.
 
adam harris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you jesper. how can i create main class base on this code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!