gpt4 book ai didi

codenameone - 我如何在 Codename One 中通过电子邮件发送 .csv 文件?

转载 作者:行者123 更新时间:2023-12-03 18:35:50 24 4
gpt4 key购买 nike

在我的应用程序中,我通过写入 OutputStream 创建了一个包含逗号分隔数组的文件。然后我希望能够通过电子邮件共享它,以便用户可以获得数据。这是我用来创建文件的代码:

    public String getLogFile(String logName) {
String path = FileSystemStorage.getInstance().getAppHomePath() + "exp " + logName + ".csv";
Set<Long> keys;
OutputStream os = null;
try {
os = FileSystemStorage.getInstance().openOutputStream(path);
Hashtable<Long, Integer> log = (Hashtable<Long, Integer>) dataStorage
.readObject(logName);
keys = log.keySet();
for (Long key : keys) {
String outString = (key + "," + log.get(key) + "\n");
System.out.println(outString);
byte[] buffer = outString.getBytes();
os.write(buffer);
}

} catch (IOException e) {
AnalyticsService.sendCrashReport(e, "Error writing log", false);
e.printStackTrace();
} finally {
try {
os.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return path;
}

然后,我创建了一个按钮,按下该按钮时会传递要共享的文件的路径。我曾尝试使用 MIME 类型,例如“text/plain”和“text/comma-separated-values”,但这会导致错误。这是按下按钮时执行的代码。

        public void exportLog(String logName) {
String path = dataBuffer.getLogFile(logName);
EmailShare email = new EmailShare();
// email.share("Here is your log.", path, "text/plain");
email.share("Here is your log.", path, "text/comma-separated-values");
}

按下时(在模拟器中)。选择要发送到的虚拟电子邮件联系人后,我得到了这个堆栈:

java.lang.NullPointerException
at com.codename1.impl.javase.JavaSEPort.scale(JavaSEPort.java:3483)
at com.codename1.ui.Image.scale(Image.java:963)
at com.codename1.ui.Image.scaledImpl(Image.java:933)
at com.codename1.ui.Image.scaled(Image.java:898)
at com.codename1.impl.javase.JavaSEPort$60.save(JavaSEPort.java:6693)
at com.codename1.share.ShareForm.<init>(ShareForm.java:75)
at com.codename1.share.EmailShare$1$2$1.actionPerformed(EmailShare.java:102)
at com.codename1.ui.util.EventDispatcher.fireActionSync(EventDispatcher.java:455)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:358)
at com.codename1.ui.List.fireActionEvent(List.java:1532)
at com.codename1.ui.List.pointerReleasedImpl(List.java:2011)
at com.codename1.ui.List.pointerReleased(List.java:2021)
at com.codename1.ui.Form.pointerReleased(Form.java:2560)
at com.codename1.ui.Component.pointerReleased(Component.java:3108)
at com.codename1.ui.Display.handleEvent(Display.java:2017)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1065)
at com.codename1.ui.Display.mainEDTLoop(Display.java:994)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

最佳答案

EmailShare 类需要一个图像文件路径而不是任意文件作为它的第二个参数,因此加载失败。

Message 类确实更适合于此。您还可以使用不会启动 native 电子邮件应用程序的云发送选项。例如。 Log 类直接通过 Log.sendLog API 包含该功能。

关于codenameone - 我如何在 Codename One 中通过电子邮件发送 .csv 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34966366/

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