Error: Incompatible Types: Int[][] Cannot Be Converted to Int

int cannot be converted to int []

           sumArray[i]= R1[i]+ R2[j]; // updated line

you need to assign to an array element, but you were doing it wrong.

error: incompatible types: int[][] cannot be converted to int

c is an array/matrix but you try to return an int, try

public static int[][] sum (int[][]a,int[][]b) {

In general you should specificy in which line java tells you the error appears when asking a question.

Hope it helps!

Java incompatible types: int cannot be converted to int[]

return new int[]{x[i], x[j]};

You want to return an array int[], not a single int value.

return x[i];
return x[j];

doesn't make any sense because a return statement immediately interrupts the flow (returns control to the invoker) making the following statements unreachable.

You are also missing a return statement at the end. When target hasn't been met, you still have to return something from the method.

It could be an empty array:

return new int[0];

However, usually, we throw an exception saying the given arguments didn't make the method work:

throw new IllegalArgumentException("The target wasn't met for the given input.");

Incompatible types : Int cannot be converted to "class" data type

Changing edge.add(x,y) to edge.add(new Edge(x,y)) should help. The list edge expects an Object of class Edge, while two ints are being passed, causing the error.

error: incompatible types: int[] cannot be converted to Integer[]

Error clearly says that you are providing int[] as input parameter where as your function is expecting Integer[] array. It would be better you change the input array to type Integer[]

Integer[] ip1 = new Integer[ip1_size];

incompatible types: int cannot be converted to T

You have a generic parameter so it will be logically correct for you to create a new tree when reading CSV.

This also means insertList(...) should become static and now be invoked like
BinarySearchTree<Integer> tree = BinarySearchTree.insertList(...)

Here is the code:

    public static void insertList(String csv)
{
String[] inputValues = csv.split(",") ; // Numbers are seperated by comma as instructed
BinarySearchTree<Integer> tree = new BinarySearchTree<>();
for (String x : inputValues)
{
int y = Integer.parseInt(x);
tree.insert(y);
}
}


Related Topics



Leave a reply



Submit