Encode Base64 Cannot Find Symbol Error

error: cannot find symbol ...String base64 = Base64.encodeToString(array, Base64.DEFAULT);

Base64.DEFAULT is from Android, not the java.util.Base64. (If you look at the docs for java.util.Base64, you'll see it really doesn't have a DEFAULT member - you should always be careful about contextual things like this when copying code from elsewhere.

I believe all you need to use java.util.Base64 is

String base64 = Base64.getEncoder().encodeToString(array);

Base64 apache.commons .encodeBase64 symbol not found

The new keyword expects a type to be created. As the little caret points out, there should be brackets () behind Base64.

Yet, Base64 is a collection of static methods, so you are done if you just drop the new in this case.

String encStr = Base64.encodeBase64String(out);

should do the trick.

Cannot Resolve Symbol "Default"

I solved this in following 2 Steps;

Add this

import android.util.Base64;

Remove these

import java.util.Base64;
import java.util.Base64.Decoder;

Base64Encoder cannot be resolved

Looks like you are using a class that does not exist in a jar you have included in the web application. Can you try the following? Make adjustments if necessary, I am just looking at the documentation for commons and typing this out --

  1. Go to http://commons.apache.org/codec/index.html and read through the information there
  2. Now go to http://commons.apache.org/codec/download_codec.cgi and download the zip file
  3. Extract out the jar file and copy it to the lib directory of your web application
  4. Replace the line
    [String encoding = Base64Encoder.encode ("test:test");]

with

String encoding = new String(
org.apache.commons.codec.binary.Base64.encodeBase64
(org.apache.commons.codec.binary.StringUtils.getBytesUtf8("test:test"))
);


Related Topics



Leave a reply



Submit