no158
asked on
NullPointerException
> NullPointerException:
at Expand.fib(Expand.java:53) = sorter[counter] = (sorter[counter] + filename.charAt(i));
at Expand.main(Expand.java:16 ) = sorter1 = fib("header.h");
at sun.reflect.NativeMethodAc cessorImpl .invoke0(N ative Method)
at sun.reflect.NativeMethodAc cessorImpl .invoke(Un known Source)
at sun.reflect.DelegatingMeth odAccessor Impl.invok e(Unknown Source)
at java.lang.reflect.Method.i nvoke(Unkn own Source)
import java.io.*;
import java.util.*;
import java.lang.*;
public class Expand {
private static String word;
private static Scanner s;
private static String holder;
private static String a;
private static final String pattern = "#include";
private static String filename = "";
private static String [] sorter;
private static String [] sorter1;
public static void main(String[] args) throws IOException {
sorter1 = fib("header.h");
/*
* Recursion method here
*/
System.out.println(sorter1 );
}
public static String getToken() {
word = s.next();
word = word.replaceAll("[\\*/\"]" , "");
return word;
}
public static String [] fib(String file) throws IOException {
s = new Scanner(new BufferedReader(new FileReader(args[0]+file))) ;
while (s.hasNext()) {
holder = holder + (a=getToken());
if(a.matches(pattern)) {
if(filename == null) {
filename = getToken();
}
if(filename != null) {
filename = filename + " " + getToken();
//System.out.println(filen ame);
}
}
}
int counter = 0;
for(int i = 0; i < filename.length(); i++) {
if(filename.charAt(i) == ' '){
counter++;
}
if(filename.charAt(i) != ' ') {
sorter[counter] = (sorter[counter] + filename.charAt(i));
}
}
s.close();
return sorter;
}
}
at Expand.fib(Expand.java:53)
at Expand.main(Expand.java:16
at sun.reflect.NativeMethodAc
at sun.reflect.NativeMethodAc
at sun.reflect.DelegatingMeth
at java.lang.reflect.Method.i
import java.io.*;
import java.util.*;
import java.lang.*;
public class Expand {
private static String word;
private static Scanner s;
private static String holder;
private static String a;
private static final String pattern = "#include";
private static String filename = "";
private static String [] sorter;
private static String [] sorter1;
public static void main(String[] args) throws IOException {
sorter1 = fib("header.h");
/*
* Recursion method here
*/
System.out.println(sorter1
}
public static String getToken() {
word = s.next();
word = word.replaceAll("[\\*/\"]"
return word;
}
public static String [] fib(String file) throws IOException {
s = new Scanner(new BufferedReader(new FileReader(args[0]+file)))
while (s.hasNext()) {
holder = holder + (a=getToken());
if(a.matches(pattern)) {
if(filename == null) {
filename = getToken();
}
if(filename != null) {
filename = filename + " " + getToken();
//System.out.println(filen
}
}
}
int counter = 0;
for(int i = 0; i < filename.length(); i++) {
if(filename.charAt(i) == ' '){
counter++;
}
if(filename.charAt(i) != ' ') {
sorter[counter] = (sorter[counter] + filename.charAt(i));
}
}
s.close();
return sorter;
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well you guys help me get on track but there seems to be a problem still with the output
the program will pull up the two file names, null is in the name, how do i get that out
nullfilename1
nullfilename2
I think it with this line of code that things are getting messed up
if(sorter1[i].charAt(i) != ' ') {
Since ' ' does not = null and you can't have null == char, i'm not sure what will work
Suggestions?
the program will pull up the two file names, null is in the name, how do i get that out
nullfilename1
nullfilename2
I think it with this line of code that things are getting messed up
if(sorter1[i].charAt(i) != ' ') {
Since ' ' does not = null and you can't have null == char, i'm not sure what will work
Suggestions?
if(sorter1[i].charAt(i) != '')
try this one
try this one
ASKER
Error: empty character literal
Error: unclosed character literal
Error: unclosed character literal
:-)
I think you are trying to do something illegal here.
In method Expand.fib(String) variable "args" is not defined(So basically this should not compile).
Can you describe what is the goal of this file, maybe I can think of better solution.