0
import org.apache.commons.codec.binary.Base64;
import java.util.Base64;

It gives me an error when I run the code.

    private void upload() {
    Bitmap bm = BitmapFactory.decodeFile(mCurrentPhotoPath);
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.JPEG, 50, bao);
    byte[] ba = bao.toByteArray();
    ba1 = Base64.encodeBytes(ba);

    // Upload image to server
    new uploadToServer().execute();

}

The errors I got are:

Error:(81, 21) error: cannot find symbol method encodeBytes(byte[])
Error:(43, 25) error: cannot find symbol class Base64
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Desh Premi
  • 21
  • 1
  • 2

1 Answers1

4

You are importing Java library. Use android library for Base64 instead.

import android.util.Base64;
Vibhu Jain
  • 130
  • 10
  • Good call! I didn't notice that! – Aurasphere Jul 18 '17 at 09:10
  • Same happens when importing DateTime Utils. Both java as well as android library have classes for them. A novice user easily gets confused between them. – Vibhu Jain Jul 18 '17 at 09:12
  • Yep that's right, not any Java libray is available under Android. Take Swing and AWT for example. – Aurasphere Jul 18 '17 at 09:17
  • import android.util.Base64; is available only since Java 8 – Vasanth Aug 03 '17 at 05:28
  • @Vasanth buddy I nowhere mentioned any Java library class. I'm talking about Android's android.util.Base64; which I think has no link with Java 8 or Java 7. Also, since everyday some of the functions/methods and other features of Android/Java are getting deprecated alongwith the advancement of technology and feature advancements, there is no point using older version on Java/Android SDK. – Vibhu Jain Aug 03 '17 at 06:15