Error: The package “javax.xml.bind” does not exist. You might be missing a library

Hi, this is an example to connect an Arduino-BLE33 Nano to www.teachablemachine.withgoogle.com and called TM_Collector.
I want to transfer Image-data with the virtuell COM to the processing TM_Connector application...
The library javax.xml.bind.DatatypeConverter of this application is imported in code but the Error says it does not exist...

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

I hope, you can help by this problem.

Thnaks

Hi! It sounds like you might be running version 4.4.8.

There is a bug that we are getting sorted out and hoping to release a fix for soon in 4.4.9.

Will keep you posted on our progress. Thank you

moon

1 Like

Hello @Bua,

Welcome to forum!

The code should be separate from the discussion in the post so it is easy to read and a simple click of the mouse to copy the code.

It is also important to provide details:

  • Operating system
  • Processing version
  • Any other important details to reproduce the error.

I quoted this from your post:

Hi, this is an example to connect an Arduino-BLE33 Nano to LINK REMOVED and called TM_Collector.
I want to transfer Image-data with the virtuell COM to the processing TM_Connector application…
The library javax.xml.bind.DatatypeConverter of this application is imported in code but the Error says it does not exist…

I removed the link because my browsers did not allow me to view it.
There is a working link to a related GitHub topic in one of the references below.

Code provided:

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

You did not provide enough code to reproduce the error.

I will be using Processing 4.4.7 and Windows 10 for this discussion.

Related discussions:

Using code from last reference above I get this:

Note:
The error in RED did NOT appear right away and I had to scroll down and select it for details.
Under the error there is code that is commented that MAY be a correction based on the some of the references listed and testing.
I was only testing so you have to scrutinize this and correct as required.

The warning in BLUE is something new… the code still ran.
Research suggests it a warning and not typically a critical issue.
I can’t comment or explore this further at this time.

And the sketch launched:

The details are important.

Have fun!

:)

Oh Sorry,

I tried this with 4.4.8 and 4.4.7 with Windows11

I hope, it will help

Thanks

*** UPDATE ***

This (code here) seems to work with Processing 4.4.7 and Processing 4.4.10 as is without any changes and no errors! I am using W10.

Lesson learned!
I must be more meticulous and thorough when testing.

I am still going to go back to understand what happened and why that red underlined error was present before with Processing 4.4.7 (bottom right of image) !

Have fun!

:)

I sorted this out!
I have many libraries installed and they were providing the missing pieces.

This works with the ArtNet library installed but is still underlined in Red as in previous post:


import javax.xml.bind.DatatypeConverter; // Works with ArtNet library installed
//import java.util.*;

final int cameraWidth = 8;
final int cameraHeight = 8;
final int cameraBytesPerPixel = 1;
final int bytesPerFrame = cameraWidth * cameraHeight * cameraBytesPerPixel;

PImage myImage;
byte[] frameBuffer = new byte[bytesPerFrame];

void setup()
  {      
  // Generate a framebuffer for testing  
  for (int i = 0; i < bytesPerFrame; i++) 
    {
    //frameBuffer[i] = (byte) (choice(0, 256) % 256); // Choice returns 0 to 255 random
    frameBuffer[i] = (byte) (i%256);  // Generate some data (0, 1, 2, ..., 255)
    }  
       
  // Works with: 
  // import javax.xml.bind.DatatypeConverter;   
  // Arnet Library installed.
  String data1 = DatatypeConverter.printBase64Binary(frameBuffer);
  
  printData(data1);
  } 
  
void printData(String data)
  { 
  println(data.length());
  for(int i=0; i<data.length(); i++)
    {    
    if (i%64 == 0) println();
    print(data.charAt(i));  // Too long!
    }
  println();  
  }

This is the recommended solution:

//import javax.xml.bind.DatatypeConverter; 
import java.util.*;

final int cameraWidth = 8;
final int cameraHeight = 8;
final int cameraBytesPerPixel = 1;
final int bytesPerFrame = cameraWidth * cameraHeight * cameraBytesPerPixel;

