雷老虎好:
下面是源代码,用于读取一个txt文件的第一行,单个运行时可以读出。但用JAD启动时就出现Application Error:IILegalArgument 这一句是出现在手机中,用的环境是The JBuilder MobileSet, Nokia Edition。经查出错语句是openInputStream。烦请仔细看一下,关系到我的前途问题,我会考虑加分的。谢谢!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);
}
}
下面是源代码,用于读取一个txt文件的第一行,单个运行时可以读出。但用JAD启动时就出现Application Error:IILegalArgument 这一句是出现在手机中,用的环境是The JBuilder MobileSet, Nokia Edition。经查出错语句是openInputStream。烦请仔细看一下,关系到我的前途问题,我会考虑加分的。谢谢!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);
}
}
解决方案 »
- java 接口 抽象类问题
- JAVA上个一个空指针异常
- 提供些JAVA基础实例的材料!
- 我想用这段代码显示硬盘里的一张图片,可为什么显示不了?
- 如何在java程序中取得一个给定目录下的所有文件名?
- 使用JDK编译servlet不能通过,是不是要把servlet.jar这个文件放到classpath这个环境变量中?
- 一個初學者苦苦思索,不得要領,大俠,F1、F1
- 怎样消除JTree在展开和合闭时的闪烁?(付代码)
- 一个打印的问题....各位大哥帮帮小弟....急...在线等待........
- Java用傅立叶转化FFT方法对图像处理 数组越界问题
- 如何在发送一个数据给对方的时候,获得对方IP?
- 请各位大虾出手相助!
我这里使用了InputStreamReader,InputStream是一个抽象类,而StreamConnection是接口,我怀疑会有问题。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;public class help extends MIDlet {
private Display display;
String url="http://localhost/hello.txt";
//String url=this.getAppProperty("url");
/**Construct the midlet*/
public help() {
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 myurl) throws IOException
{
InputStreamReader isr=null;
StringBuffer b=new StringBuffer();
TextBox t=null;
try
{
isr =new InputStreamReader(Connector.openInputStream(myurl));
int ch;
while((ch=isr.read()) != 13)
{
b.append((char)ch);
}
System.out.println(b.toString());
t=new TextBox(url,b.toString(),1024,0);
}
finally
{
if(isr!=null)
isr.close();
}
display.setCurrent(t);
}
MIDlet-Vendor: fengrain
MIDlet-Version: 1.0
MIDlet-Jar-Size: 4687
MIDlet-Jar-URL: connection.jar
MIDlet-1: firstExample, , testmidp.firstExample
MIDlet-2: secondExapmle, , testmidp.secondExapmle
MIDlet-3: testMidlet, , testmidp.testMidlet
url: http://localhost:8080/test/Hello.txt
按照jad的功能,作为变量的url怎么会出现在jad中呢?
我也在MIDlet suite中加了几个MIDlet,不论是放在网上用midp -install 或在本地用midp -descriptor 都没问题,在命令行、j2me wireless toolkit ]forte 2.0 ce中执行也都没问题,如果nokia的开发环境允许jad中定义变量,那么我怀疑问题在url的定义上: :8080是必须的吗?
E-mail:[email protected]