对象数量 (3) 不等于键数量 (8)

发布于 2024-12-12 06:39:24 字数 1732 浏览 0 评论 0原文

好的,所以问题来自于尝试从 sqlite DB 中提取数据并将其放入数组中以进行滚动视图显示。我使用 FM 数据库库连接到 sql 数据库

代码如下:

NSMutableArray *data = [[NSMutableArray alloc] init];
FMResultSet *result = [[[StorageTank sharedStorageTank] DB] 
                                        executeQuery:@"SELECT * FROM table"];
while([result next])
{
    NSArray *values = [[NSArray alloc] initWithObjects: 
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"id"]],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"count"]],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"required"]],
                     [result stringForColumn:@"image_portrait"],
                     [result stringForColumn:@"image_landscape"],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"end_date"]],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"active"]],
                     [result stringForColumn:@"merchant"], nil];
    NSLog(@"%@", values);

    NSArray *keys = [[NSArray alloc] initWithObjects: @"id",@"count",@"required",
                     @"image_portrait",@"image_landscape",
                     @"end_date",@"active",@"merchant",nil];
     NSLog(@"%@", keys);

    NSDictionary *row = [[NSDictionary alloc] initWithObjects: values  forKeys: keys];


    [data addObject: row];
}

NSArray *resultArray = [[NSArray alloc] init];
resultArray = data;

因此,显然从我测试过的代码来看,确保值计数等于键计数...但我仍然收到此错误:

“终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“-[__NSPlaceholderDictionary initWithObjects:forKeys:]:对象数量(3)不等于键数量(8)'”

我我一生都无法理解为什么当我打印出值数组时看到 8 个值时计数会有所不同...这应该与我的 8 个键匹配?他们是正确的吗?

任何帮助/指导将不胜感激!

谢谢,

Ok, so the issue is coming from trying to pull data from a sqlite DB and place it in an array for a scroll view display. Im using FM Database library to connect to sql database

The code is as follows:

NSMutableArray *data = [[NSMutableArray alloc] init];
FMResultSet *result = [[[StorageTank sharedStorageTank] DB] 
                                        executeQuery:@"SELECT * FROM table"];
while([result next])
{
    NSArray *values = [[NSArray alloc] initWithObjects: 
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"id"]],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"count"]],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"required"]],
                     [result stringForColumn:@"image_portrait"],
                     [result stringForColumn:@"image_landscape"],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"end_date"]],
                     [[NSNumber alloc] initWithInt:[result intForColumn:@"active"]],
                     [result stringForColumn:@"merchant"], nil];
    NSLog(@"%@", values);

    NSArray *keys = [[NSArray alloc] initWithObjects: @"id",@"count",@"required",
                     @"image_portrait",@"image_landscape",
                     @"end_date",@"active",@"merchant",nil];
     NSLog(@"%@", keys);

    NSDictionary *row = [[NSDictionary alloc] initWithObjects: values  forKeys: keys];


    [data addObject: row];
}

NSArray *resultArray = [[NSArray alloc] init];
resultArray = data;

So, obviously from the code i've tested to make sure the values count is equal to the keys count... yet Im still getting this error:

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderDictionary initWithObjects:forKeys:]: number of objects (3) not equal to number of keys (8)'"

I can't understand for the life of me why the count would differ if when I print out the values array I see 8 values... which should match my 8 keys? and they are correct?

Any help/direction would be greatly appreciated!

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞花火° 2024-12-19 06:39:25

您的值数组中的第四项是:

[result stringForColumn:@"image_portrait"]

返回 nil 吗?该值告诉 -initWithObjects 列表已完成。

Is the fourth item in your values array:

[result stringForColumn:@"image_portrait"]

returning nil? That's the value that tells -initWithObjects that the list is done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文