• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalArgumentException: im == null!  RSS feed

 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is portion of my code. Here I wrote a method 'stegProcess' that returns a byte[]. I want to write an image file from this byte array. But getting this error, "java.lang.IllegalArgumentException: im == null!". This code works fine if I commented out the call to 'stegProcess'. Another important point is that I am getting a value for in.available(), like.. Available: 53270

Thanks you very much in anticipation of an early reply.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that error message coming from the steg_process method? If so, you might want to look at that method to see why it is doing whatever it does to cause you to "get" that message (whatever you meant by that).
 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. This is my steg_process method. I don't know what's wrong with this method



anxiously waiting for a solution..
 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there anyone here who can help me? please respond buddies..please give me a solution to this problem or give me some suggestions to write an image from a byte[] after manipulating bits on that byte[] array. please..i will be ever grateful to you...it is extremely urgent for me...
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you let us know the exact line the error is happening on? The stack trace of the error will tell you that.

(Even better would be a self-contained example - a SSCCE - that demonstrates the error that we could run for ourselves)
 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please run the following codebefore running please make you have a file named test.jpg in your C: drive)



Here is the stacktrace after running the program:



waiting for a solution....
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here's what is happening.

On line 33, the ImageIO.read method is returning null. That results in the exception later when you try and write the image.

The Javadocs for the ImageIO.read method say:
Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered. The InputStream is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned.


The ImageIO class identifies a suitable ImageReader that can read the stream - presumably based on the format of the data in the stream. There are no suitable readers registered, so the method returns null.

What I think is happening (although this is an educated guess) is that your steg_process has messed with the bytes enough that the ImageIO class can no longer recognise it as a JPEG. This is consistent with the way it works if you comment out the call to steg_process.

If that's correct, how you fix it is another matter. I don't know enough about JPEG formatting to sensibly comment.

Edit: you may have noticed that long code lines mess up the width of the forum pages. I've put a line break in one of your comments to fix it.
 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. I modified my code to identify the existence of image reader.



Even if output_data is replaced by imageInByte, in that case also i am getting an output like..

Available: 109980
Reader is not found

I don't know what exactly wrong with this code..is there anyone here who can kindly help me about this image processing?
 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If anyone here expert in java image processing, please respond. It would be a great help for me. I am in extreme deadline. Please give me solution to this problem or suggest me an alternate way in which I can write an image after bit-manipulation. waiting....
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem still appears to be that after you muck about with the bytes in the image, it isn't a valid image any more. The way to fix that is not simple: you need to know which bytes you can change and which bytes you can't change, and which bytes you have to change if you change some other bytes. And this depends on what kind of image it is.

Let's assume you're using a JPG, for example. Then it's going to have some headers describing various aspects of the image, and then some data containing the actual image. If you change things in the header at random then you're going to end up with something which doesn't satisfy the criteria for being a JPG. And that's exactly what you're doing... I don't see anything JPG-specific in that code there.
 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that is what exactly the case!! I just modified some header information. Thanks a lot buddy for helping me. Can you please tell me what should I do to get the header information. Can you suggest any article or webpage that could be helpful for me..thanks anyway..it was a great help...
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if this were my problem, and I had planned to use JPG files, my google keywords would be "JPEG specification".

(tries it out...)

Yup, that gives you a whole page of links which look like they might lead to the JPEG specification.
 
Simanto Chakraborty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm..thanks again buddy..take care
 
jason hue
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simanto Chakraborty wrote:hmmm..thanks again buddy..take care


Hi, may i know do you to solve the problem already ? Mind to share ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!