The Glade 4.0

"Turn the lights down, the party just got wilder."
It is currently Sun Nov 24, 2024 3:35 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Apr 10, 2011 2:02 am 
Offline
User avatar

Joined: Thu Sep 24, 2009 4:57 am
Posts: 849
Long story short, I'm in a bit over my head with a Java program. Professor gave us a very open-ended project, part of which has come down to making use of (and soon, changing) this Java program written by a student a semester or two ago. A program I've been trying and failing to get it to compile or run.

The files:

He sent us this program in a .zip file. This file includes many .java files, one .class file, and a bunch of .wavs. I am 99% certain that all but one of the .java files comprise this API created to support the RFID device we are working with. The first line of code in all of these files is package com.thingmagic; The other .java file (theGUI.java) is the one the student wrote. The .class file (theGUI.class) included is, presumably, the compiled version of the student's .java file.

The errors:
Quote:
>java theGUI.class
Exception in thread "main" java.lang.NoClassDefFoundError: theGUI/class
Caused by: java.lang.ClassNotFoundException: theGUI.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: theGUI.class. Program will exit.

>javac theGUI.java
theGUI.java:25: warning: sun.audio.AudioPlayer is Sun proprietary API and may be
removed in a future release
import sun.audio.AudioPlayer;
^
theGUI.java:26: warning: sun.audio.AudioStream is Sun proprietary API and may be
removed in a future release
import sun.audio.AudioStream;
^
theGUI.java:28: package com.thingmagic does not exist
import com.thingmagic.*;
^
theGUI.java:35: cannot access Reader
bad class file: .\Reader.java
file does not contain class Reader
Please remove or make sure it appears in the correct subdirectory of the classpath.
public Reader r;
^


The technical details:

My classpath variable - .;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip;C:\directory\I\have\all\these\files\in

My verdict: I'm overlooking something stupid. The error trying to run the .class file seems perhaps a bit scary, but then the error trying to compile makes it seem like there is something just blatantly stupid going on on my part, and I'm not sure that is coincidental. Then again, between the classpath looking like it's set properly in two different ways and the import looking fine to me, I have no idea what's up there either.

Tried this on a computer in the IST lab at school, too, with the exact same errors.

Any help would be awesome, as it's pretty important we get this working soon so I have time to try and change it. Though I'm kicking *** in my Java class, that class is one half step beyond an introductory course. This being a full and complete program going well beyond the basics I've gone over in that Java class I suspect I'll need the time to make changes to this program.

I'll include the content of theGUI.java here, both in case that matters at all, and in case anyone is just curious. :p Judging by the code, it seems like a pretty simple little GUI to work with a RFID reader. Depending on what tags it reads, it plays a certain note.

Spoiler:
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
   import java.awt.event.KeyListener;
   import java.io.FileInputStream;
import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.InputStream;
   import java.util.Scanner;
   import java.util.Vector;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

   import sun.audio.AudioPlayer;
   import sun.audio.AudioStream;

import com.thingmagic.*;

public class theGUI implements ActionListener, ListSelectionListener{
   /**
    * Sample program that reads tags for a fixed period of time (500ms)
    * and prints the tags found.
    */
public Reader r;

public static int counter = 0; //counter for # of tags read.
//NOTE: This variable should be synonymous with the # of tags in the JList.
public static JFrame frame;
public static JPanel panel;
public static TagReadData[] tagReads;
public static JTextArea field;
public static JTextField input;
public static JButton callMethod;
public static JButton connectButton;
public static int count = 0;
public DefaultListModel model;
public JList list;
static InputStream[] in = null;
static AudioStream[] as = null;
String path = System.getProperty("java.library.path");
String scanresult = null;
public String[] EPCvalues = new String[500];//stores EPC values of tags read in.
//System.out.println(path);
//System.out.println("Please provide Reader URL");
Scanner scan = new Scanner(System.in);
   // Import the API
     @SuppressWarnings("deprecation")
     public theGUI()
     {
        frame = new JFrame();
        panel = new JPanel();
//        field = new JTextArea(30,30);
        model = new DefaultListModel();
        list = new JList(model);
        list.setVisible(false);
        input = new JTextField(11);
        callMethod = new JButton("Click here to read a tag!");
        connectButton = new JButton("Connect");
        panel.add(input);
        panel.add(callMethod);
        panel.add(connectButton);
   //     list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION );
//        ListSelectionModel listmodel = list.getSelectionModel();
//        listmodel.addListSelectionListener(this);
        panel.add(list);
        list.addListSelectionListener(this);
        panel.setSize(600,600);
        frame.setSize(600,600);
        callMethod.addActionListener(this);
        connectButton.addActionListener(this);
        frame.add(panel);
        frame.setVisible(true);
       
     }
   public static void main(String args[])
     {
      new theGUI();
      
     }
    
