gpt4 book ai didi

java - libGDX/RoboVM 项目中的 MFMailComposeViewController 生成错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:43:56 24 4
gpt4 key购买 nike

我正在尝试向现有的 iOS libGDX 应用程序添加功能(使用 RoboVM),以便当按下 scene2d.ui 按钮时,会显示 MFMailComposeViewController 弹出窗口,并附加一组预定义的 CSV 文件,这些文件存储在应用程序的 Library > 本地文件夹中。这是我到目前为止的代码:

进口和成员(member):

import org.robovm.apple.foundation.*;
import org.robovm.apple.messageui.MFMailComposeResult;
import org.robovm.apple.messageui.MFMailComposeViewController;
import org.robovm.apple.messageui.MFMailComposeViewControllerDelegate;
import org.robovm.apple.uikit.*;
import org.robovm.objc.ObjCObject;

private UIWindow mailWindow;
private UIViewController mailViewController;
private MFMailComposeViewController mailPicker;

方法:

private void createMailWindow() 
{
mailWindow = new UIWindow(UIScreen.getMainScreen().getBounds());
mailViewController = new UIViewController();
mailWindow.setRootViewController(mailViewController);
}

private void sendEmail(String fileName, String subject, String body)
{
mailPicker = new MFMailComposeViewController();
mailPicker.addStrongRef(mailWindow);
String path = NSBundle.getMainBundle().getResourcePath();

if (fileName != null)
{
path = path.substring(0, path.lastIndexOf('/')) + "/Library/local/" + fileName;
}

MFMailComposeViewControllerDelegate delegate = new MFMailComposeViewControllerDelegate()
{
public void mailComposeControllerDidFinish(MFMailComposeViewController controller, MFMailComposeResult result, NSError error)
{
controller.dismissViewController(true, null);
mailPicker.removeFromParentViewController();
mailPicker.removeStrongRef(mailWindow);
mailWindow.setHidden(true);
mailPicker = null;
}

@Override
public void didFinish(MFMailComposeViewController controller, MFMailComposeResult result, NSError error)
{

}
};

mailPicker.setMailComposeDelegate(delegate);
mailPicker.addStrongRef((ObjCObject) delegate);

if (fileName != null)
{
// attach CSVs here...
}

mailPicker.setSubject((subject != null ? subject : "Test Results"));
mailPicker.setMessageBody((body != null ? body : "Please find attached the latest results data."), false);

if (MFMailComposeViewController.canSendMail())
{
mailWindow.getRootViewController().presentViewController(mailPicker, true, null);
mailWindow.makeKeyAndVisible();
}
}
}

我已经准备好了这段代码,并且在我尝试构建之前 Eclipse 不会标记任何问题,因此我收到以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/robovm/rt/bro/NativeObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.mmu.cfa.DesktopMain.main(DesktopMain.java:26)
Caused by: java.lang.ClassNotFoundException: org.robovm.rt.bro.NativeObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 49 more

我已将 RoboVM Cocoa Touch 库和 RoboVM 运行时库添加到我的主项目的构建路径中。如果我删除这两种方法,我的项目构建不会出现错误。我还需要设置其他东西才能运行它吗?

最佳答案

问题

在 Libgdx 应用程序中,主项目由所有支持平台的项目共享

因此主项目必须包含平台无关的代码

RoboVM Cocoa Touch 库RoboVM 运行时库依赖于平台,仅适用于 iOS,不适用于桌面、android、html 等。

<小时/>

解决方案

  1. 从主项目中删除 RoboVM Cocoa Touch LibraryRoboVM Runtime Library 依赖项。
  2. 将这些依赖项添加到 RoboVM 项目中。 (如果他们还没有出现。)
  3. 创建一个界面,代表您在主项目中需要的功能。

    public interface EmailHandler {
    public void createMailWindow();
    public void sendEmail(String fileName, String subject, String body);
    }
  4. 使用您已编写的代码在 robovm 项目中创建一个实现类

    public class RobovmEmailHandler implements EmailHandler {

    @Override
    public void createMailWindow() {
    // Your code goes here.
    }

    @Override
    public void sendEmail(String fileName, String subject, String body) {
    // Your code goes here.
    }
    }
  5. EmailHandler 参数添加到 ApplicationListener(主项目中的主游戏类)的构造函数

    public class MyAwesomeGame extends Game {

    private EmailHandler emailHandler; // Use it wherever you like.

    public MyAwesomeGame(EmailHandler emailHandler) {
    this.emailHandler = emailHandler;
    // Rest of constructor.
    }
    }
  6. 提供RobovmLauncher(robovm项目的主类)中的实现参数

    public class RobovmLauncher extends IOSApplication.Delegate {

    @Override
    protected IOSApplication createApplication() {
    EmailHandler emailHandler = new RobovmEmailHandler();
    IOSApplicationConfiguration config = new IOSApplicationConfiguration();
    return new IOSApplication(new MyAwesomeGame(emailHandler), config);
    }
    }
<小时/>

注意:
其他平台的项目会开始要求您向他们提供 EmailHandler。这是自然的,也是意料之中的。您应该为您想要定位的每个平台提供特定于平台的接口(interface)实现。

希望这有帮助。
祝你好运。

关于java - libGDX/RoboVM 项目中的 MFMailComposeViewController 生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24294704/

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