# Error with importing javax.xml.bind.DatatypeConverter

**URL:** <https://discourse.processing.org/t/error-with-importing-javax-xml-bind-datatypeconverter/43019>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [October 20, 2023, 8:02am UTC](https://discourse.processing.org/t/error-with-importing-javax-xml-bind-datatypeconverter/43019 "2023-10-20T08:02:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivam](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Shivam](https://discourse.processing.org/u/Shivam)\
**Post date:** [October 20, 2023, 8:02am UTC](https://discourse.processing.org/t/error-with-importing-javax-xml-bind-datatypeconverter/43019/1 "2023-10-20T08:02:19Z")

</div>

While running the code, i am getting the following error “The package “javax.xml.bind” does not exist. You might be missing a library.”  
\</

import processing.serial._;  
import java.nio.ByteBuffer;  
import java.nio.ByteOrder;  
import websockets._;  
import javax.xml.bind.DatatypeConverter;  
import controlP5._;  
import java.util._;

Serial myPort;  
WebsocketServer ws;

// must match resolution used in the sketch  
final int cameraWidth = 96;  
final int cameraHeight = 96;  
final int cameraBytesPerPixel = 1;  
final int bytesPerFrame = cameraWidth \* cameraHeight \* cameraBytesPerPixel;

PImage myImage;  
byte frameBuffer = new byte[bytesPerFrame];  
String portNames;  
ControlP5 cp5;  
ScrollableList portsList;  
boolean clientConnected = false;

void setup()  
{  
size(448, 224);  
pixelDensity(displayDensity());  
frameRate(30);  
cp5 = new ControlP5(this);  
portNames = Serial.list();  
portNames = filteredPorts(portNames);  
ws = new WebsocketServer(this, 8889, “/”);  
portsList = cp5.addScrollableList(“portSelect”)  
.setPosition(235, 10)  
.setSize(200, 220)  
.setBarHeight(40)  
.setItemHeight(40)  
.addItems(portNames);

portsList.close();  
// wait for full frame of bytes  
[//myPort.buffer](https://myPort.buffer)(bytesPerFrame);  
//myPort = new Serial(this, “COM5”, 9600);  
//myPort = new Serial(this, “/dev/ttyACM0”, 9600);  
//myPort = new Serial(this, “/dev/cu.usbmodem14201”, 9600);

myImage = createImage(cameraWidth, cameraHeight, RGB);  
noStroke();  
}

void draw()  
{  
background(240);  
image(myImage, 0, 0, 224, 224);

drawConnectionStatus();  
}

void drawConnectionStatus() {  
fill(0);  
textAlign(RIGHT, CENTER);  
if (!clientConnected) {  
text(“Not Connected to TM”, 410, 100);  
fill(255, 0, 0);  
} else {  
text(“Connected to TM”, 410, 100);  
fill(0, 255, 0);  
}  
ellipse(430, 102, 10, 10);  
}  
void portSelect(int n) {  
String selectedPortName = (String) cp5.get(ScrollableList.class, “portSelect”).getItem(n).get(“text”);

try {  
myPort = new Serial(this, selectedPortName, 9600);  
myPort.buffer(bytesPerFrame);  
}  
catch (Exception e) {  
println(e);  
}  
}

boolean stringFilter(String s) {  
return (!s.startsWith(“/dev/tty”));  
}  
int lastFrame = -1;  
String filteredPorts(String ports) {  
int n = 0;  
for (String portName : ports) if (stringFilter(portName)) n++;  
String retArray = new String[n];  
n = 0;  
for (String portName : ports) if (stringFilter(portName)) retArray[n++] = portName;  
return retArray;  
}

void serialEvent(Serial myPort) {  
// read the saw bytes in  
myPort.readBytes(frameBuffer);  
//println(frameBuffer);

// access raw bytes via byte buffer  
ByteBuffer bb = ByteBuffer.wrap(frameBuffer);  
bb.order(ByteOrder.BIG\_ENDIAN);  
int i = 0;

while (bb.hasRemaining()) {  
//0xFF & to treat byte as unsigned.  
int r = (int) (bb.get() & 0xFF);  
myImage.pixels[i] = color(r, r, r);  
i++;  
//println(“adding pixels”);  
}  
if (lastFrame == -1) {  
lastFrame = millis();  
}  
else {  
int frameTime = millis() - lastFrame;  
print("fps: ");  
println(frameTime);  
lastFrame = millis();  
}

myImage.updatePixels();  
myPort.clear();  
String data = DatatypeConverter.printBase64Binary(frameBuffer);  
ws.sendMessage(data);  
}

void webSocketServerEvent(String msg) {  
if (msg.equals(“tm-connected”)) clientConnected = true;  
}/\>

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [October 20, 2023, 9:25pm UTC](https://discourse.processing.org/t/error-with-importing-javax-xml-bind-datatypeconverter/43019/2 "2023-10-20T21:25:13Z")

</div>

Hi @Shivam,

This is not longer part of jdk since [jdk11 (jep320)](https://openjdk.org/jeps/320#Java-EE-modules).

> [@Shivam](#):
>
> javax.xml.bind.DatatypeConverter.printBase64Binary(frameBuffer);

As you only need to convert base64 you can simply use  
[Base64 class](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Base64.html).

> **[Java Base64 Encoding and Decoding | Baeldung](https://www.baeldung.com/java-base64-encode-and-decode)**
>
> How to do Base64 encoding and decoding in Java, using the new APIs introduced in Java 8 as well as Apache Commons.

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Shivam](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@Shivam](https://discourse.processing.org/u/Shivam)\
**Post date:** [October 21, 2023, 4:43am UTC](https://discourse.processing.org/t/error-with-importing-javax-xml-bind-datatypeconverter/43019/3 "2023-10-21T04:43:46Z")

</div>

Hi @mnse, thanks for the reply. Will try this.
