Where is a bug when get bundle path?

Discussion in 'iOS Programming' started by mikezang, Aug 29, 2010.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I use code as below to get path in bundle, but I got nil, I am not sure why? can you give me some suggestion?
    Code:
    -(NSString *) pathInBundle:(NSString *)fullFileName {
    	NSString *filename = [fullFileName stringByDeletingPathExtension];
    	NSString *ext = [fullFileName pathExtension];
    	NSBundle *bundle = [NSBundle mainBundle];
    	return [bundle pathForResource:filename ofType:ext];
    }
    
     

    Attached Files:

  2. donaghy macrumors member

    Joined:
    Aug 6, 2009
    #2
    try printing out your filename and extension to the console window to make sure that they are returning the expected values. At a guess maybe your extension is returning dot [extension name] instead of just [extension name]. I'm not sure if the path accepts dot [extension name], i'm sure someone will correct me on this.
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    Apply some basic debugging.

    What does it mean when NSBundle pathForResource:eek:fType: returns nil?

    1. Start with the NSBundle class reference doc:
    http://developer.apple.com/iphone/l...asses/NSBundle_Class/Reference/Reference.html

    2. Go to the section describing the method.

    3. Read what it says about the Return Value:
    Return Value
    The full pathname for the resource file or nil if the file could not be located.

    From this information, what is the next logical thing to check?

    Try confirming that there is a file with the name and extension you asked for.


    If there is such a file, then double-check the spelling of the name and extension in your code.

    Select a large font size to temporarily make the letters in your source file more obvious.

    Use screen zoom to temporarily magnify the debugger window, to temporarily make strings like database.sqliet3 more obvious.


    To enable screen zoom:
    System Preferences > Universal Access > Seeing tab
    Zoom has 2 radio buttons: On Off.
    Choose amount of Maximum Zoom using Options... button.
    Choose other options, too: smoothing, zoom follows keyboard focus, how the screen image moves, etc.
     
  4. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan

Share This Page