• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Java Bridge - Calling Java methods from Cocoa(Objective-C)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java Bridge - Calling Java methods from Cocoa(Objective-C)


  • Subject: Re: Java Bridge - Calling Java methods from Cocoa(Objective-C)
  • From: Saratchandra Kongara <email@hidden>
  • Date: Sun, 8 Dec 2002 15:27:22 -0500

Hello,
Thanks to Andreas Monitzer. I finally figured out my mistake. I was adding the keys (NSJavaNeeded, NSJavaRoot, NSJavaPath) to the wrong property list. It works now (kind of). My application hangs now after printing the response from the Java method call.
I tried selecting a few menus and clicking a few buttons but nothing happened, But I still managed to select the menu option and re-execute the method that's calling the java method again. It also crashed after few more clicks. Here is the crash log.
Any ideas? Thanks in advance.

Regards
Sarat


Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
#0 0x9068ba54 in objc_msgSend
#1 0x90132428 in CFRetain
#2 0x9016bca8 in CFRunLoopObserverInvalidate
#3 0x90148b38 in __CFRunLoopDoObservers
#4 0x90148e8c in __CFRunLoopRun
#5 0x9018157c in CFRunLoopRunSpecific
#6 0x92ba34cc in RunCurrentEventLoopInMode
#7 0x92bb326c in ReceiveNextEventCommon
#8 0x92bda280 in BlockUntilNextEventMatchingListInMode
#9 0x93082184 in _DPSNextEvent
#10 0x930ccf84 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#11 0x930ca500 in -[NSApplication run]
#12 0x930d2598 in NSApplicationMain
#13 0x00003e34 in main (main.m:13)
#14 0x00003bb8 in _start (crt.c:267)
#15 0x00003a38 in start

Thread 1:
#0 0x90074168 in mach_msg_trap
#1 0x900064b0 in mach_msg
#2 0x928ec28c in JNI_CreateJavaVM_Impl
#3 0x928ec224 in JNI_CreateJavaVM_Impl
#4 0x928a51fc in JVM_GetClassMethodsCount
#5 0x90021268 in _pthread_body

Thread 2:
#0 0x90074168 in mach_msg_trap
#1 0x900064b0 in mach_msg
#2 0x9283de9c in JVM_NewInstance
#3 0x9285eae4 in JVM_FillInStackTrace
#4 0x928647a0 in JVM_Send
#5 0x9290114c in JNI_CreateJavaVM_Impl
#6 0x928a51fc in JVM_GetClassMethodsCount
#7 0x90021268 in _pthread_body

Thread 3:
#0 0x90074168 in mach_msg_trap
#1 0x900064b0 in mach_msg
#2 0x9283ddf4 in JVM_NewInstance
#3 0x92845d80 in JVM_ArrayCopy
#4 0x9285d620 in JVM_MonitorNotify
#5 0x9285e2f8 in JVM_MonitorWait
#6 0x02102678 in 0x2102678
#7 0x0210068c in 0x210068c
#8 0x0210068c in 0x210068c
#9 0xa2843c38 in typeinfo name for std::bad_exception
#10 0x92838bdc in JVM_CurrentTimeMillis
#11 0x92878c28 in JVM_FindClassFromClass
#12 0x92892c90 in JVM_IsSameClassPackage
#13 0x9288cf70 in JVM_GetMethodIxExceptionTableEntry
#14 0x928787a0 in JVM_FindClassFromClass
#15 0x928a51fc in JVM_GetClassMethodsCount
#16 0x90021268 in _pthread_body


On Sunday, December 8, 2002, at 12:25 PM, Saratchandra Kongara wrote:

Hello,
I wrote a small java program that converts a RTF file to a HTML file. I
am trying to call the methods in this class from a Cocoa Objective-C
program.

Here is how I am integrating this in to my Cocoa (Objective-C) App.

// HTMLConversionTool.java

import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import javax.swing.text.rtf.RTFEditorKit;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.DefaultStyledDocument;

public class HTMLConversionTool {
private HTMLEditorKit htmlKit;
private DefaultStyledDocument tempRTFDoc;
private RTFEditorKit rtfKit;

public HTMLConversionTool() {
htmlKit = new HTMLEditorKit();
tempRTFDoc = new DefaultStyledDocument();
rtfKit = new RTFEditorKit();
}

public static void main (String args[]) {
HTMLConversionTool converter = new HTMLConversionTool();
}

public String echo(String input) {
return input;
}

public void convert(String inputFile, String tempFile) throws
Exception {
File file = new File(inputFile);
rtfKit.read(new BufferedReader(new InputStreamReader(new
FileInputStream(file), "ISO-8859-1")), tempRTFDoc, 0);

Writer writer = null;
writer = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(tempFile), "ISO-8859-1"));

try {
htmlKit.write(writer,tempRTFDoc,0,tempRTFDoc.getLength());
writer.flush();

} catch (Exception ex) {ex.printStackTrace();}
finally {
if (writer != null)
writer.close();
}
}

}

I added an echo method just for testing the communication between
Objective-C code and Java code using the bridge.

In one of my methods in Objective-C code I do this

id converter=[[NSClassFromString(@"HTMLConversionTool") alloc] init];
NSString *result = [converter echo:@"How are you?"];
NSLog(@"response from converter: %@ ", result);
[converter release];

I also created a HTMLCoversionTool.h file in the Cocoa Project

// HTMLConversionTool.h

#import <Foundation/Foundation.h>

@interface HTMLConversionTool : NSObject
{}
- (NSString *)echo:(NSString *)value;

@end

I added these settings in Target Settings (Settings->Expert View) in my
Cocoa App.

NSJavaNeeded = YES
NSJavaPath = HTMLConversionTool.jar
NSJavaRoot = Contents/Resources/Java

I created a new group "Java" under Resources and added the
HTMLConversionTool.jar to this group in PB using the Project->Add Files
menu option.

I also added a copy files build phase to my project and dragged the
HTMLConversionTool.jar file from the Files->Resources->Java group to
the path field. This is how my Copy Files section in Build Phases reads

Where: Resources Subpath: Java
copy only when installing is unchecked.
Files: /Users/sarat/Workspace/Java
Projects/HTMLConversionTool/build/HTMLConversionTool.jar


Output from my NSLog()
response from converter: (null)

I checked the Application package contents after the build and it does
contain the jar file in the appropriate folder. Is there a file where I
can check for these settings (NSJavaNeeded, NSJavaPath, NSJavaRoot)? I
don't see them in info.plist.

Any help is appreciated. Thanks in advance.

Regards
Sarat Kongara
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Java Bridge - Calling Java methods from Cocoa(Objective-C) (From: Saratchandra Kongara <email@hidden>)

  • Prev by Date: Re: Nib establishConnection Question
  • Next by Date: Re: rotating arrows
  • Previous by thread: Java Bridge - Calling Java methods from Cocoa(Objective-C)
  • Next by thread: rotating arrows
  • Index(es):
    • Date
    • Thread