1 Reply Latest reply: Jan 8, 2009 11:56 PM by 843807 RSS

    javax.usb problem

    843807
      i would like to use window xp to test this program

      import javax.usb.*;
      import java.util.List;

      public class TraverseUSB
      {
      public static void main(String argv[])
      {
      try
      {
      // Access the system USB services, and access to the root
      // hub. Then traverse through the root hub.
      UsbServices services = UsbHostManager.getUsbServices();
      UsbHub rootHub = services.getRootUsbHub();
      traverse(rootHub);
      } catch (Exception e) {}
      }

      public static void traverse(UsbDevice device)
      {
      if (device.isUsbHub())
      {
      // This is a USB Hub, traverse through the hub.
      List attachedDevices = ((UsbHub) device).getAttachedUsbDevices();
      for (int i=0; i<attachedDevices.size(); i++)
      {
      traverse((UsbDevice) attachedDevices.get(i));
      }
      }
      else
      {
      // This is a USB function, not a hub.
      // Do something.
      }
      }
      }
      error message
      C:\TraverseUSB.java:1: package javax.usb does not exist
      import javax.usb.*;
      ^
      C:\TraverseUSB.java:18: cannot resolve symbol
      symbol : class UsbDevice
      location: class TraverseUSB
      public static void traverse(UsbDevice device)
      ^
      C:\TraverseUSB.java:12: cannot resolve symbol
      symbol : class UsbServices
      location: class TraverseUSB
      UsbServices services = UsbHostManager.getUsbServices();
      ^
      C:\TraverseUSB.java:12: cannot resolve symbol
      symbol : variable UsbHostManager
      location: class TraverseUSB
      UsbServices services = UsbHostManager.getUsbServices();
      ^
      C:\TraverseUSB.java:13: cannot resolve symbol
      symbol : class UsbHub
      location: class TraverseUSB
      UsbHub rootHub = services.getRootUsbHub();
      ^
      C:\TraverseUSB.java:23: cannot resolve symbol
      symbol : class UsbHub
      location: class TraverseUSB
      List attachedDevices = ((UsbHub) device).getAttachedUsbDevices();
      ^
      C:\TraverseUSB.java:26: cannot resolve symbol
      symbol : class UsbDevice
      location: class TraverseUSB
      traverse((UsbDevice) attachedDevices.get(i));
      ^
      7 errors

      Tool completed with exit code 1

      also i would like to ask when i run this program, what package do it use. and how can i run this program.
        • 1. Re: javax.usb problem
          843807
          Hi, i've tried this code as well.. i manage to solve your error, but i cant get it to run properly.
          meaning, the program cant read the device at all. i also had teh same code as you, i got it from somewhere, but it don't seem to work.. can anyone help me?

          System.out.println("hello");
          UsbServices services = UsbHostManager.getUsbServices();
          System.out.println("hello1");
          UsbHub rootHub = services.getRootUsbHub();
          System.out.println("hello2");
          traverse(rootHub);
          System.out.println("hello3");

          the output is only hello.
          so i don't know what is wrong.. anyone any idea?




          download link: [http://sourceforge.net/project/showfiles.php?group_id=21114]