• Post Reply Bookmark Topic Watch Topic
  • New Topic

javac thinks byte[] is a String  RSS feed

 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this thread:

http://www.coderanch.com/t/374496/java/java/send-byte-array

here, so I figure this is the approriate forum.

I am using the org.apache.xerces.impl.dv.util.Base64. More precisely, I am trying to use it. I have tried all the combinations I can imagine to get my digest bytes into it, finally resorting to simply creating a new byte[] as a test.

This is what javac thinks of my test:

Any ideas what is going on here? I know that I don't find a String where byte[] is required in that code.

I'm compiling with JDK 1.4.2_06 on XP.

I'm limited in my choices for a Base64 encoder, due to an arduous process for getting third party code approved for deployment. I may just write one myself, but I'd still like to know why I get this compilation error.

Thanks,

Joe
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Joe]: I know that I don't find a String where byte[] is required in that code.

And yet, it's there.

    byte[] h = Base64.encode(new byte[5]);

The left hand side is saying it expects a byte[]:

    byte[] h =

On the right hand side, this part here is indeed a byte[]:

    new byte[5]

But when you call the encode() method, it returns a String.

    Base64.encode(new byte[5]);

Thus, you probably want code that looks something like this:

    String s = Base64.encode(new byte[5]);
[ July 11, 2006: Message edited by: Jim Yingst ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message is telling you that the method returns a String, not a byte[]. Base64 encoding turns bytes into text.
 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh!

Thanks,

Joe
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!