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???