I'm new to java, and I've been trying to produce code reversing a string using recursion. I've spent about a day thinking of solutions as to why it's not working as expected, to no avail. At this point in my debugging, the code compiles, but when executing, it produces a "Exception in thread "main" java.lang.NullPointerException" error. Can you tell me what's causing this?
class RevStr {
String str,Final;
RevStr(String string) {
String str=string;
String Final="";
}
void Reverse() {
String str=str;
int count=1;
if(str.length()==1) {
Final+=str;
}
else {
String last=str.substring(str.length()-1);
Final+=last;
str=str.substring(0,(str.length()-1));
Reverse();
}
}
String RetRev() {
return Final;
}
}
class ReverseString {
public static void main(String args[]) {
RevStr name=new RevStr("Cameron");
name.Reverse();
String rev=name.RetRev();
//System.out.println(rev);
}
}