我正在开发一个应用程序,它从服务器获取数据并解析xml并在列表视图中显示它。但问题是代码在模拟器上运行正常,但是当我在设备上安装应用程序时,它不从服务器获取数据(不连接到互联网)。
我已经使用BB键对应用程序进行了签名,因此该部分没有错误。
以下是我的一些代码..我正在使用连接到互联网 -
public XMLParser() throws SAXException, IOException{
// connect to feed's URL
String url=urlToHit;
System.out.println(url);
try {
httpConnection = (HttpConnection)Connector.open(url);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
inputStream = httpConnection.openDataInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(httpConnection.getResponseCode() == HttpConnection.HTTP_OK)
{
// check header field for a specific encoding
String desiredEncoding = "ISO-8859-1"; //iso-8859-1
String contenttype = httpConnection.getHeaderField("Content-Type");
if (contenttype != null)
{
contenttype = contenttype.toUpperCase();
if (contenttype.indexOf("UTF-8") != -1)
{
desiredEncoding = "UTF-8";
}
}
// we need an input source for the sax parser
InputSource is = new InputSource(inputStream);
// setup Encoding to match what the web server sent us
is.setEncoding(desiredEncoding);
// create the factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// create a parser
SAXParser parser = null;
try {
parser = factory.newSAXParser();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// instantiate our handler
DefaultHandler myHandler= new DefaultHandler(){
public void startElement(String uri, String localName,String element_name, Attributes attributes)throws SAXException{
if (element_name.equals("Books")){
bookCount=attributes.getValue("booksCount");
}
if (element_name.equals("Book")){
TableRowManager row = new TableRowManager();
Bitmap scaledBitmap = new Bitmap(50, 70);
Bitmap img=Bitmap.createBitmapFromBytes((getImageFromUrl(attributes.getValue("image")).getBytes()), 0,-1, 1);
img.scaleInto(scaledBitmap, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FIT);
//img=(new WebBitmapField(attributes.getValue("image"))).getBitmap();
row.add(new BitmapField(scaledBitmap));
row.add(new LabelField(attributes.getValue("title"),DrawStyle.ELLIPSIS));
//row.add(new BitmapField(attributes.getValue("image"),));
LabelField lf1=new LabelField("Author:"+attributes.getValue("author"),DrawStyle.ELLIPSIS){
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
};
row.add(lf1);
LabelField lf2=new LabelField("ISBN:"+attributes.getValue("isbn13"),DrawStyle.ELLIPSIS){
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
};
row.add(lf2);
LabelField lf3=new LabelField("year:"+attributes.getValue("year"),DrawStyle.ELLIPSIS){
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
};
row.add(lf3);
title.addElement(attributes.getValue("title"));
isbn.addElement(attributes.getValue("isbn13"));
bookImg.addElement(attributes.getValue("image"));
author.addElement(attributes.getValue("author"));
year.addElement(attributes.getValue("year"));
row.add(new BitmapField(p1));
rows.addElement(row);
}
}
public void characters(char[] ch, int start, int len) throws SAXException{
}
};
// perform the synchronous parse
parser.parse(is,myHandler);
}
}
请建议。
答案 0 :(得分:3)
使用;deviceside=true
附加网址表示您正在使用DIRECT_TCP传输。在某些无线提供商上,此传输还需要在设备上配置APN设置。请注意,APN设置通常是无线提供商特定的。
谷歌搜索您可以找到无线提供商的APN设置。例如,请检查此link。