Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the trouble of openInputStream()!

 
goldfeng
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i use httpConnection to visit one file with name hello.txt, i have visited it successfully . but when I run it from the jad, there is the message of "Application error:IILegal Argument" on the screen of mobile phone . why?
Here is my code:
package testmidp;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
public class firstExample extends MIDlet {
private Display display;
String url="http://localhost/hello.txt";
//String url=this.getAppProperty("url");
/**Construct the midlet*/
public firstExample() {
display=Display.getDisplay(this);
}
/**Main method*/
public void startApp() {
try
{
this.getViaStreamConnection(url);
}
catch(IOException e)
{
System.out.println("IOException: " + e);
e.printStackTrace();
}
}
/**Handle pausing the MIDlet*/
public void pauseApp() {
}
/**Handle destroying the MIDlet*/
public void destroyApp(boolean unconditional) {
}
void getViaStreamConnection(String url) throws IOException
{
StreamConnection c=null;
InputStream s=null;
StringBuffer b=new StringBuffer();
TextBox t=null;
try
{
c=(StreamConnection)Connector.open(url);
s=c.openInputStream();
int ch;
while((ch=s.read()) != 13)
{
b.append((char)ch);
}
System.out.println(b.toString());
t=new TextBox(url,b.toString(),1024,0);
}
finally
{
if(s!=null)
s.close();
if(c!=null)
c.close();
}
display.setCurrent(t);
}
}
 
shailesh sonavadekar
Ranch Hand
Posts: 1874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
goldfeng , Welcome to javaranch.
PROPER NAMES ARE NOW REQUIRED
Please look carefully at official naming policy at javaranch & reregister yourself with proper first & last name. Please adhere to official naming policy & help maintain the decorum of the forum.
Waiting for your posts with proper first & last name. Once you have reregister , please let us know about that & then your previous account will be disabled.
Regards.

Your Friendly Bartender
Shailesh.
 
gold feng
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had found the answer. When I tested it in WhiteBoard 2.0 , It worked well. So it was the bug of Jbuilder.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic