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...

[3382 byte] By [Qternocq_a] at [2007-10-2 10:05:44]
# 1
Did you try to cast the Object to a user like this?user tempUser = (user) users.get(1);You need a similar cast for the other places where you have "users.get(i)" I do not have J2SDK 1.5 but I believe that if you have 1.5 there is a way to do this without a cast.
atmguya at 2007-7-13 1:21:28 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
It worked! Thanks :-) Sorry im such a newbie... Dunno if the forum is for help-requests like this...
Qternocq_a at 2007-7-13 1:21:28 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
Not a problem for me.
atmguya at 2007-7-13 1:21:28 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...