View Full Version : small program

Oct 27, 2009, 02:06 PM
I want to write something in objective-c.I I wrote at the moment short something:

#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>

int main (int argc, const char * argv[]) {
// NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString * adres = @"http://www.google.pl";

DOMDocument * dok1 = [[[DOMDocument alloc] URL] initWithString:adres];

// insert code here...
NSLog(@"Hello, World!");
[dok1 release];
//[pool drain];
return 0;

The program is being compiled but in the process of action it is throwing the exception out: EXC_BAD_ACCESS, after certain (long) time can even hang the computer.Why? What am I doing badly? I've tried also like this:

DOMDocument * dok1 = [[[DOMDocument alloc] URL] initWithString:&adres];

but still the same : EXC_BAD_ACCESS

Oct 27, 2009, 03:26 PM
DOMDocument * dok1 = [[[DOMDocument alloc] URL] initWithString:adres];

This line is the problem. initWithString: isn't a method (from what I can see looking at the headers) that DOMDocument knows. Also, after alloc you're going to 99% of the time call an init method, so I'm not sure why the URL method is there.

If you're trying to get the DOMDocument object for a given URL, try using the WebView class. alloc/init an instance of that, load your URL into it, wait for it to complete (requires a run loop and a delegate), and then you can grab the DOMDocument object from its main frame.

If that doesn't make sense then you should probably learn some more Cocoa fundamentals before trying to understand this.

Oct 27, 2009, 03:57 PM
Thanks , Kainjow

I'll try the way you said and learn some more Cocoa fundamentals too.