我尝试运行documentation中捕获类中提供的演示代码来点击照片,但它给了我以下错误: -
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:1556)
at com.codename1.ui.Display.processSerialCalls(Display.java:1152)
at com.codename1.ui.Display.mainEDTLoop(Display.java:969)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
java.lang.IllegalStateException: Layout doesn't support adding with arguments: com.codename1.ui.layouts.FlowLayout
at com.codename1.ui.layouts.Layout.addLayoutComponent(Layout.java:64)
at com.codename1.ui.Container.addComponent(Container.java:557)
at com.codename1.ui.Form.addComponent(Form.java:1214)
at com.codename1.ui.Container.add(Container.java:198)
at com.mycompany.myapp.MyApplication.start(MyApplication.java:165)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.codename1.impl.javase.Executor$1$1.run(Executor.java:123)
at com.codename1.ui.Display.processSerialCalls(Display.java:1152)
at com.codename1.ui.Display.mainEDTLoop(Display.java:969)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
UTFDataFormatException总是出现在一个新的hello world程序中,并且没有影响到目前为止我编写过的任何代码的运行。但是IllegalStateException在模拟器中崩溃了应用程序。它也没有指向在我的代码中引发此异常的行。
答案 0 :(得分:1)
您安装Codename One似乎存在严重问题。这种例外永远不会发生,并表明某些重大事件已被打破。
答案 1 :(得分:0)
随着一些代码的玩法,我能够成功启动相机。以下是可能遇到类似问题的其他人的好处的运行代码: -
package com.mycompany.myapp;
import com.codename1.ui.Display;
import com.codename1.ui.FontImage;
import com.codename1.ui.Form;
import com.codename1.ui.Graphics;
import com.codename1.ui.Image;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.Style;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.capture.Capture;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import com.codename1.ui.layouts.BorderLayout;
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 Camera {
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("Rounder", new BorderLayout());
// Label picture = new Label("", "Container");
// hi.add(BorderLayout.CENTER, picture);
// hi.getUnselectedStyle().setBgColor(0xff0000);
// hi.getUnselectedStyle().setBgTransparency(255);
// Style s = UIManager.getInstance().getComponentStyle("TitleCommand");
// Image camera = FontImage.createMaterial(FontImage.MATERIAL_CAMERA, s);
// hi.getToolbar().addCommandToRightBar("", camera, (ev) -> {
// try {
// int width = Display.getInstance().getDisplayWidth();
// Image capturedImage = Image.createImage(Capture.capturePhoto(width, -1));
// Image roundMask = Image.createImage(width, capturedImage.getHeight(), 0xff000000);
// Graphics gr = roundMask.getGraphics();
// gr.setColor(0xffffff);
// gr.fillArc(0, 0, width, width, 0, 360);
// Object mask = roundMask.createMask();
// capturedImage = capturedImage.applyMask(mask);
// picture.setIcon(capturedImage);
// hi.revalidate();
// } catch(IOException err) {
// Log.e(err);
// }
// });
Form hi = new Form("Camera", new BorderLayout());
Label picture = new Label("", "Container");
hi.add(BorderLayout.CENTER,picture);
Style s = UIManager.getInstance().getComponentStyle("TitleCommand");
Image camera = FontImage.createMaterial(FontImage.MATERIAL_CAMERA, s);
hi.getToolbar().addCommandToRightBar("", camera, ev -> {
try {
Image image = Image.createImage(Capture.capturePhoto());
picture.setIcon(image);
hi.revalidate();
} catch (IOException e) {
// TODO: handle exception
Log.e(e);
}
});
hi.show();
}
public void stop() {
current = Display.getInstance().getCurrent();
if(current instanceof Dialog) {
((Dialog)current).dispose();
current = Display.getInstance().getCurrent();
}
}
public void destroy() {
}
}