Wednesday, May 31, 2017

org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory


Hi Guys , You might face this exception when using wildfly 10 with hibernate. This exception is linked with the classloader since the same class is loaded by two different class loaders. You can the following solution

 <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.1.0.Final</version>
            <scope>provided</scope>
        </dependency>

Tuesday, May 30, 2017

Uncaught TypeError: Converting circular structure to JSON


Hi Guys
You will see this error on converting a json to string using JSON.stringify .
Full stacktrace is like
Uncaught TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at <anonymous>:1:6
Below is the sample code that can cause this exception. You can see that we have created an element object in line number 1 and in line number 2 we are assigning the same element object to the node attribute of the element. This is having a circular reference . Hence you will experience the exception.
var element={"node":{}};
element.node=element;
JSON.stringify(element);
You might also face the error for the following block of code :
var element={"node":{}};
element.node=element;
angular.toJson(element);
Uncaught is added since the exception is not catched by a catch block . According to MSDN, A TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function .So here it is explicitly thrown by stringify method.It is also possible that a common utility method is throwing this exception. Check if your code has the following statement .
new TypeError("Converting circular structure to JSON");

Sunday, May 28, 2017

The integer literal does not conform to the expected type String

Hi Guys ,

There are multiple reasons for getting this error .

1. If you have a class for which you are trying to create an object and you have missed to specify any of the class variables while creating the object, you might face the exception like :
The boolean literal does not conform to the expected type String .

Take a look at the program below :

class Student(
    val name: String,
    var age: Int
)

fun main(args: Array<String>) {
    val student= Student(1)
    println(student.name)
    println(student.age)
}


If you try to run the above program you might face an error like .
Click here to run this test.



Friday, May 26, 2017

Java vs. Kotlin

Hi Guys,
There are a lot of difference in how a java program and kotlin program.
1. package
2.import
Java program by default imports java.lang.* package.

Thursday, May 25, 2017

Kotlin Hello World

Let's check out a simple kotlin program to print hello world to the console.
Let's check out a simple kotlin program to print hello world to the console.
Here's the program to print hello world to the console.

package demo
fun main(args : Array<String>){
println("hello world")
}
If you run the above program you will get the following output.
hello world
Now let's go the program and try to understand the way it works.
Its way more simple for developers with java background,and I strongly recommend get hands on java experience to get expertise on kotlin.
The program starts with package deceleration , which is optional. If you do not declare the package the file goes to the default package . You have few restrictions for the package name . You cannot name package as java , this is same for the programs written in java language. But kotlin is different from java , you can actually name your package as kotlin .

ec2-user@ec2 Permission denied