Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9115431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:25:51+00:00 2026-06-17T04:25:51+00:00

I have a Client Server Connection from Android to a Java Application. What I

  • 0

I have a Client Server Connection from Android to a Java Application. What I am doing is writing a ArrayList with writeObject so I can then cast it back to a ArrayList after doing readObject but I get this Exception:

01-07 11:10:08.821: E/AndroidRuntime(1314): Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
01-07 11:10:08.821: E/AndroidRuntime(1314):     at com.williamhenry.audiobolle.ConnectionToServer.getUsers(ConnectionToServer.java:127)

The Android Application tells the Server to get the Users with the Command GETUSERS

This is in MainActivity.java

adapter=new ListAdapter(this, new ConnectionToServer().execute("GETUSERS").get());

This is in the ConnectionToServer.java part where the Exception is thrown (The line where it is converted):

private ArrayList<HashMap<String, String>> getUsers()
{
ArrayList<HashMap<String, String>> usersList = new ArrayList<HashMap<String, String>>();

try {
    Socket socket = new Socket(url, 8001);
    ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
    oos.writeObject("GETUSERS");

    ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());

    usersList = (ArrayList<HashMap<String, String>>) ois.readObject();

    ois.close();
    oos.close();


} catch (UnknownHostException e) {} catch (IOException e) {} catch (ClassNotFoundException e) {}
return usersList;
}

And this is how the Server sends it to the Android Application (Client):

else if(messageArray[0].equals("GETUSERS"))
            {
                try {
                    //st.setUserFullName(messageArray[1], messageArray[2], messageArray[3]);
                    oos.writeObject(st.getUsers());
                } catch (SQLException e) {oos.writeObject("[ERROR]");}
            }

And this is the Method that is called:

public ArrayList<HashMap<String, String>> getUsers() throws SQLException
    {
        ArrayList<HashMap<String, String>> usersList = new ArrayList<HashMap<String, String>>();
        Statement statement = conn.createStatement();
        try {

            String query = "SELECT userID,username,status,fullname,lastonline FROM users";
            ResultSet resultSet = statement.executeQuery(query);
            try { 
                while (resultSet.next()) {
                    HashMap<String, String> map = new HashMap<String, String>();

                    // In Hashmap das Key und den Wert reinschreiben
                    map.put(KEY_ID, resultSet.getString("userID"));
                    map.put(KEY_USERNAME, resultSet.getString("username"));
                    map.put(KEY_STATUS, resultSet.getString("status"));
                    map.put(KEY_LASTONLINE, resultSet.getString("lastonline"));
                    map.put(KEY_THUMB_URL, resultSet.getString("thumb_url"));

                    // Hashlist in die ArrayList einfügen
                    usersList.add(map);
                }
            } finally {
                resultSet.close();
            }
        } finally {
            statement.close();
        }
        return usersList;
    }

Thank you for your help I really appreciate it 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:25:52+00:00Added an answer on June 17, 2026 at 4:25 am

    The field thumb_url is missing from the query. So resultSet.getString("thumb_url")) fails and the server send the string "[ERROR]", which cannot be deserialized as a List by the client.

    You probably can do something like :

    Object result = ois.readObject();
    if ("[ERROR]".equals(result)) {
       // something was wrong server side
       throw SomeException();
    } else {
       usersList = (ArrayList<HashMap<String, String>>) result;
    }
    

    but I think it would be even better not to catch the Exception on server side

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java program that mirrors a connection from a client server to
I have a Client program by tcp connection that send data to a server.
I have a server-side code using .NET Remoting to establish the connection with client.
I have created a server in java which accepts client connections. But I am
I have successfully implemented this from android to a java httpservlet on google app
I have an app in android which is a kind of client-server. I've established
I'm writing a client server application, but I don't receive the same bytes at
I have a problem with my android application which should connect to java tcp
I have a client on Android and server on c#. The client sends messages
I'm having trouble getting a socket connection between Android(client) and a c# app(server) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.