   @Override
   public void actionPerformed(ActionEvent arg0) {
      // TODO Auto-generated method stub
      if(arg0.getSource()==callMethod)
      {
         
         if(r == null)
         {
            connectButton.setText("Not connected");
         }
         else
         {
        //Program setup
       // Create Reader object, connecting to physical device
       try
       {
        
       //  boolean keepplaying = true; //flag to keep reading tags.
        
         //pointer for Vector.
         // Read tags
         Vector vec = new Vector(0);
         // Print tag reads
        
        
          
           tagReads = r.read(500);
          
           System.out.println(tagReads.toString());
           for(int i = 0; i < tagReads.length; i++)
           {
              vec.add(tagReads[i]);
              EPCvalues[count]=tagReads[i].toString().substring(4, 28);
              System.out.println(EPCvalues[count].toString());
              model.addElement(EPCvalues[count]);
              count++;
           }
           //set the List visible.
           list.setVisible(true);
       }
      
         
      catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
         }
      }
      else if (arg0.getSource()==connectButton)
      {
         //Reader r;
         try {
            if(r == null)
            {
               String arguments = "tmr:///com3";
            r = Reader.create(arguments);
             r.connect();
               r.paramSet("/reader/region/id", Reader.Region.NA);
               connectButton.setText("Disconnect");
               tagReads = r.read(500);
            }
            else
            {
               //destroys connection to the reader, and ends the program.
               r.destroy();
               JOptionPane.showMessageDialog(frame,"Thank you for using the reader. Goodbye!");
               System.exit(0);
            }
         } catch (ReaderException e) {
            // TODO Auto-generated catch block
            connectButton.setText("Not connected");
         }
      }
   
      }
      
