1

I have a program in java which changes password for a user, if changed then a messagebox appears stating its successful, and if not able to change then a messagebox appears stating not successful.

This program works successfully on Windows 8 system but when run on Windows XP it does not give the output. Instead it gives a null pointer exception when it compares the strings.

if (output.equals("System error 5 has occurred."))

The following is the code that I am using:

import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

public class SystemDemo 
{
    public static void infoBox(String infoMessage, String titleBar)
    {
        JOptionPane.showMessageDialog(null, infoMessage, "Message: " + titleBar, JOptionPane.INFORMATION_MESSAGE);
    }

    public static void main(String[] args) 
    {
        try
        {
            Process p=Runtime.getRuntime().exec("net user ins 1234");
            InputStream stderr=p.getErrorStream(); 
            InputStreamReader isr=new InputStreamReader(stderr);
            BufferedReader br=new BufferedReader(isr);
            String output = br.readLine(); 
            if (output.equals("System error 5 has occurred."))
            {
                SystemDemo.infoBox("run with valid admin credentials", "Wrong Input");
            }
            else
            {
                SystemDemo.infoBox("Password changed Successfully", "Success");
            }
        }
        catch(IOException e1) {} 
    }
}

Java is a Platform Independent Language, then why is it not running on Windows XP???

jmatula
  • 38
  • 4
ins
  • 11
  • 3
  • 2
    There are a number of things to check. **1)** Are you running the same version of java on both OS's. **2)** Do XP and Windows8 report the error using the exact same syntax? – RiggsFolly Mar 31 '15 at 14:12
  • According to http://stackoverflow.com/questions/14474747/executing-a-net-use-command/14475049#14475049 `Runtime.exec` runs on a different process that you need to wait for – chancea Mar 31 '15 at 14:24
  • @RiggsFolly 1) yeah I have the same version of java on both win8 and win xp.. Does the version affect the execution of the program?. 2) The same code is run on both the systems and the program is successfully executed on win8 but I get an error on win xp. – ins Apr 01 '15 at 13:11
  • So check the actual error message you get from the XP machine is exactly the same as it is from WIN8. Maybe there is a minor difference. Afterall you are checking a piece of text not a numeric return code – RiggsFolly Apr 01 '15 at 13:53
  • yeah checked the error message. it gives the same error "System error 5 has occurred." in both the systems. I also tried checking the output of all the variables individually, here the value of the variable 'output' itself is null. Therefore the null pointer exception is given when is tries to compare the strings. – ins Apr 01 '15 at 14:42

0 Answers0