• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Die Bildungsoffensive hier im Forum geht weiter! Jetzt sollen Kreativität und technische Möglichkeiten einen neue Dimension erreichen. Das Thema in diesem Monat lautet - Verkehrte Welt - Hier geht es lang --> Klick

XML Parsing - App stürzt beim scrollen ab

BigOnkel

Jonagold
Registriert
01.06.10
Beiträge
23
Hallo,

ich habe vor kurzem angefangen mich mit XML-Parsing auseinander zu setzen.
Ich bin dabei nach folgendem Tutorial vorgegangen:
http://www.youtube.com/watch?v=5iKkbi3d35Y

Soweit klappt auch alles recht gut, das Problem ist allerdings, dass
sobald ich mehr als 10 Einträge habe und ich somit im TableView srcollen muss,
stürtzt die App plötzlich ab, die Console sagt mir dann folgendes:

Code:
[Session started at 2010-06-05 19:33:15 +0200.]
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 44156.
(gdb)

Ich hoffe jemand kann mit weiterhelfen.

Gruß
BigOnkel
 
Hallo,

diese Ausgabe ist da leider nicht sehr hilfreich. Das steht normal bei jeder Anwendung die Ausgeführt wird in der Console. Das sind ein paar Infos über den Compiler + die Process-Id des Programms.

Dein Code wäre hilfreich.

Gruß

Sascha
 
XMLController.m
Code:
//
//  XMLController.m
//  XMLParser
//
//  Created by -- on 03.06.10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "XMLController.h"
#import "data.h"


@implementation XMLController
@synthesize datas;

-(id)loadXMLByURL:(NSString *)urlString {
	datas = [[NSMutableArray alloc] init];
	NSURL *url = [NSURL URLWithString:urlString];
	parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
	[parser setDelegate:self];
	[parser parse];
	return self;
}

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict 
{
		if([elementName isEqualToString:@"eintrag"])
		{
			currentData = [data alloc];
			currentContent = [[NSMutableArray alloc] init];
		}
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
	if([elementName isEqualToString:@"from"])
		currentData.from = currentContent;
	if([elementName isEqualToString:@"content"])
		currentData.content = currentContent;
	if([elementName isEqualToString:@"eintrag"])
	{
		[datas addObject:currentData];
		[currentData release];
		currentData = nil;
		[currentContent release];
		currentContent = nil;
	}
}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
	currentContent = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
@end

RootViewController.m
Code:
//
//  RootViewController.m
//  XMLParser
//
//  Created by -- on 03.06.10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "RootViewController.h"
#import "data.h"
#import "detailView.h"

@implementation RootViewController
@synthesize xmlCont;


- (void)viewDidLoad {
	
	xmlCont = [[XMLController alloc] loadXMLByURL:@"<URL>"];
	for(data *d in [xmlCont datas]) {
		//NSLog(@"Autor: %@ hat geschrieben: %@",d.from,d.content);
	}
	
	[self setTitle:@"XMLParser"];
	[self.tableView reloadData];
	
    [super viewDidLoad];

    //Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    //self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release anything that can be recreated in viewDidLoad or on demand.
	// e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSMutableArray *ar = [xmlCont datas];
	return [ar count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	NSMutableArray *cont = [xmlCont datas];
	data *current = [cont objectAtIndex:indexPath.row];
	
	cell.detailTextLabel.text = [current from];
	cell.textLabel.text = [current content];

    return cell;
}

// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

	NSMutableArray *cont = [xmlCont datas];
	data *current = [cont objectAtIndex:indexPath.row];
	detailView *det = [[detailView alloc] init];
	//detailTable *det = [[detailTable alloc] initWithNibName:@"detailTable" bundle:nil];
	[det initWithData:current];
	[self.navigationController pushViewController:det animated:YES];
	[det release];
	
    // Navigation logic may go here -- for example, create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
	// [self.navigationController pushViewController:anotherViewController animated:YES];
	// [anotherViewController release];
}

- (void)dealloc {
    [super dealloc];
}


@end

ich geh mal davon aus, dass die .h Dateien irrelevant sind, da sie ja keinen wirklichen Code enthalten ;)
 
Achja, was ich noch vergessen hab, führe mal bitte das Programm im Debug-Modus aus. Da müsstest du auf der Konsole mehr Informationen erhalten, wenn das Programm abstürzt.

Gruß

Sascha
 
also im Debug-Modus bekomm ich in der Console folgende Meldung:
Program received signal: “EXC_BAD_ACCESS”.

