Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help in J2Me

 
nor alain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They're given you advice. I recommend you take it!
 
Peter Miklosko
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
nor alain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok,

Is there anyone can help me, please ?
 
Amila Jayatillaka
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic