'How to get the JAR file for sun.misc.BASE64Encoder class?
I have some code in my Activity class that uses sun.misc.BASE64Encoder class. But it is showing java.lang.NoClassDefFoundError : sun.misc.BASE64Encoder. Do I need the jar? Where can I download it from?
Solution 1:[1]
Since Java 8 you can use java.util.Base64 class:
byte[] original = "Base64".getBytes(StandardCharsets.UTF_8);
// encode
byte[] toBase64 = Base64.getEncoder().encode(original);
// decode
byte[] fromBase64 = Base64.getDecoder().decode(toBase64);
// output
System.out.println(new String(toBase64)); //QmFzZTY0
System.out.println(new String(fromBase64)); //Base64
System.out.println(Arrays.equals(original, fromBase64)); //true
See also: How can I convert a string into a GZIP Base64 string?
Solution 2:[2]
- Just add rt.jar to the build path of the project from path
C:\Program Files\AdoptOpenJDK\jdk-8.0.202.08\jre\lib - Copy the jar and paste in the libraries folder of the project.
Solution 3:[3]
For me it is resolved with simple steps, I was using Java11 JDK.As, in this version Base64 classes are deprecated, we are getting this issue. Changing to Java 8 solved the issue. Steps: In Eclipse,
- Go to, Windows-> Preferences-> Installed JREs
- Add-> select JDK8 or lesser version of JDK->Add
- Make it as default JDK by selecting this JDK
- Apply and Close
And, Done.
Thank you.
Solution 4:[4]
It's available in rt.jar, that comes with Sun java runtimes.
In 1.5.0_06 : jre\lib\rt.jar
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | aviboy2006 |
| Solution 3 | Amulya Koppula |
| Solution 4 | user1893074 |
