Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Taylor Quinn
Taylor Quinn
20,003 Points

Help debugging exc_bad_acess

So i am building a two page tabbed app. I am using the Charts framework to put charts in my app. Both page have the same chart with different data in each. When I run the app the first page and chart display fine but when I try to run the second page and chart it crashes and I get an exc_bad_access error. here is my code

@IBOutlet weak var yourRankRetailLabel: UILabel!

@IBOutlet weak var barChartView2: BarChartView!


var employee: [String]!
var currentRank = ""


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

        DataService.dataService.CURRENT_USER_REF.observeEventType(FEventType.Value, withBlock: { snapshot in //snap

        let rank = snapshot.value.objectForKey("rankretail") as! String

        self.yourRankRetailLabel.text = "You were ranked \(rank) in service sales last week!"
        self.currentRank = rank
        }, withCancelBlock: { error in
            print(error.description)
    })//snap


    employee = ["1491", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    let unitsSold = [5.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]

    setChart(employee, values: unitsSold)




}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.



    }

func setChart(dataPoints: [String], values: [Double]) {
    barChartView2.noDataText = "You need to provide data for the chart."

    var dataEntries: [BarChartDataEntry] = []
    for i in 0..<dataPoints.count {
        let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
        dataEntries.append(dataEntry)
    }

    let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
    let chartData = BarChartData(xVals: employee, dataSet: chartDataSet)
    barChartView2.data = chartData
Steven Deutsch
Steven Deutsch
21,046 Points

Hey Taylor Quinn,

Can you post the top part of the debugger output?

2 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

it looks like barChartView2 is not being instantiated before you access it

Taylor Quinn
Taylor Quinn
20,003 Points

Could you please elborate on what that is and how to go about fixing it.