Skip to main content

Featured post

How to Insert line break in Text component in React Native

Hi, I was developing an application in react native.I have to handle lots of text data in this small react native application.I have used  Text component in react native many times. While working on this application,i had a requirement to display some text content with line breaks.I will explain it clearly with an example.I want to display a text as shown below  Welcome Please subscribe my channel I wrote react native code as shown below <View> <Text> Welcome Please subscribe my channel </Text> <View> When i run these lines of code,It will display text as shown below Welcome Please subscribe my channel   - instead of displaying in two lines with line break,it displays in a single line.So i have to find a solution to insert line break in Text component in React Native.After lots of research,i found a clean solution as shown below <View> <Text> Welcome{"\n"} Please subscribe my channel </Text> <View> Here ...

Val cannot be reassigned compile time error in kotlin function solved

Hi friends,





I was writing a kotlin function.I used the keyword val as shown below


fun main() {

    println("Hello, world!")

    // Hello, world!

    val subscribers = 500

    subscribers=600

}


When i execute the above code,i got an error as shown below

Val cannot be reassigned


It means ,  when we run the line  val subscribers = 500, the local variable subscribers is assigned with the value 500.Then in the next line when we execute, subscribers=600,we are trying to reassign the local variable subscribers with the value 600.


Actually In Kotlin val declares final, read only, reference. We can can not reassign such variables with new values.So we got the error message as 


Val cannot be reassigned


How can we solve Val cannot be reassigned error in Kotlin


By using var instead of val in kotlin, we can resolve the error.Kindly check below example


fun main() {

    println("Hello, world!")

    // Hello, world!

    var subscribers = 500

    subscribers=600

}

Here we used var,so we can reassign the local variable subscribers any number of times

So i hope you understood the reason behind the error Val cannot be reassigned

Thanks