Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    Web services chat application assignment emergency

    I have been tasked with writing a chat application using Java web services through NetBeans IDE. I have been given a basic chat application (server and client) to start me off and I have to add certain features to it - the two I am most concerned with are being able to specify a username and then have that username be displayed with a message when it is sent. The process I would like, as best as I can describe it, is as follows:

    The client is run and a JOptionPane with a JTextArea in it appears asking for a name which the user enters and presses ok. It is then stored on the server using the 'getText()' method in an arrayList of type String. Initially the user was just added with the arrayList and the 'id' was determined as the size of the arrayList with the element just being an empty string and the various methods (server side) - join, talk, listen, leave - given to us all involved 'id' being an integer value, but in my infinite wisdom I have changed it to be a string thanks to the username and so it is giving me problem with the following routine:

    public String listen(String id) { 
          String temp = serverList.get(id);
          return temp; 

    giving the following error messages:

    String temp = serverList.get(id);
    cannot find symbol
    symbol: method get(java.lang.string)
    location: class java.util.ArrayList<java.lang.String>

    -same as previous-

    I can see what is causing a problem because the 'set()' method takes the element at a certain position and replaces it with a certain string. How can I get around this problem and still keep my idea of using the JOptionPane to specify the username?
    If any of what I said doesn't make sense please ask me which bit needs clarification.
    Can anyone who feels like they can help me send me a private message? I am pretty desperate but at the same time I am not looking for someone to completely finish it for me, I just need someone to help me fix my problems ASAP!!!

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    Thats a problem since arrayList does not have a get or set method that allows an associative string key offset.
    You're options are as follows: cast that id to an integer with the Integer.parseInt method, or use a Map that allows you to specify a string for a key. Optionally overload that method to accept both a string and an integer, and chain the string to the integer call after casting.

    I'm not sure how much you'll be able to change though; I somehow doubt you can alter that list to a map and hope that it will work properly. The server will be expecting specific input from the client, and vice versa. While you can use trickery where desired, you cannot change expected signatures (unless you're writing both of course). If you are tracking key/value combination's and you need to work with a list, you can still use a map and cast it to a list by using the values method and casting to the desired collection.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts