• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to retrieve the string from textbox using Midlet to invoke the JSP

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried using thread.If a string is been assigned to a variable then the result is been got in the MIDlet. But if a text box or a text field is used then the value is not been retrieved and is not invoking the JSP.

When the Midlet runs it shows a warning like

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

Then i tried creating two classes.But still it shows the same warning.

Please help me...to solve this.

Soumya.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
To avoid the warning u should write this in a separate thread,ie,
run().The first query is not very clear tome. It seems that u want to retieve the strings in a text box or in a text field. To get the strings in a text box or in a text field, use getString().

Regards,
Debojit
 
Soumya Mathai
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried using this code :

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;

public class HttpLogger extends MIDlet {

private Display display;

private Command exitCommand =
new Command( "Exit", Command.EXIT, 1 );
private Command okCommand =
new Command( "OK", Command.OK, 1 );
private Command cancelCommand =
new Command( "Cancel", Command.CANCEL, 1 );

private URLEntry mainForm;


public HttpLogger(){
}

protected void destroyApp( boolean unconditional )
throws MIDletStateChangeException {
exitMIDlet();
}

protected void pauseApp(){
}

protected void startApp()
throws MIDletStateChangeException {
if( display == null ){
initMIDlet();
}
}

private void initMIDlet(){
display = Display.getDisplay(this);
mainForm=new URLEntry();
display.setCurrent(mainForm);
}

public void exitMIDlet(){
notifyDestroyed();
}


void displayError( Throwable e, Displayable next ){
Alert a = new Alert( "Exception" );
a.setString( e.toString() );
a.setTimeout( Alert.FOREVER );
display.setCurrent( a, next );
}

class URLEntry extends TextBox implements CommandListener {

URLEntry()
{
super("Enter URL:","localhost:8080/jsp-examples/hello.html",100,0 );
addCommand(exitCommand );
addCommand(okCommand );
setCommandListener( this );
}

public void commandAction( Command c,
Displayable d ){
if( c == exitCommand ){
exitMIDlet();
}
else if( c == okCommand ) {
try {
HttpConnection conn =(HttpConnection)Connector.open("http://"+getString());
display.setCurrent(new Logger( this, conn ) );
}
catch( IOException e ){
displayError( e, this );
}
}
}
}


class Logger extends Form
implements Runnable, CommandListener {
private Displayable next;
private HttpConnection conn;
private StringItem text =
new StringItem( null, "" );

Logger( Displayable next,
HttpConnection conn )
{
super( "HTTP Log" );

this.next = next;
this.conn = conn;

addCommand( cancelCommand );
setCommandListener( this );

append( text );

Thread t = new Thread( this );
t.start();
}

public void commandAction( Command c,
Displayable d ){
display.setCurrent( next );

try {
conn.close();
}
catch( IOException e ){
displayError( e, next );
}
}

public void run(){
update( "Connecting to " + conn.getURL() );

try {
int rc = conn.getResponseCode();
update( "Response code: " + rc );
update( "Response message: " +
conn.getResponseMessage() );

String key;

for( int i = 0;
( key =
conn.getHeaderFieldKey( i ) )
!= null;
++i ){
update( key + ": " +
conn.getHeaderField( i ) );
}
}
catch( IOException e ){
update( "Caught exception: " +
e.toString() );
}

removeCommand( cancelCommand );
addCommand( okCommand );
}

void update( String line ){
if( display.getCurrent() != this ) return;

String old = text.getText();
StringBuffer buf = new StringBuffer();

buf.append( old );
if( old.length() > 0 ){
buf.append( '\n' );
}

buf.append( line );
text.setText( buf.toString() );
}
}
}

but still it is showing the same warning as:


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

how to solve this?

Please help...,

Saumya.
 
Soumya Mathai
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me to solve the problem
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sowmya,
I hope that you are using Sun Wireless Tool Kit and so you would be facing this problem. The Best way to evade this problem..is that when ever you try to react to OK command...just span a New thread....as opposed to opening a Network Connection in the CommandAction Listener. And also rather than creating a new Inner Class make that Midlet implement Runnable and then just in the CommandListener action..just span a new thread and in the new Thread do the Networking Stuff......This is the Way I have done it..It worked for me.
For Ex


Do the coding in the Run Method...


This is what i have done.....Ranchers!!! Do tell me if I am wrong..

Thanks,
Chaitanya V
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic