aspose file tools*
The moose likes Java Micro Edition and the fly likes help in J2Me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "help in J2Me" Watch "help in J2Me" New topic
Author

help in J2Me

nor alain
Greenhorn

Joined: Mar 19, 2009
Posts: 11

Hi all,

I wanna help in my code ..

I wrote some code that when the user select particular category, all places under that catgeory will retreive from database and appears in the windows as a list ...

This is the code:


public Screen CategoryListAction() {

try {
int a = CategoryList.getSelectedIndex();
PlaceList = new List("Select Place", Choice.IMPLICIT);
int i = 0;
// try{
stub = new NewWebServiceService_Stub();
getBranches = stub.findAll();
getPlaces = stub.findAllX(); // getCom
getCategories = stub.findAllY(); // getCat
String __selectedString = getCategoryList().getString(getCategoryList().getSelectedIndex());
if (__selectedString != null) {
if (__selectedString.equals("Hospital")) {
try{
for (int j = 0; j < getCategories.length; j++) {
if (getCategories[i].getCateName().toLowerCase() == "Hospital".toLowerCase()) {
String ind = getCategories[i].getCateId();
for (i = 0; i < getPlaces.length; i++) {
if (getPlaces[i].getCateId() == ind) {
PlaceList.append(getPlaces[i].getPlaceName(), null);
PlaceList.addCommand(getBackCommand3());
PlaceList.addCommand(getExitCommand3());
PlaceList.addCommand(getCancelCommand4());
PlaceList.setCommandListener(this);
return PlaceList;
}
}
}
}
} catch (Exception e){
e.printStackTrace();
}
return PlaceList;
} else if (__selectedString.equals("Hotel")) {
return null;
} else if (__selectedString.equals("School")) {
return null;
} else if (__selectedString.equals("University")) {
return null;
}
}
} catch (RemoteException ex) {
ex.printStackTrace();
}
return PlaceList;
}



But, when i run the emulator, it works correctly before this step ..

The following window i appear



( The emulator here is stop working)

and this is the message that appears in the netbeans:

Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.


Can you help me, please ?[/img]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

They're given you advice. I recommend you take it!


Customer surveys are for companies who didn't pay proper attention to begin with.
Peter Miklosko
Ranch Hand

Joined: May 26, 2009
Posts: 76
Have look at BaldassareMidlet from chapter 18 of Kicking Butt with MIDP and MSA by Jonathan Knudsen for idea how to do this sort of job with Threads
nor alain
Greenhorn

Joined: Mar 19, 2009
Posts: 11
I use the thread in the code, but still have the sam problem

public Screen CategoryListAction (){
try {
int a = CategoryList.getSelectedIndex();
PlaceList = new List("Select Place", Choice.IMPLICIT);
stub = new NewWebServiceService_Stub();
getPlaces = stub.findAllX(); // getCom
getCategories = stub.findAllY(); // getCat
String __selectedString = getCategoryList().getString(getCategoryList().getSelectedIndex());
if (__selectedString != null) {
if (__selectedString.equals("Hospital")) {
new Thread(new Runnable() {
public void run() {
for (int j = 0; j < getCategories.length; j++) {
if (getCategories[j].getCateName().toLowerCase() == "Hospital".toLowerCase()) {
String ind = getCategories[j].getCateId();
for (int i = 0; i < getPlaces.length; i++) {
if (getPlaces[i].getCateId() == ind) {
PlaceList.append(getPlaces[i].getPlaceName(), null);
PlaceList.addCommand(getBackCommand3());
PlaceList.addCommand(getExitCommand3());
PlaceList.addCommand(getCancelCommand4());
// PlaceList.setCommandListener(this);
// PlaceList.setCommandListener(this);}
}
}
}
}
});
return PlaceList;
} else if (__selectedString.equals("Hotel")) {
return null;
} else if (__selectedString.equals("School")) {
return null;
} else if (__selectedString.equals("University")) {
return null; }
}
} catch (RemoteException ex) {
ex.printStackTrace(); }
return PlaceList; }
Amila Jayatillaka
Greenhorn

Joined: Sep 29, 2006
Posts: 28


Well next time when you put a code please format it well and put it inside a code tag like this ...
because it's easy to read


SCJP 1.4, SCMAD 1.0, SCWCD 5.0
nor alain
Greenhorn

Joined: Mar 19, 2009
Posts: 11
Ok,

Is there anyone can help me, please ?
Amila Jayatillaka
Greenhorn

Joined: Sep 29, 2006
Posts: 28
well i'm not that familiar with web services... but up to what this code runs.... i mean from the code given by you, is it running after line number 5
because i think there you are trying to create the connection to the web service....
So just put your connection part into a thread and see if it works....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: help in J2Me