Help - Search - Members - Calendar
Full Version: Couple of Java questions
Invision Power Services > Community Forums > Community Web Design and Coding
Stephen
I am working on a J2ME Messaging System using XML web services as part of my uni coursework (talk about throwing us in at the deep end getlost.gif).

There are 2 methods in the webservice listUsers and listMessages

These each return a String[] array of their items (text from the database).

First question, any idea how I would return an array of the IDs and the text from the database.

In PHP I would use array(id => text), but in Java I can't do this as you have to set the size of the array and of course the size doesn't always match up with the IDs (i.e. there might only be 3 items, but the lowest ID could be 35) so if I tried items[35] = text it would cause an error as the maximum index for the array is 3.

The second question, the array is returned from the WebService to the Client, but I need to create an array variable to assign it to. Of course I don't know the size of the array so how would I do that?
Wombat
Wrong tool for the job in this case i think. Instead of using an Array you'd probably want to use a Collection of some kind. I'd probably go for an ArrayList for this case.

Collections: http://java.sun.com/j2se/1.4.2/docs/guide/...ions/index.html
ArrayList: http://java.sun.com/j2se/1.4.2/docs/api/ja.../ArrayList.html
Stephen
Problem is that datatype isn't an XML datatype.

The only ones which can be used are

CODE
xsd:base64Binary      byte[]
xsd:boolean     boolean
xsd:byte     byte
xsd:dateTime     java.util.Calendar
xsd:decimal     java.math.BigDecimal
xsd:double     double
xsd:float     float
xsd:hexBinary     byte[]
xsd:int     int
xsd:integer     java.math.BigInteger
xsd:long     long
xsd:QName     javax.xml.namespace.QName
xsd:short     short
xsd:string     java.lang.String


Only thing I can think of is it use one of the complex data types such as a hashtable, serialise it and then return it as a string. but that seems messy
Wombat
I started looking over the Java API for XML Web Services... and I just remembered one of Java's pitfalls. Over complexity. Don't think I'm gonna be of much help on this one, without learning the JAX-WS API that is. Sorry. ermm.gif wacko.gif
Stephen
No problem. Think I might email the lecturer original.gif

On a similar note, my head is starting to hurt

Click to view attachment

blink.gif
Wombat
QUOTE(Stephen @ Apr 14 2006, 01:06 AM) *
On a similar note, my head is starting to hurt

Click to view attachment

blink.gif


NetBeans turns that into some kind of code skeleton for you... right? Otherwise... blink.gif
Stephen
yeah, thats just the flow of the forms.

Each section needs 3 dialogs; the actual form, a wait screen (this is where it actually calls the remote procedure) and a dialog to show any messages to the user.

If I knew Java well enough I'd do it by hand as netbeans is slowing my laptop down so much, but as I said we've basically been thrown in at the deep end.
Watty
As much as you've helped me over the years, I wish I could help you with this one. sad.gif The only thing I know about Java is that it's spelled J A V A.

One of these days, Stephen... one of these days. wink.gif
Wombat
QUOTE(Stephen @ Apr 14 2006, 01:35 PM) *
yeah, thats just the flow of the forms.

Each section needs 3 dialogs; the actual form, a wait screen (this is where it actually calls the remote procedure) and a dialog to show any messages to the user.

If I knew Java well enough I'd do it by hand as netbeans is slowing my laptop down so much, but as I said we've basically been thrown in at the deep end.


Yeah, NetBeans has some really nice features... it's just a shame that it's a generally dog slow Java application. sad.gif
Stephen
Suddenly had a thought. Maybe I can make each items within the array another array with 2 items, the first being the ID and the second being the text.

Might work, will have to go play around with it
Wombat
QUOTE(Stephen @ Apr 14 2006, 02:46 PM) *
Suddenly had a thought. Maybe I can make each items within the array another array with 2 items, the first being the ID and the second being the text.

Might work, will have to go play around with it


Heh, I thought that, but as far as I know an Array in Java can only hold 1 data type, so in this case, EITHER an int OR a String, but not both. sad.gif

The only solution I can see is defining your own complex type, e.g. User, and then returning an array of Users. Again, I don't know how this would all fit together with the Web Services API, but from what I've seen I think that would be the way to do it. ermm.gif
Stephen
I believe you can set the field from the database as a different datatype, i.e. by using rs.getString("id") to get the id as a string, which wouldn't be a problem because the client would just need to use parseInt then.

Going to try using a seperator first though instead, i.e. id|text and then just getting the first instance of | to split it
Stephen
That worked, the web service is working completely. Now to figure out how to build up some sort of selectable list of the data on the mobile client getlost.gif
Stephen
Thanks for your help everyone original.gif

Think I've managed to break the back of it today

Login screen
Still need to figure out why the boxes are displaying next to the labels instead of under like they should.

Wait Screen
Not really much to see there

Message list
Need to figure out why the icon is being cut up

Message options

Message view
If I created the database I'd have a field to say who sent the message so would have a reply option also, but since the database was supplied to us I can't.

Update details screen

New message
Last bit left to do, need to make the message field bigger and assign an action to the recepients field which shows a list of system users with checkboxes to select each

original.gif

QUOTE(Watty @ Apr 14 2006, 02:45 PM) *
As much as you've helped me over the years, I wish I could help you with this one. sad.gif The only thing I know about Java is that it's spelled J A V A.

One of these days, Stephen... one of these days. wink.gif


hehe, only just spotted your reply. original.gif

Thanks anyway wink.gif
_
Just a little typo, it's recipients, not recepients. wink.gif
Stephen
Yeah, spotted that after uploading the screenshots. Thanks anyway thumbsup.gif
Stephen
Just thought I'd bump to say, the work was marked today. The group got 100% for the Java work (well when I say the group, I mean me since I did it all wink.gif). Apparently we're the first group to ever finish it, the lecturer was very impressed. If I had known that I wouldn't of done so much.

Shame it is only worth 15% of the coursework mark, which is collectively only worth 30% of the module :'(
Rikki
Wow, congrats thumbsup.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.