Incompatible types
Hello everyone
I've got this problem:
Int he API i read that linkedlist.get(int) returns the object located at the index of int. With that I tried to see what kind of object I was dealing with:
System.out.println(linkedlist.get(1).getClass())
It printed: class user
When I tried the following:
user tempUser = linkedlist.get(1);
The compiler said: incompatible types.
How is that posible?
Here's my code:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
//klasse
publicclass databaseimplements Serializable{
private LinkedList users =new LinkedList();
private ListIterator iterator = users.listIterator();
//Constructor
public database(){
}
publicvoid checkUser(String geefUserName, String geefPassword){
try{
ObjectInputStream in =new ObjectInputStream(new FileInputStream("database.dat"));
users=(LinkedList)in.readObject();
in.close();
user tempUser = users.get(1);//gives me incompatible types
System.out.println("Database loaded succesfull");
System.out.println(users.get(0));//nicely prints me a user.toString();
System.out.println(users.get(1).getclass());//prints class user
}
catch(Exception p){
System.out.println("Database not found");
}
for (int i = 0; i < users.size(); i++){
if (geefUserName == users.get(i).getUsername){
if (geefPassword.equals(users.get(i).getPassword)){
System.out.println("Logged in succesfully");
}
}
}
}
}
about that last piece of code, with the if-statements, the compiler said it couldnt find the methods getPassword and getUsername... Though they work when I use them on a user (i added those getters in the user class)
So my question is: How can I make a user out of a linkedlist element (which says its a user)?
Thanks in advance! Hope I was clear...

