我想在 Android 上保存一个 xml 文件,然后我问了一个问题,现在我被卡住了如何获取文件;(我使用 Gluon(Netbeans 插件并且已经按照他所说的做了一切: JavaFXPorts(Gluon Plugin)在 Android 上保存文件)
你能帮我吗?我想在 Android 上保存一个 XML 文件,这是我的代码:
public static void loadConfig() throws JAXBException {
if (ConfigFile.length() != 0) {
JAXBContext jaxbContext = JAXBContext.newInstance(Info.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
info = (Info) jaxbUnmarshaller.unmarshal(ConfigFile);
} else {
info = new Info();
}
}
public static void saveConfig() {
try {
info.setAge(10);
JAXBContext context = JAXBContext.newInstance(Info.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(info, ConfigFile);
} catch (PropertyException ex) {
Logger.getLogger(STM_WU_LABOR.class.getName()).log(Level.SEVERE, null, ex);
} catch (JAXBException ex) {
Logger.getLogger(STM_WU_LABOR.class.getName()).log(Level.SEVERE, null, ex);
}
}
public File getFile() throws IOException {
File path = PlatformFactory.getPlatform().getPrivateStorage();
return new File(path, "config.xml");
}
我是这样称呼它的:
ConfigFile = getFile();
if (!ConfigFile.exists()) {
ConfigFile.createNewFile();
}
这是信息类:
package com.stm_wu_labor;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Merduma
*/
@XmlRootElement
public class Info {
Info() {
}
public Info(String gender, int age, int SchoolClass) {
this.gender = gender;
this.age = age;
this.SchoolClass = SchoolClass;
}
private String gender;
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSchoolClass() {
return SchoolClass;
}
public void setSchoolClass(int SchoolClass) {
this.SchoolClass = SchoolClass;
}
private int age;
private int SchoolClass;
}
当我尝试在 Android 上启动程序时程序停止,请帮助我
Here is adb logcat(I hope this is relevant):
I/System.out(13007): The programm started
I/System.out(13007): Succesfully started
I/System.out(13007): Info was added
W/art (13007): Unresolved exception class when finding catch block: javax.xml.bind.PropertyException
W/art (13007): Unresolved exception class when finding catch block: javax.xml.bind.JAXBException
W/System.err(13007): Exception in Application start method
I/System.out(13007): QuantumRenderer: shutdown
W/System.err(13007): java.lang.reflect.InvocationTargetException
W/System.err(13007): at java.lang.reflect.Method.invoke(Native Method)
W/System.err(13007): at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err(13007): at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:188)
W/System.err(13007): at java.lang.Thread.run(Thread.java:818)
W/System.err(13007): Caused by: java.lang.RuntimeException: Exception in Application start method
W/System.err(13007): at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
W/System.err(13007): at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$137(LauncherImpl.java:182)
W/System.err(13007): at com.sun.javafx.application.LauncherImpl.access$lambda$1(LauncherImpl.java)
W/System.err(13007): at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)
W/System.err(13007): ... 1 more
W/System.err(13007): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/bind/JAXBContext;
W/System.err(13007): at com.stm_wu_labor.STM_WU_LABOR.saveConfig(STM_WU_LABOR.java:161)
W/System.err(13007): at com.stm_wu_labor.STM_WU_LABOR.start(STM_WU_LABOR.java:65)
W/System.err(13007): at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$144(LauncherImpl.java:863)
W/System.err(13007): at com.sun.javafx.application.LauncherImpl.access$lambda$8(LauncherImpl.java)
W/System.err(13007): at com.sun.javafx.application.LauncherImpl$$Lambda$9.run(Unknown Source)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$157(PlatformImpl.java:326)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl.access$lambda$6(PlatformImpl.java)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl.lambda$null$155(PlatformImpl.java:295)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl.access$lambda$18(PlatformImpl.java)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
W/System.err(13007): at java.security.AccessController.doPrivileged(AccessController.java:52)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl.lambda$runLater$156(PlatformImpl.java:294)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl.access$lambda$5(PlatformImpl.java)
W/System.err(13007): at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)
W/System.err(13007): at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
W/System.err(13007): at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
W/System.err(13007): ... 1 more
W/System.err(13007): Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.xml.bind.JAXBContext" on path: DexPathList[[zip file "/data/app/com.stm_wu_labor-2/base.apk"],nativeLibraryDirectories=[/data/app/com.stm_wu_labor-2/lib/arm, /vendor/lib, /system/lib]]
W/System.err(13007): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err(13007): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
W/System.err(13007): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
W/System.err(13007): ... 18 more
W/System.err(13007): Suppressed: java.lang.ClassNotFoundException: javax.xml.bind.JAXBContext
W/System.err(13007): at java.lang.Class.classForName(Native Method)
W/System.err(13007): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
W/System.err(13007): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
W/System.err(13007): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
W/System.err(13007): ... 19 more
W/System.err(13007): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available