• 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
Calling java.util.regex from Objective-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling java.util.regex from Objective-C


  • Subject: Calling java.util.regex from Objective-C
  • From: Ivan Myrvold <email@hidden>
  • Date: Thu, 12 Jun 2003 08:17:24 +0200

I am trying to access the java.util.regex classes from Objective-C.
This should work, but I don't understand why it doesn't:

Make a new Java class in PB in my Cocoa application:

// RegExpression.java
import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
import java.util.regex.*;

public class RegExpression {
public String replaceWithPattern(String originalString, String
replacementString, String thePattern) {
Pattern p = Pattern.compile(thePattern);
Matcher m = p.matcher(originalString);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
while(result) {
m.appendReplacement(sb, replacementString);
result = m.find();
}
m.appendTail(sb);
return sb.toString();
}
}

Now I am calling this method from my Objective-C class:

- (NSString *)test {
id reg = [[NSClassFromString(@"RegExpression") alloc] init]
autorelease];
NSString *str = [reg replaceWithPattern:@"alittleteststring" :@"a"
:@"s"];

return str;
}

The strange thing was that the reg variable were nil after the
NSClassFromString line. I then commented out everything but the line

Pattern p = Pattern.compile(thePattern);
in the Java class. Now I got an instance in reg. But the next line
created this error:

java.lang.NoClassDefFoundError: java/util/regex/Pattern
at RegExpression.replaceWithPattern(RegExpression.java:24)

Do anyone know why? I haven't had any such problems with the
Java-bridge before.

Ivan
_______________________________________________
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.

  • Follow-Ups:
    • Re: Calling java.util.regex from Objective-C
      • From: Chris Hanson <email@hidden>
  • Prev by Date: [OT] Mouse buttons (was Re: troubling article)
  • Next by Date: Re: [OT] Mouse buttons (was Re: troubling article)
  • Previous by thread: Re: installer application ?
  • Next by thread: Re: Calling java.util.regex from Objective-C
  • Index(es):
    • Date
    • Thread