Question

I am trying to call a Java class from an objective C, iPhone 5 application. I am using Xcode 4.5.1. At this stage, I can't even load the Virtual Machine without the following error:

Undefined symbols for architecture i386:

"_OBJC_CLASS_$_NSJavaVirtualMachine", referenced from: objc-class-ref in main.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

These are the steps I have followed,

1) In main.m:

@autoreleasepool {

      [NSJavaVirtualMachine defaultVirtualMachine]; //Added this line to load the Java VM.

        id vector=[[NSClassFromString(@"java.util.Vector") alloc] init];
        [vector add:@"one item!"];
        NSLog(@"item 1=%@",[vector get:0]);

 return 0;

}

2) I added the JavaVM.Framework by: (right click on) frameworks -> "add files to project" -> JavaVM.Framework -> (Copy Items into destination group's folder and Create Folder References... -> Click Add

(It also shows up at Build Phases -> Link Binary with Libraries)

3) In info.plist, the following properties were added:

Cocoa Java Application = Yes

Java Class Path and Java Root Directory

Both were set to the global directory where I'm storing my Java files.

I'm trying to call the add and get functions of the Java class Vector. But I can't seem to load the VM into Xcode at all! Please help.

Was it helpful?

Solution

You can't NSJavaVirtualMachine on iOS. The Cocoa/Java bindings are only available OS X and even there they are deprecated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top