位图图像未从URL链接显示
出于某种原因,每当我试图通过互联网显示URL中的位图图像时,我的黑莓应用程序就会崩溃 我发现与stackoverflow上的其他函数相比,位图图像未从URL链接显示,url,blackberry,bitmap,Url,Blackberry,Bitmap,出于某种原因,每当我试图通过互联网显示URL中的位图图像时,我的黑莓应用程序就会崩溃 我发现与stackoverflow上的其他函数相比,downloadImage()。其他人没有任何关于如何实现其功能的例子。我已经测试了函数downloadImage多次,但都失败了 请用代码示例进行解释。谢谢 无论如何,编译器将在此处停止: g.drawBitmap(10,y+6,50,50,imageBmp,0,0); 以下是完整的代码: 包解析包; 导入java.io.ByteArrayOutputSt
downloadImage()。其他人没有任何关于如何实现其功能的例子。我已经测试了函数downloadImage多次,但都失败了
请用代码示例进行解释。谢谢
无论如何,编译器将在此处停止:
g.drawBitmap(10,y+6,50,50,imageBmp,0,0);
以下是完整的代码:
包解析包;
导入java.io.ByteArrayOutputStream;
导入java.io.IOException;
导入java.io.InputStream;
导入java.util.Vector;
导入javax.microedition.io.Connector;
导入javax.microedition.io.HttpConnection;
导入javax.microedition.io.StreamConnection;
导入net.rim.device.api.system.Bitmap;
导入net.rim.device.api.system.DeviceInfo;
导入net.rim.device.api.system.Display;
导入net.rim.device.api.system.EncodedImage;
导入net.rim.device.api.ui.DrawStyle;
导入net.rim.device.api.ui.Field;
导入net.rim.device.api.ui.FieldChangeListener;
导入net.rim.device.api.ui.Graphics;
导入net.rim.device.api.ui.Manager;
导入net.rim.device.api.ui.ui应用程序;
导入net.rim.device.api.ui.component.BitmapField;
导入net.rim.device.api.ui.component.Dialog;
导入net.rim.device.api.ui.component.LabelField;
导入net.rim.device.api.ui.component.ListField;
导入net.rim.device.api.ui.component.ListFieldCallback;
导入net.rim.device.api.ui.container.main屏幕;
导入net.rim.device.api.ui.container.VerticalFieldManager;
导入net.rim.device.api.xml.parsers.DocumentBuilder;
导入net.rim.device.api.xml.parsers.DocumentBuilderFactory;
导入org.w3c.dom.Document;
导入org.w3c.dom.Node;
导入org.w3c.dom.NodeList;
公共类xmlparsing扩展UiApplication实现ListFieldCallback、FieldChangeListener
{
公共静态void main(字符串[]args)引发IOException
{
xmlparsing app=新的xmlparsing();
app.enterEventDispatcher();
}
公共长霉色;
连接_connectionthread;
私有静态列表字段_list;
私有静态向量列表元素=新向量();
私有静态向量listPrice=新向量();
私有静态向量listAbstract=新向量();
私有静态向量listIcon=新向量();
私有向量listInfoVector=新向量();
公共主屏幕=新主屏幕();
位图图像bmp=null;
垂直场经理主经理;
VerticalFieldManager子管理员;
UiApplication ui=UiApplication.getUiApplication();
公共xmlparsing()引发IOException
{
超级();
推屏(屏幕);
最终位图背景位图=Bitmap.getBitmapResource(“blackbackground.png”);
mainManager=新的垂直字段管理器(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR)
{
公共空间绘制(图形)
{
graphics.drawBitmap(0,0,Display.getWidth(),Display.getHeight(),backgroundBitmap,0,0);
超级油漆(图形);
}
};
subManager=新的垂直字段管理器(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR)
{
受保护的空位子布局(int-maxWidth、int-maxHeight)
{
int displayWidth=Display.getWidth();
int displayHeight=Display.getHeight();
超级子布局(显示宽度、显示高度);
setExtent(显示宽度、显示高度);
}
};
screen.add(mainManager);
_列表=新列表字段()
{
公共空间绘制(图形)
{
graphics.setColor((int)mycolor);
超级油漆(图形);
}
受保护的布尔导航单击(int状态,int时间)
{
尝试
{
//在此处导航到另一个屏幕
pushScreen(新的ResultScreen());
}
捕获(例外e)
{
System.out.println(“异常:-:navigationClick()”+e.toString());
}
返回true;
}
};
mycolor=0x00FFFFFF;
_list.invalidate();
_list.setEmptyString(“*提要不可用*”,DrawStyle.HCENTER);
_列表。设置行高(70);
_list.setCallback(this);
mainManager.add(子管理器);
listElements.removeAllElements();
listPrice.removeAllElements();
listAbstract.removeAllElements();
listIcon.removeAllElements();
_connectionthread=新连接();
_connectionthread.start();
}
私有类连接扩展线程
{
公共连接()
{
超级();
}
public void run(){
文件文件;
StreamConnection conn=null;
InputStream=null;
试试{
连接=(流连接)连接器。打开(“http://imforchange.org/international-movement-for-change/testing/data.xml“+“deviceside=true”);
DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
setIgnoringElementContentWhitespace(true);
docBuilderFactory.setCoalescing(true);
DocumentBuilder docBuilder=docBuilderFactory.newDocumentBuilder();
isValidating();
is=conn.openInputStream();
doc=docBuilder.parse(is);
doc.getDocumentElement().normalize();
NodeList list1=doc.getElementsByTagName(“事件名称”);
对于(inti=0;ipublic static String escapeHTML(String s)
{
StringBuffer sb = new StringBuffer();
int n = s.length();
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
switch (c) {
case ' ': sb.append("%20"); break;
default: sb.append(c); break;
}
}
return sb.toString();
}
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.io.IOUtilities;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
public class GetImage {
public static Bitmap connectServerForImage(String url) {
HttpConnection httpConnection = null;
DataOutputStream httpDataOutput = null;
InputStream httpInput = null;
int rc;
Bitmap bitmp = null;
try {
httpConnection = (HttpConnection) Connector.open(url);
rc = httpConnection.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
httpInput = httpConnection.openInputStream();
InputStream inp = httpInput;
byte[] b = IOUtilities.streamToBytes(inp);
EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
return hai.getBitmap();
} catch (Exception ex) {
// System.out.println("URL Bitmap Error........" + ex.getMessage());
} finally {
try {
if (httpInput != null)
httpInput.close();
if (httpDataOutput != null)
httpDataOutput.close();
if (httpConnection != null)
httpConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return bitmp;
}
}
g.drawBitmap(xpos, ypos, w, h, image, 0, 0);//pass the Bitmap reference Here