+ 1

In this java code i have this error "uncked call to add(e) as a number of the raw type java.util.list". How to resolve it?

s_emps.add(new Emp("Bill", "bill@oracle.com",4000, getADate(2011,3,24,9,0) )) ;        s_emps.add(new Emp("Gary", "gary@oracle.com", 5000, getADate(2007,2,24,9,0) )) ;        s_emps.add(new Emp("Jeff", "jeff@oracle.com", 5500, getADate(2003,2,19,9,0) )) ;        s_emps.add(new Emp("Joe", "joe@oracle.com", 4000, getADate(2012,2,13,9,0) )) ;        s_emps.add(new Emp("Shay", "shay@oracle.com",6000, getADate(2002,2,21,9,0) )) ; 

16th Apr 2018, 6:42 PM
Shah Zaib
Shah Zaib - avatar
31 ответ
+ 4
Link for others: https://code.sololearn.com/cgMe0zgoB1YI Emps doesn't have properties or super to call so line 11 to 13 isn't needed.
16th Apr 2018, 9:15 PM
John Wells
John Wells - avatar
+ 3
Without all the code, no. My suggestion makes that piece compile cleanly. It is the best that can be done without all of it.
17th Apr 2018, 7:55 PM
John Wells
John Wells - avatar
+ 3
You provided the Emp class, but there isn't a main function. https://code.sololearn.com/cjmwVidYEEH0
18th Apr 2018, 3:05 AM
John Wells
John Wells - avatar
+ 2
Your array list needs to accept Emp types. Line 18 s_emps = new ArrayList<Emp>(); 
16th Apr 2018, 9:27 PM
John Wells
John Wells - avatar
+ 2
The only thing you have public is code I've seen. Where is the definition of the Emp class. You also need a main function and maybe other functions to make use of your classes.
18th Apr 2018, 2:23 AM
John Wells
John Wells - avatar
+ 1
I would assume you are adding objects of a class Emp to your list. Make sure your list declaration shows this. Say: List<Emp> s_emps = new ArrayList<Emp>();
16th Apr 2018, 6:58 PM
cyk
cyk - avatar
+ 1
ok. thanks
16th Apr 2018, 6:59 PM
Shah Zaib
Shah Zaib - avatar
+ 1
before you can add items to arraylist, you need to declare it. Example: ArrayList<String> = new ArrayList<>(); i asked you that how did you declare the s_emps arraylist? It should be declared in one of the following two ways. ArrayList<Emp> = new ArrayList<>(); or List<Emp> = new ArrayList<>();
16th Apr 2018, 7:02 PM
Yousaf
Yousaf - avatar
+ 1
Sure. You can insert a link to it in your post or you can insert it in a comment
16th Apr 2018, 7:05 PM
cyk
cyk - avatar
+ 1
I can take a look at it but where is it?
16th Apr 2018, 7:20 PM
cyk
cyk - avatar
+ 1
Did you keep getting an error after you declared the list the way we said?
16th Apr 2018, 7:24 PM
cyk
cyk - avatar
+ 1
Do you know how to use Code Playground? If your code is there it will be easier for us to look at it and help you
16th Apr 2018, 7:41 PM
cyk
cyk - avatar
+ 1
Make it public. I will be able to see it on your profile. You can make it private again later if you want
16th Apr 2018, 7:46 PM
cyk
cyk - avatar
+ 1
Saw it. I will take a look at it
16th Apr 2018, 8:12 PM
cyk
cyk - avatar
0
what errors are there can you tell me?
16th Apr 2018, 6:56 PM
Shah Zaib
Shah Zaib - avatar
0
is there anyway that I can send you my complete code?
16th Apr 2018, 7:03 PM
Shah Zaib
Shah Zaib - avatar
0
ok
16th Apr 2018, 7:05 PM
Shah Zaib
Shah Zaib - avatar
0
now can anyone rewrite my code?
16th Apr 2018, 7:19 PM
Shah Zaib
Shah Zaib - avatar
0
I shared it on my post?
16th Apr 2018, 7:22 PM
Shah Zaib
Shah Zaib - avatar
0
sorry for question mark.
16th Apr 2018, 7:22 PM
Shah Zaib
Shah Zaib - avatar