PImage myImage;
byte[] frameBuffer = new byte[bytesPerFrame];

void setup()
  {    
  
  // Generate a framebuffer for testing  
  for (int i = 0; i < bytesPerFrame; i++) 
    {
    //frameBuffer[i] = (byte) (choice(0, 256) % 256); // Choice returns 0 to 255 random
    frameBuffer[i] = (byte) (i%256);  // Generate some data (0, 1, 2, ..., 255)
    }  
           
  // Works with: 
  // import java.util.*;;   
  // Arnet Library library not required.  
  String data2 = Base64.getEncoder().encodeToString(frameBuffer);
  
  println();
  printData(data2);
  } 
  
void printData(String data)
  { 
  println(data.length());
  for(int i=0; i<data.length(); i++)
    {    
    if (i%64 == 0) println();
    print(data.charAt(i));  // Too long!
    }
  println();  
  }

I asked Google Gemini to summarize for a post:

JAXB is Not Available in Current Processing Versions

The class your code uses, javax.xml.bind.DatatypeConverter, is not available in recent versions of Processing because it was removed from the standard Java Development Kit (JDK) starting with Java 11.

This occurred because the Java Architecture for XML Binding (JAXB) framework was separated from the core Java SE (Standard Edition) platform that Processing uses, as JAXB was part of the older Java EE (Enterprise Edition) platform.


Accidental Solution: Why the Library Made it Work

Your code worked because the installed, but unused, ArtNet library provided the missing file through an unintended side effect (or transitive dependency).

  1. Classpath Loading: When you install the ArtNet library, the Processing IDE automatically adds the library’s files and all of its dependencies (the JAR files it needs to run) to your project’s Classpath (the list of locations Java searches for classes).
  2. The Hidden Dependency: Since the ArtNet library itself relies on XML Binding (JAXB), installing it places the necessary JAXB JAR file (containing DatatypeConverter) onto your Classpath.
  3. Code Execution: The Java Virtual Machine simply finds the missing JAXB class inside the ArtNet dependency JAR and successfully runs your code.

In short, the ArtNet library accidentally solved your problem by adding the correct missing piece of Java’s deprecated technology to your search path.


Recommended Solution

Relying on an unrelated library to fix a dependency issue is unreliable. The proper solution is to use a method for Base64 encoding that is natively supported by modern Java and, therefore, by current versions of Processing: java.util.Base64.

You were already using the better method in your example code (data2). Switch your implementation to rely solely on this, and you can remove the problematic DatatypeConverter import and the installed ArtNet library if you don’t actually need it.

I was able to verify above by examining the artnet4j.jar file:

In the future I will isolate projects into their own sketchbook folder with only the required libraries for testing.

:)

1 Like

Hi,

thanks a lot for help :-).

But also these ideas are not working by processing 4.4.7 and 4.4.8 with win11. I want to use this with my students, so I need a running system🤷‍♀️.

May be you find a solution …

I found a solution (discussed in previous posts) that works for me on:

  • W10
  • W11
  • Processing 4.4.7
  • Processing 4.4.10

Code source:

teachablemachine-community/snippets/markdown/tiny_image/tiny_templates/TMConnector/TM_Connector/TM_Connector.pde at master · googlecreativelab/teachablemachine-community · GitHub

Changes made:

// Do not use:
//import javax.xml.bind.DatatypeConverter;

// Do not use:
//String data = DatatypeConverter.printBase64Binary(frameBuffer);

// Use this:
String data = Base64.getEncoder().encodeToString(frameBuffer);

Use a separate Sketchbook folder and add only the libraries required:

The other libraries are included with Processing and do not have to be added.

I encourage you and your students to read the guidelines:

The section on Asking Questions may be helpful!

I will assist you if follow the guidelines with future questions and only work with Processing 4.4.7 or the latest Processing 4.4.10.

Have fun!

:)

Thanks a lot; it works :slight_smile:

1 Like