NSInvalidArgumentException问题

时间:2012-01-11 02:04:58

标签: objective-c ios

在将数据提供给DBAccess类中的对象时,我遇到了NSInvalidArgumentException。

ObjectClass-> ItemShow

@interface ItemShow : NSObject 
{
NSString *itemYear;
NSInteger KMRef;
NSString *mintMark;
NSInteger rarity;
NSString *specialRemark;
NSString *mintage;
NSString *dateCode;
NSString *dateDescription;
NSString *dateComment;
NSString *masterMark;
NSInteger availability;
NSInteger quality;
}
@property(nonatomic,retain)NSString *itemYear;
@property(nonatomic)NSInteger KMRef;
@property(nonatomic)NSInteger rarity;
@property(nonatomic)NSInteger availability;
@property(nonatomic)NSInteger quality;
@property(nonatomic,retain)NSString *specialRemark;
@property(nonatomic,retain)NSString *dateComment;
@property(nonatomic,retain)NSString *mintage;
@property(nonatomic,retain)NSString *mintMark;
@property(nonatomic,retain)NSString *masterMark;
@property(nonatomic,retain)NSString *dateCode;
@property(nonatomic,retain)NSString *dateDescription;

@end

的.m

@implementation ItemShow
@synthesize     itemYear,KMRef,mintMark,rarity,specialRemark,mintage,dateCode,dateDescription,dateComment,masterMark,availability,quality;
@end

DBAccess类方法:

-(NSMutableArray*)getItem:(int)itemID
{
NSMutableArray *itemsArray=[[[NSMutableArray alloc]init]autorelease];
const char *sqlItems=sqlite3_mprintf("SELECT itm.itemYear,itm.KMRef,itm.mintmark,itm.rarity,itm.specialRemark,itm.mintage,dc.dateCode,dc.dateDescription,itm.dateComment,itm.masterMark,av.availability,av.[quality]\
                                     FROM Items as itm, DateCultures as dc, itemAvailability as av\
                                     WHERE dc.dateCultureID=itm.dateCulture AND av.itemID=itm.itemID\
                                     AND itm.itemID=%i",itemID);

sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sqlItems, -1, &statement, NULL);
if ( sqlResult== SQLITE_OK)
{
    while (sqlite3_step(statement) == SQLITE_ROW)
    {
        ItemShow *item=[[Item alloc]init];

        char *itemYear=(char *)sqlite3_column_text(statement,0);
        item.KMRef=sqlite3_column_int(statement,1);
        char *mintmark=(char *)sqlite3_column_text(statement,2);
        item.rarity=sqlite3_column_int(statement,3);
        char *specialRemark=(char*)sqlite3_column_text(statement,4);
        char *mintage=(char *)sqlite3_column_text(statement,5);
        char *dateCode=(char *)sqlite3_column_text(statement,6);
        char *dateDescription=(char *)sqlite3_column_text(statement,7);
        char *dateComment=(char *)sqlite3_column_text(statement,8);
        char *masterMark=(char *)sqlite3_column_text(statement,9);
        item.availability=sqlite3_column_int(statement,10);
        item.quality=sqlite3_column_int(statement,11);

        item.itemYear=(itemYear)?[NSString stringWithUTF8String:itemYear]:@"";
        item.mintage=(mintage)?[NSString stringWithUTF8String:mintage]:@"Unknown";
        item.mintMark=(mintmark)?[NSString stringWithUTF8String:mintmark]:@"";
        item.specialRemark=(specialRemark)?[NSString stringWithUTF8String:specialRemark]:@"";
        item.dateCode=(dateCode)?[NSString stringWithUTF8String:dateCode]:@"";
        item.dateDescription=(dateDescription)?[NSString stringWithUTF8String:dateDescription]:@"";
        item.dateComment=(dateComment)?[NSString stringWithUTF8String:dateComment]:@"";
        item.masterMark=(masterMark)?[NSString stringWithUTF8String:masterMark]:@"";

        [itemsArray addObject:item];
        [item release];
    }
    sqlite3_finalize(statement);
}
else
{
    [self dbConnectionError];
}
return itemsArray;
 }

所以,在行

item.KMRef=sqlite3_column_int(statement,1);

我得到:由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [Item setKMRef:]:无法识别的选择器发送到实例0x5c767a0'

它出了什么问题? KMRef是 int ,它是 syntesized

1 个答案:

答案 0 :(得分:1)

在提供的代码中,未显示item来自何处,是否有效?最佳猜测item不是您的想法,也不会响应setKMRef。也许itmitem应该是同一个名字?