- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已按照您的建议编辑了问题,但捕获了空指针异常。我使用 connectionRequest 而不是 multipartRequest,因为我不需要上传(只需要从 json 读取值)。我的所有代码都在下面,请看一下。
已编辑:异常
java.lang.NullPointerException
at userclasses.StateMachine$16.readResponse(StateMachine.java:1834)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:438)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:263)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
代码:
@Override
protected void beforeImgGallery(Form f) {
int iter = 0;
GridLayout gr = new GridLayout(1, 1);
Container grid = new Container(gr);
gr.setAutoFit(true);
grid.setScrollableY(true);
grid.addComponent(new InfiniteProgress());
f.addComponent(BorderLayout.CENTER, grid);
f.removeAllCommands();
f.setBackCommand(null);
createPictureCommand(grid);
}
private static boolean animating;
private Vector<Map<String, Object>> responsesgallery;
String galleryPhotoUrl;
private void createPictureCommand(final Container grid) {
ConnectionRequest mp = new ConnectionRequest(){
@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
results = p.parse(new InputStreamReader(input));
responsesgallery = (Vector<Map<String, Object>>) results.get("data");
//i've kept this for loop in postResponse but same error
for (int i = 0; i < responsesgallery.size(); i++) {
//null pointer exception in this line
final Button btn = createImageButton(i, grid, imageList.getSize());
//if i simply create a btn like below, it works
// final Button btn = new Button((URLImage.createToStorage(placeholder, token, galleryPhotoUrl, URLImage.RESIZE_SCALE_TO_FILL)));
imageList.addImageId(i);
grid.addComponent(i, btn);
Hashtable hm = (Hashtable) responsesgallery.get(i);
String galleryImgId = (String) hm.get("news_id");
galleryPhotoUrl = (String) hm.get("photo");
}
}
};
mp.setUrl("http://capitaleyedevelopment.com/~admin/traffic/api/news/getLatestNews");
NetworkManager.getInstance().addToQueueAndWait(mp);
}
ImageList imageList;
Button createImageButton(final int imageId, final Container grid, final int offset) {
final Button btn = new Button(URLImage.createToStorage(placeholder, token, galleryPhotoUrl, URLImage.RESIZE_SCALE_TO_FILL));
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
imageList.setSelectedIndex(offset);
final Container viewerParent = new Container(new LayeredLayout());
ImageViewer viewer = new ImageViewer(imageList.getItemAt(offset));
viewerParent.addComponent(viewer);
Container parent = new Container(new BorderLayout());
viewerParent.addComponent(parent);
viewer.setImageList(imageList);
grid.getParent().replace(grid, viewerParent, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 300));
Display.getInstance().getCurrent().setBackCommand(createBackCommand(viewerParent, grid));
}
});
return btn;
}
public static final String SERVER_URL = "http://capitaleyedevelopment.com/~admin/traffic/api/news/getLatestNews";
class ImageList implements ListModel<Image> {
private int selection;
private long[] imageIds;
private EncodedImage[] images;
private EventDispatcher listeners = new EventDispatcher();
public void addImageId(int id) {
long[] n = new long[imageIds.length + 1];
EncodedImage[] nImages = new EncodedImage[n.length];
System.arraycopy(imageIds, 0, n, 0, imageIds.length);
System.arraycopy(images, 0, nImages, 0, images.length);
n[imageIds.length] = id;
imageIds = n;
images = nImages;
listeners.fireDataChangeEvent(-1, DataChangedListener.ADDED);
}
public long getSelectedImageId() {
return imageIds[selection];
}
public ImageList(long[] images) {
this.imageIds = images;
this.images = new EncodedImage[images.length];
}
public Image getItemAt(final int index) {
if (images[index] == null) {
images[index] = placeholder;
Util.downloadUrlToStorageInBackground(IMAGE_URL_PREFIX + imageIds[index], "FullImage_" + imageIds[index], new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
images[index] = EncodedImage.create(Storage.getInstance().createInputStream("FullImage_" + imageIds[index]));
listeners.fireDataChangeEvent(index, DataChangedListener.CHANGED);
} catch (IOException err) {
err.printStackTrace();
}
}
});
}
return images[index];
}
public int getSize() {
return imageIds.length;
}
public int getSelectedIndex() {
return selection;
}
public void setSelectedIndex(int index) {
WebServiceProxy.getPhotoLikesAsync(imageIds[selection], new Callback<Integer>() {
public void onSucess(Integer value) {
}
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
}
});
selection = index;
}
public void addDataChangedListener(DataChangedListener l) {
listeners.addListener(l);
}
public void removeDataChangedListener(DataChangedListener l) {
listeners.removeListener(l);
}
public void addSelectionListener(SelectionListener l) {
}
public void removeSelectionListener(SelectionListener l) {
}
public void addItem(Image item) {
}
public void removeItem(int index) {
}
}
最佳答案
在Photo Share demo ( that's on github ) 我演示了一些非常相似的东西。我使用了一个自定义列表模型,该模型动态地将图像提取到 ImageViewer
。
有趣的是这个列表模型,其中图像根据需要动态下载:
class ImageList implements ListModel<Image> {
private int selection;
private long[] imageIds;
private EncodedImage[] images;
private EventDispatcher listeners = new EventDispatcher();
public void addImageId(long id) {
long[] n = new long[imageIds.length + 1];
EncodedImage[] nImages = new EncodedImage[n.length];
System.arraycopy(imageIds, 0, n, 0, imageIds.length);
System.arraycopy(images, 0, nImages, 0, images.length);
n[imageIds.length] = id;
imageIds = n;
images = nImages;
listeners.fireDataChangeEvent(-1, DataChangedListener.ADDED);
}
public long getSelectedImageId() {
return imageIds[selection];
}
public ImageList(long[] images) {
this.imageIds = images;
this.images = new EncodedImage[images.length];
}
public Image getItemAt(final int index) {
if(images[index] == null) {
images[index] = placeholder;
Util.downloadUrlToStorageInBackground(IMAGE_URL_PREFIX + imageIds[index], "FullImage_" + imageIds[index], new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
images[index] = EncodedImage.create(Storage.getInstance().createInputStream("FullImage_" + imageIds[index]));
listeners.fireDataChangeEvent(index, DataChangedListener.CHANGED);
} catch(IOException err) {
err.printStackTrace();
}
}
});
}
return images[index];
}
public int getSize() {
return imageIds.length;
}
public int getSelectedIndex() {
return selection;
}
public void setSelectedIndex(int index) {
WebServiceProxy.getPhotoLikesAsync(imageIds[selection], new Callback<Integer>() {
public void onSucess(Integer value) {
if(likeCount != null) {
likeCount.setText("" + value);
likeCount.getParent().revalidate();
}
}
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
}
});
selection = index;
}
public void addDataChangedListener(DataChangedListener l) {
listeners.addListener(l);
}
public void removeDataChangedListener(DataChangedListener l) {
listeners.removeListener(l);
}
public void addSelectionListener(SelectionListener l) {
}
public void removeSelectionListener(SelectionListener l) {
}
public void addItem(Image item) {
}
public void removeItem(int index) {
}
}
关于java - 来自 json codenameone 的 ImageViewer 图像循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34471848/
当我从购物车中删除产品时,我想刷新我的表格我尝试了所有方法但没有用,有什么办法吗? 我的 Cart 类显示了我的购物车中的产品以及当我从购物车中删除产品时我想要的位置我想刷新整个表单但不知道该怎么做我
我正在使用此代码拍摄照片 m_photoFile = Capture.capturePhoto(1920, -1); CN1 不强制使用 1920 宽度,至少在 Android 手机中是这样。因此,我
我有一个在模拟器上运行良好的应用程序。我做了一个 Android 构建并安装在设备上。现在,一些功能不起作用。我收到的调试日志包含多个此类错误 [EDT] 0:23:31,275 - Exce
谁能告诉我如何从 codenameOne 中的 .cn1 (Stoarge) 读取图像 .png 或 .jpg。 我试过两种方法都行不通: 1- img = EncodedImage.create(S
如何自动构建代号一个项目(仅限命令行)? 今天,我们需要尽可能自动化。 是否可以为 CodeName One 项目编写构建管道? 如果是,哪个 CI/CD 工具更好? 最佳答案 是和否。 Codena
android 中的 float 操作按钮是不错的选择。我希望在我的 codenameone 应用程序中使用它。我通过使用 LayeredLayout 尝试过它,有两个布局。我无法完美地实现它。按钮随
这听起来像是一个荒谬的问题,但我终究不能在 ios 上使用代号 one 创建一个目录。有人做过吗?这是我尝试的方法(一些愚蠢的测试有些不那么愚蠢,我在这里感到绝望): FileSystemStorag
我正在使用浏览器组件在我的应用程序中显示 HTML 文本。之前一切正常,但在最近的构建中,浏览器组件中显示的字体大小非常小。它在模拟器上运行良好,但在设备上看起来非常小。这是我的测试用例,并在 iPh
/image/XAUHW.png 我想为我的聊天应用实现这样的通知计数器。任何人都知道如何在 CodenameOne 中执行此操作? 谢谢。 最佳答案 看这个: Form hi = new F
如何将使用 Android SDK 构建的应用程序移植到 Codenameone?目标是移植到多个操作系统。 最佳答案 我建议查看 Codename One 网站上的 Android 踪迹 http:
如何获取 html 中代号为一的元素?比如通过 Id 获取元素并提取信息,比如获取 innerHtml 或者获取样式或 href 等。有任何实用程序吗? 最佳答案 您可以使用 XMLParser 类来
我正在尝试将 CookXml 移植到 codenameone,以便我可以使用它在 xml 中定义 UI。 CookXml 依赖于 w3c dom 和 javax 解析器。我正在寻找一种方法来用 cod
我已经构建了一个代号为一个 android 应用程序,它使用 REST 连接一个 restdb.io 数据库后端。但是,我遇到如下随机网络故障 > [EDT] 0:4:26,949 - Exc
我是 codenameone 的新手。我想使用 ASP.Net WSDL Web 服务,我必须在其中发送一个带有他的值的参数。我已经使用 ksoap 库在 android 中实现了它,但不知道如何在
在 CodenameOne 的一个版本和最新版本之间,对话框的 DialogBody 变得更大,并且在其内容下方留下过多的空间。我目前在 IntelliJ 中使用 4.4 版。这是一个例子(但我所有的
我一直在开发一个有客户列表的应用程序,我将客户显示为列表(使用容器而不是代号一中解释的列表)。从带有前导标签的列表中,我单击该项目,它会转到显示客户图片和其他信息的详细信息页面。这是我从 url (a
我为应用程序制作了一个简单的侧边菜单。第一次调用菜单时。菜单显示正常。 当我第二次重新调用菜单时,我看到一个空白屏幕。 这是我构建菜单的方式: package com.mainsys.zappeion
我正在尝试使用以下代码行更改特定容器的背景颜色: Container container = new Container(new BorderLayout()); container.getStyle
我是代号一的新手。我必须在具有特定宽度和高度的容器(流布局)中添加图像。 1:codenameone的指南说我们必须在资源文件夹中添加图像。那个资源文件夹在哪里? 2:要创建图像,我使用图像类的 cr
我有一个接受图像并将其四舍五入的函数,如下所示: public static Image roundImage(Image img) { int width = img.getWidt
我是一名优秀的程序员,十分优秀!