Novice Novice - 1 month ago 5x
Android Question

Java "package does not exist" error

I'm using Android Studio (v 1.2.2) with Java Platform (JDK) release 8u45 for Android App development. At the moment I'm trying to convert a byte array to a string with base 64 encoding by importing the following as such::

import java.util.Base64.Encoder;
import javax.xml.bind.DatatypeConverter;

However, after trying to import
I got the error

Error:(30, 24) error: package java.util.Base64 does not exist

at compile time. I then tried to import
for base 64 encoding and got a similar error. I tried updating Android studio (to what it is now, v 1.2.2) and updating Java JDK (to its current 8u45). If somebody could offer a pointer as to why these import statements aren't recognized it would be much appreciated.


The android API ships with its own Base64 utility which can be found under android.util.Base64. If this import does not work, there is a problem with your project setup.

Here is a quick working example:

String data = Base64.encode(new byte[] {0, 1, 2, 3, 4, 5});

More Information: Official Documentation