Hi guys, my first post over here, I hope somebody can help me, thanks in advantage and sorry for my English.
I'm creating this simple program that read the information from a cmd variable and I want to add some If and Else (If this contains the "x" string, then do this, else, ....)
This is my code:
import java.io.*; public class ugh { public static void main(String args[]) throws IOException, InterruptedException { String line; CharSequence look = "108"; Process p=Runtime.getRuntime().exec("cmdkey /list"); p.waitFor(); BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); line=reader.readLine(); while(line!=null) { line=reader.readLine(); if(line.contains(look)) { System.out.println("Yes"); } } } }
I get the expected behavior but followed by this error:
Yes
Exception in thread "main" java.lang.NullPointerException
at ugh.main(ugh.java:24)