small program

Discussion in 'Mac Programming' started by hop666, Oct 27, 2009.

  1. macrumors newbie

    Joined:
    Oct 27, 2009
    Location:
    minsk maz
    #1
    Hi
    I want to write something in objective-c.I I wrote at the moment short something:
    Code:
    #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:

    Code:
    DOMDocument * dok1 = [[[DOMDocument alloc] URL] initWithString:&adres];
    but still the same : EXC_BAD_ACCESS
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Code:
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Oct 27, 2009
    Location:
    minsk maz
    #3
    Thanks , Kainjow

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

Share This Page