gpt4 book ai didi

codenameone - 打开图库并显示所选图片 代号一

转载 作者:行者123 更新时间:2023-12-02 01:11:13 25 4
gpt4 key购买 nike

开发环境:

  • eclipse
  • 桌面 Windows 7
  • 模拟器 Nexus 5
  • 设备

我想打开设备的图库并显示用户选择的图像。我制作了一个按钮,一个 ActionListener 应该将我转移到设备的画廊。但是即使我省略了图库部分的打开并只添加了按钮,模拟器也会显示一个空白屏幕。此外,它在日志中给出以下异常:-

Jul 20, 2017 4:11:00 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
java.io.UTFDataFormatException: malformed input around byte 64
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at com.codename1.ui.util.Resources.loadTheme(Resources.java:1270)
at com.codename1.ui.util.Resources.openFileImpl(Resources.java:303)
at com.codename1.ui.util.Resources.openFile(Resources.java:269)
at com.codename1.ui.util.Resources.<init>(Resources.java:189)
at com.codename1.ui.util.Resources.open(Resources.java:768)
at com.codename1.ui.util.Resources.open(Resources.java:688)
at com.codename1.impl.javase.JavaSEPort$4.run(JavaSEPort.java:1720)
at com.codename1.ui.Display.processSerialCalls(Display.java:1056)
at com.codename1.ui.Display.mainEDTLoop(Display.java:873)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

以下是我在一个空的新裸骨项目上制作的主要 java 文件:-

package com.mycompany.myapp;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Image;
import com.codename1.ui.Button;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.components.ImageViewer;
import com.codename1.io.Log;
import com.codename1.media.MediaManager;
import com.codename1.ui.Toolbar;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import java.io.IOException;
/**
* This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose
* of building native mobile applications using Java.
*/
public class MyApplication {
private Form current;
private Resources theme;
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
// Enable Toolbar on all Forms by default
Toolbar.setGlobalToolbar(true);
// Pro only feature, uncomment if you have a pro subscription
// Log.bindCrashProtection(true);
}

public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Hi World");
hi.addComponent(new Label("Hi World"));
Button gallery = new Button("Browse");
hi.add(gallery);
gallery.addActionListener(new ActionListener<ActionEvent>() {
@Override
public void actionPerformed(ActionEvent evt) {
// TODO Auto-generated method stub
Display.getInstance().openGallery((e) -> {
if(e != null && e.getSource() != null) {
// String file = (String)e.getSource();
// try {
// Label path = new Label(file);
// hi.add(path);
//
// } catch(Exception err) {
// Log.e(err);
// }
}
}, Display.GALLERY_IMAGE);
}
});
}
public void stop() {
current = Display.getInstance().getCurrent();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = Display.getInstance().getCurrent();
}
}

public void destroy() {
}
}

最佳答案

看来您有几个问题。第一个是您应该在安装 JDK 时解决的首选项问题:

Resolving the problem The work around is to login as the administrator and create the key HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs

来自 Java: java.util.Preferences Failing

接下来您的资源文件似乎已损坏。很难说那里出了什么问题……它的长度是 0 吗?

查看 this article用于跟踪设计器工具问题。

在某些设备上处理来自相机的大图像需要一些时间。您可以捕获较小的图像(请参阅各种捕获方法),但我猜您只是在添加到用户界面后没有重新验证,并错误地认为这很慢。

关于codenameone - 打开图库并显示所选图片 代号一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45212864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com