我正在尝试编写一些代码将使用Rococoa加载Cocoa IKPictureTaker小部件的java代码。我觉得我现在越来越近但我收到了一个错误,我不太确定它为什么会发生。我得到的错误是:
Exception in thread "main" java.lang.ExceptionInInitializerError
at IKPictureTakerTest.main(IKPictureTakerTest.java:39)
Caused by: java.lang.IllegalArgumentException: interface IKPictureTaker$_Class is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
at org.rococoa.Rococoa.createProxy(Rococoa.java:164)
at org.rococoa.Rococoa.wrap(Rococoa.java:118)
at org.rococoa.Rococoa.createClass(Rococoa.java:50)
at IKPictureTaker.<clinit>(IKPictureTaker.java:31)
因此,首先在这里进行交互的两个小类是IKPictureTaker类:
public interface IKPictureTaker extends NSObject
{
public static final _Class MYCLASS = Rococoa.createClass("IKPictureTaker", _Class.class);
public interface _Class extends NSClass
{
/**
* Returns a shared {@code IKPictureTaker} instance, creating it if necessary.
* @return an {@code IKPictureTaker} object.
*/
IKPictureTaker pictureTaker();
}
NSInteger runModal();
}
测试类:
public class IKPictureTakerTest extends JFrame
{
public static void main(String[] args) throws Exception
{
// You need a GUI before this will work.
new IKPictureTakerTest().setVisible(true);
NSAutoreleasePool pool = NSAutoreleasePool.new_();
QTKit instance = QTKit.instance;
// Initialize the Quartz framework.
Quartz.instance.toString();
// Display the dialog.
IKPictureTaker pictureTaker = IKPictureTaker.MYCLASS.pictureTaker();
NSInteger result = pictureTaker.runModal();
if (result.intValue() == 0) // NSCancelButton
{
System.out.println("User cancelled.");
}
else
{
assert result.intValue() == 1; // NSOKButton
System.out.println("User chose an image.");
}
pool.release();
}
}
这是我第一次在java中进行任何命令行编译,所以我认为可能是链接器错误来自于此但我不确定。谁能给我一个关于这里会发生什么的暗示?
P.S。可能很重要的是要注意,在发生此错误之前,Cocoa应用程序会弹出一个空窗口,但是没有内容。
答案 0 :(得分:1)
不确定你的一行类是什么(这是正在加载的库),但我认为这就是你的问题所在。我通过确保加载Quartz来实现它的工作:
public interface IKPictureTaker extends NSObject {
Library quartzINSTANCE = (Library) Native.loadLibrary("Quartz", Library.class);
//...
}
public class IKPictureTakerTest extends JFrame {
//...
//QTKit instance = QTKit.instance;
//Quartz.instance.toString();
//...
}