und der Debugger spuckt Assembler-Code aus und 2 Codestellen:

#2:
Code:
cell.textLabel.text = current.content;

und am Schluss #18:

Code:
int retVal = UIApplicationMain(argc, argv, nil, nil);

Thread-1:

Code:
#0	0x97fb6ed7 in objc_msgSend
#1	0x00398c43 in -[UILabel setText:]
#2	0x00002172 in -[RootViewController tableView:cellForRowAtIndexPath:] at RootViewController.m:105
#3	0x002e1e60 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
#4	0x002d9a97 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]
#5	0x002ec5a3 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow]
#6	0x002e3953 in -[UITableView layoutSubviews]
#7	0x035322b0 in -[CALayer layoutSublayers]
#8	0x0353206f in CALayerLayoutIfNeeded
#9	0x035318c6 in CA::Context::commit_transaction
#10	0x0353153a in CA::Transaction::commit
#11	0x03539838 in CA::Transaction::observer_callback
#12	0x01bb5252 in __CFRunLoopDoObservers
#13	0x01bb465f in CFRunLoopRunSpecific
#14	0x01bb3c48 in CFRunLoopRunInMode
#15	0x023a078d in GSEventRunModal
#16	0x023a0852 in GSEventRun
#17	0x0029d003 in UIApplicationMain
#18	0x00001d2c in main at main.m:14
 
Spuck mal noch data.h und data.m aus. Der Fehler muss fast dort irgendwo liegen, falls ich da vom Handy alles gesehen habe :-)

Gruss ppocket

Sent from my HTC Desire using Tapatalk
 
data.h
Code:
//
//  data.h
//  XMLParser
//
//  Created by --- on 03.06.10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface data : NSObject {
	
	NSString *content;
	NSString *from;

}
@property(nonatomic,retain)NSString *content;
@property(nonatomic,retain)NSString *from;

@end

data.m
Code:
//
//  data.m
//  XMLParser
//
//  Created by --- on 03.06.10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "data.h"


@implementation data
@synthesize content,from;

@end

is eigentlich kein großartiger code dabei
 
Spuck mal noch data.h und data.m aus. Der Fehler muss fast dort irgendwo liegen, falls ich da vom Handy alles gesehen habe :-)

Gruss ppocket

Sent from my HTC Desire using Tapatalk

Würde ich auch behaupten und ich hab am Computer geschaut. ;-)

Gruß

Sascha
 
hmm, also wenn ich statisch nur eine Reihe festlege und diese dann statisch mit datensatz 15 oder so, also über 10, fülle, gibts keine probleme mit der Anzeige.
 
Kontrollier mal bitte, ob im data-Object, der content befüllt ist.

Gruß

Sascha
 
also content is da, ohne fehler. Was mir allerdings aufgefallen ist, unmittelbar nach dem Ausführen der App im Simulator erhalte ich mehrere Fehlerzeilen in der Console:

Code:
XMLParser2(47968,0xa0ac14e0) malloc: *** error for object 0x382fea0: double free
*** set a breakpoint in malloc_error_break to debug
XMLParser2(47968,0xa0ac14e0) malloc: *** error for object 0x382fc70: double free
*** set a breakpoint in malloc_error_break to debug
XMLParser2(47968,0xa0ac14e0) malloc: *** error for object 0x382fa90: double free
*** set a breakpoint in malloc_error_break to debug
XMLParser2(47968,0xa0ac14e0) malloc: *** error for object 0x382f8b0: double free
*** set a breakpoint in malloc_error_break to debug
XMLParser2(47968,0xa0ac14e0) malloc: *** error for object 0x382f6d0: double free
*** set a breakpoint in malloc_error_break to debug
 
Hast du schon mal durch debugged, bis zu dieser Stelle und angeschaut, ob da mit dem Content alles IO ist?

Gruß

Sascha
 
Problem gelöst, es lag an der XML Formatierung ^^
danke für eure Hilfe ;)
 
Lass mich raten, du hast eine leerzeile bei dem Text gehabt den du in Content schreibst. :-)
Du solltest das einlesen ändern.
Die Methode für den Content der Elemente kann nämlich öfter aufgerufen werden.

Gruß

Sascha
 
Ich habe die xml datei per php generieren lassen und dachte, es würde nichts ausmachen wenn alles in einer reihe steht xD
nunja, scheinbar schon ^^
Gruß
BigOnkel