2

I am getting an object as a result of a method call. It is a raster/grid/matrix with rows and columns. But the return type of the method is a object.

On debugging, I can see the 2D array inside. But I am not being able to cast it into anything.

Object vPixels = pixelblock3.getPixelDataByRef(0);
Integer[][] wPixels = (Integer[][]) vPixels;

I get a ClassCastException at the 2nd line: [[B cannot be cast to [[Ljava.lang.Integer;

How can I fix this problem?

2 Answers 2

3

Just a guess: try:

int[][] wPixels = (int[][]) vPixels; 

Or

byte[][] wPixels = (byte[][]) vPixels; 

I think that [[B, "B" means primitive bytes.

Sign up to request clarification or add additional context in comments.

1 Comment

you're welcome. If the JVM was more kind, it should have pointed somehow byte instead of a cryptic B :)
0

A simple trick to know what is the type of the object:

Object vPixels = pixelblock3.getPixelDataByRef(0);
Class cls = vPixels.getClass();
System.out.println("The type of the object is: " + cls.getName());

Then you can cast to the appropriate type.

EDIT: as Luigi pointed out [[B means byte[][] so his answer is the correct one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.