   @Override
   public void valueChanged(ListSelectionEvent e) {
      // TODO Auto-generated method stub
      //ListSelectionModel mod = (ListSelectionModel)e.getSource();
      if(r == null)
      {
         connectButton.setText("Not connected");
      }
      else
      {
         try
           {
          // r.connect();
         in = new FileInputStream[19];
         // Create an AudioStream object from the input stream.
         as = new AudioStream[19];
            in[0] = new FileInputStream("Emods.wav");
            as[0] = new AudioStream(in[0]);
            in[1] = new FileInputStream("E2.wav");
            as[1] = new AudioStream(in[1]);
            in[2] = new FileInputStream("D5.wav");
            as[2] = new AudioStream(in[2]);
            in[3] = new FileInputStream("horse.wav");
            as[3] = new AudioStream(in[3]);
            in[4] = new FileInputStream("G2.wav");
            as[4] = new AudioStream(in[4]);
            in[5] = new FileInputStream("D4.wav");
            as[5] = new AudioStream(in[5]);
            in[6] = new FileInputStream("idk5.wav");
            as[6] = new AudioStream(in[6]);
            in[7] = new FileInputStream("G3.wav");
            as[7] = new AudioStream(in[7]);
            in[8] = new FileInputStream("D2.wav");
            as[8] = new AudioStream(in[8]);
            in[9] = new FileInputStream("idk8.wav");
            as[9] = new AudioStream(in[9]);
            in[10] = new FileInputStream("E3.wav");
            as[10] = new AudioStream(in[10]);
            in[11] = new FileInputStream("E4.wav");
            as[11] = new AudioStream(in[11]);
            in[12] = new FileInputStream("E5.wav");
            as[12] = new AudioStream(in[12]);
            in[13] = new FileInputStream("Emods.wav");
            as[13] = new AudioStream(in[13]);
            in[14] = new FileInputStream("idk13.wav");
            as[14] = new AudioStream(in[14]);
            in[15] = new FileInputStream("D3.wav");
            as[15] = new AudioStream(in[15]);
            in[16] = new FileInputStream("idk15.wav");
            as[16] = new AudioStream(in[16]);
            in[17] = new FileInputStream("idk16.wav");
            as[17] = new AudioStream(in[17]);
            in[18] = new FileInputStream("C3.wav");
            as[18] = new AudioStream(in[18]);
           }
           catch(Exception evt)
           {
          
                   
           }
          // if(list.getSelectedIndex() > -1)
          // System.out.println(EPCvalues[list.getSelectedIndex()]);
          // else
          //    System.out.println("NOTHIN!");
         //  r.destroy();
           //if(list.getSelectedIndex() = .null)
           if( list.getSelectedIndex() > -1)
           {
              if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("00000000000000000D066587"))
              {
                 AudioPlayer.player.start(as[0]);
              }
              else if (EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("0000000000000000ABC10451"))
              {
                 AudioPlayer.player.start(as[1]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003412DC03011828021097")||EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003412DC03011828021099"))
              {
                 AudioPlayer.player.start(as[2]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("300833B2DDD906C000000000"))
              {
                 AudioPlayer.player.start(as[3]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003412DC03011828021099"))
              {
                 AudioPlayer.player.start(as[4]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003412DC03011828249550"))
              {
                 AudioPlayer.player.start(as[5]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003412DC03011924215593"))
              {
                 AudioPlayer.player.start(as[6]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003412DC03011924215594"))
              {
                 AudioPlayer.player.start(as[7]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("00000000000000000A071822"))
              {
                 AudioPlayer.player.start(as[9]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("3005FB63AC1F3841EC880467"))
              {
                 AudioPlayer.player.start(as[8]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("000000000000000000400279"))
              {
                 AudioPlayer.player.start(as[10]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003411B802011114336814"))
              {
                 AudioPlayer.player.start(as[11]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("000000000000000000001180"))
              {
                 AudioPlayer.player.start(as[12]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2003411B802011114336814"))
              {
                 AudioPlayer.player.start(as[13]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("3005FB63AC1F3841EC880467"))
              {
                 AudioPlayer.player.start(as[15]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("E2008073700D02451040FCF1"))
              {
                 AudioPlayer.player.start(as[16]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("00000000000000000D066587"))
              {
             
                 AudioPlayer.player.start(as[17]);
              }
              else if(EPCvalues[list.getSelectedIndex()].equalsIgnoreCase("000000000000000000E50253"))
              {
                 AudioPlayer.player.start(as[18]);
              }
           }
   }
   }
}


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Apr 10, 2011 2:09 am 
Offline

Joined: Thu Sep 03, 2009 10:03 am
Posts: 4922
I hate it when people use "package" and all that. I'm not an expert in source control management so it makes everything a fiasco.

Here's what I would do. Strip out "package" and anything similar from all of the .java files. Delete the imports that import your own stuff, since the files will be in the same directory (I just verified this is OK from looking at an old project). Put everything in the same directory and try building. Backup theGUI.class and then delete the original since you will presumably recompile it from theGUI.java.

You can use some build command to put everything into a .jar, if you want, but I don't think you need "package" anywhere.

edit: fixed some typos


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Apr 11, 2011 8:21 pm 
Offline
User avatar

Joined: Thu Sep 03, 2009 11:05 am
Posts: 1111
Location: Phoenix
First of all, remove the .class when you are using the java command to run the program. That doesn't belong there.

Also, when you are compiling you need to add the option "-classpath ." without the quotes. That will tell the compiler to look for all the source files in the current directory.

I don't agree with Lex's suggestions regarding packages.


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 12, 2011 12:03 am 
Offline
User avatar

Joined: Thu Sep 24, 2009 4:57 am
Posts: 849
I did have success! It was actually achieved through other means.

I didn't want to mess around with the package setup, mostly because I didn't want to change any of the original files that came from the company. Also, the previous student got it to work this way, so I figured there was some other way to manage. I did mess around a little with importing each file individually but couldn't manage to make it work due to the same sort of errors, so I figured I wouldn't continue down this path.

To be honest I'm not 100% sure how it was supposed to work, based on what he sent my group. We managed to get it to work by taking all of the API .java files and putting them in a /com/thingmagic folder from the base directory. I actually tried this earlier, but it turns out that you have to this AND get rid of the .java files from the base directory as well. When I tried it, I just copied them into /com/thingmagic folder and left the originals in place. For whatever reason, Java seems to check both places and only properly work if they follow that directory path yet also not show up in the directory I'm running out of. Strange.

I'm still confused, but it's running now so I can't complain too much I suppose!

In any case, I most certainly appreciate the help.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 128 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group