Note that there are some explanatory texts on larger screens.

plurals
  1. POLast.fm java.lang.ClassCastException - reading in User objects from file
    primarykey
    data
    text
    <p>I would really appreciate if anyone can help me with this issue. I'm getting an error when I run this class UniqueUsersData.java</p> <pre><code>Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashSet at gettingData.UniqueUsersData.main(UniqueUsersData.java:30) </code></pre> <p>UniqueUsersData.java:</p> <pre><code>package gettingData; import java.io.BufferedInputStream; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.HashSet; import java.io.Serializable; import de.umass.lastfm.User; public class UniqueUsersData { public static void main(String[] args) throws IOException, ClassNotFoundException{ HashSet&lt;User&gt; userData = null; String fileName = "users.csv"; ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName)); try{ while(in != null ){ // keep reading if there are more lines in the file userData = (HashSet&lt;User&gt;) in.readObject(); } }catch(IOException e){ e.printStackTrace(); } String file = "usersInfo.csv"; BufferedWriter out = new BufferedWriter(new FileWriter(file, true)); for(User u: userData){ System.out.println(u.getId() + "," + u.getName() + "\n"); } out.close(); } // end main method } // end class </code></pre> <p>I have another class which gets the data using the last.fm api, stores User objects to an arraylist and then writes those objects to a file (users.csv). That all works fine, and I write to the file using an <code>ObjectOutputStream</code>.</p> <p>I've read things about the class needing to be <code>Serializable</code>, but I'm assuming that <code>de.umass.lastfm.User</code> doesn't implement it.</p> <p>Is there something I'm missing here? </p> <p>Thanks for any help! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload