TAGS :Viewed: 11 - Published at: a few seconds ago

[ how to resolve Inconvertible types error in Maven ]

I am using maven 3.0.5 and JDK 1.7.0_17. When i run maven using mvn install i get the following error in many places wherever conversion happens and in JBoss it's showing as Warning.

[ERROR] \Workspace\my-app\src\controller\ChangeNoterController.java:[159,43] error: inconvertible types

The code for the above line is:

                    if (resultMap != null) {
        changeNoteList = (List<ChangeNoter>) resultMap.get("changeNoterList");
        changeNoteListSize = (int) resultMap.get("changeNoterListSize");        --error

I get the same "Inconvertible types" error in maven wherever this conversion happens in java which is showing as warning in Java.

I would be grateful if someone helps me in this. Thanks in advance.

Answer 1

What is resultMap? Probably that resultMap contains some Object without specific type for exmpl: Map<String, Object>.

1) When you trying parse Integer try one of this ways:

  • Integer newValue = (Integer) resultMap.get("changeNoterListSize").toString();

  • Integer newValue = Integer.parseInt(resultMap.get("changeNoterListSize").toString());

Maven always work better when you converting to Int from String

2) Convert to list List<ChangeNoter> can be tricky and in this situation try to loop through resultMap.get("changeNoterList") and add one by one items to new List<>();

Answer 2

Since the method Map.get(Object) returns an object, it doesn't work to convert an object to int. Try to convert the object to an Integer. Here is the snippet,

changeNoteListSize = (Integer) resultMap.get("changeNoterListSize");