Hello, I am having an issue with a lateinit variab...
# android
i
Hello, I am having an issue with a lateinit variable that I am unsure on how to fix. With the code as is, the variable in question does get initialized within a while loop but because of this, AndroidStudio throws a
lateinit property series has not been initialized
error. I don't really know what a good work around would be, any advice would be helpful? Thanks To give background, I am trying to create a line graph using GraphView library
Copy code
// create a new data series
        lateinit var series: LineGraphSeries<DataPoint>
        // link activity to layout view
        val graph: GraphView = findViewById(R.id.line_chart)

        // try to read and save data into series
        val minput = InputStreamReader(assets.open("tester_data_CSV.csv"))
        val reader = BufferedReader(minput)
        var line: String
        var x: Double
        var y: Double
        while (reader.readLine().also { line = it } != null) {
            val row: List<String> = line.split(",")
            x = row[0].toDouble()
            y = row[1].toDouble()
            // add data to series, unsure what the last element is for
            series.appendData(DataPoint(x,y),true,  100)
        }
        // add series to graph
        graph.addSeries(series)
f
based on this snippet your variable is not initialled at all
i
ah! thank you
k
Yeah, doesn't look like you really need the lateinit. Just create an object