Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Problem with pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 15750 of 16485
Post > Topic >>

Problem with program exception in thread error

by christopher_board@[EMAIL PROTECTED] Feb 7, 2008 at 01:55 PM

Hi all,

I am currently developing a java application that will allow the user
to perform wake on lan. The program gets the host name and mac address
from a CSV file. When the user presses the button the application will
read the file in and then perform the wake on lan on the computer.
However I keep on getting an error and the application is not working.
This is the error that i am getting.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at remoteshutdown.WakeOnLan.WOL(WakeOnLan.java:74)
	at remoteshutdown.WakeOnLan.readFile(WakeOnLan.java:60)
	at
remoteshutdown.mainScreen.btnAddDetails_actionPerformed(mainScreen.java:
563)
	at remoteshutdown.mainScreen
$mainScreen_btnAddDetails_actionAdapter.actionPerformed(mainScreen.java:
980)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown
Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

This is the code that I am using:

package remoteshutdown;

im****t java.awt.Dimension;
im****t java.awt.Point;
im****t java.io.*;
im****t java.net.*;
im****t java.util.*;

public class WakeOnLan {
    String macStr;
//    String mac;
//    String Computer;
    Hashtable<String, String>  macTable = new Hashtable<String,
String>();


    public static final int ****T = 9;

    public void readFile() {
		try {
            // Open the file that is the first
            // command line parameter
            FileInputStream fstream = new FileInputStream("C:\
\Do***ents and Settings\\All Users\\Application Data\\Remote Shutdown\
\DHCP Ex****t.csv");
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new
InputStreamReader(fstream));
            String strLine;
            //Read File Line By Line
            while ((strLine = br.readLine()) != null) {
            	System.out.println("strLine is: " + strLine );
            	StringTokenizer st = new  StringTokenizer(strLine, ",.");

            	String Computer = st.nextToken();

            	if(strLine.contains("."))
            	{
            		int firstIndex = strLine.indexOf(".");
            		int lastIndex = strLine.lastIndexOf(".");
            		if (firstIndex == lastIndex) {
            			st.nextToken();
            		}
            		else {
        		st.nextToken();
            	st.nextToken();
            		}
            	}
            	String mac = st.nextToken();
            	System.out.println("\t\tComputer : " + Computer+" for
"+mac);

            	macTable.put((String)Computer, (String)mac);
                // Print the content on the console
            //Close the input stream
            }
           System.out.println("CLOSING IN");
            in.close();


        } catch (Exception e) { //Catch exception if any
            System.err.println("Error: " + e.toString());
        }
        WOL();
    }

    public void WOL() {
    	Object[] choices =
mainScreen.lstComputerNames.getSelectedValues();
    	for (Object aChoice : choices) {

    	String wakeComputer = (String)macTable.get(aChoice);

    	System.out.println("wakeComputer is:" + wakeComputer);


        String ipStr = "255.255.255.255"; //broadcast address

    	String originalMac = wakeComputer.substring(0,2) + ":" +
wakeComputer.substring(2,4) + ":" + wakeComputer.substring(4,6) + ":"
+ wakeComputer.substring(6,8) + ":" + wakeComputer.substring(8, 10) +
":" + wakeComputer.substring(10,12);
    		System.out.println("original mac: " + originalMac);

        String macStr = originalMac; //"00:30:4F:1C:95:dF";



        try {
//        	wait(5000);
            byte[] macBytes = getMacBytes(macStr);
            byte[] bytes = new byte[6 + 16 * macBytes.length];
            for (int i = 0; i < 6; i++) {
                bytes[i] = (byte) 0xff;
            }
            for (int i = 6; i < bytes.length; i += macBytes.length) {
                System.arraycopy(macBytes, 0, bytes, i,
macBytes.length);
            }

            InetAddress address = InetAddress.getByName(ipStr);
            DatagramPacket packet = new DatagramPacket(bytes,
bytes.length, address, ****T);
            DatagramSocket socket = new DatagramSocket();
            socket.send(packet);
            socket.close();

            System.out.println("Wake-on-LAN packet sent.");
        }
        catch (Exception e) {
            System.out.println("Failed to send Wake-on-LAN packet: +
e");
            System.exit(1);
        }
    	}

    }

    private static byte[] getMacBytes(String macStr) throws
IllegalArgumentException {
        byte[] bytes = new byte[6];
        String[] hex = macStr.split("(\\:|\\-)");
        if (hex.length != 6) {
            throw new IllegalArgumentException("Invalid MAC
address.");
        }
        try {
            for (int i = 0; i < 6; i++) {
                bytes[i] = (byte) Integer.parseInt(hex[i], 16);
            }
        }
        catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid hex digit in
MAC address.");
        }
        return bytes;
    }


}

Any help in this matter would be highly appreciated. Thank you
 




 3 Posts in Topic:
Problem with program exception in thread error
christopher_board@[EMAIL   2008-02-07 13:55:05 
Re: Problem with program exception in thread error
Knute Johnson <nospam@  2008-02-07 14:47:15 
Re: Problem with program exception in thread error
Lew <lew@[EMAIL PROTEC  2008-02-07 20:21:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 3:40:18 CDT 2008.