java - String Palindrome Program -


i created string palindrome program, getting nullpointer exception.

here code have written:

public class javaapplication2 {      /**      * @param args command line arguments      */     char c[]={'i','c','i','c','i'};     string s = new string(c);     string s1=null;     int i,j;     char c1[];     public static void main(string[] args) {         //todo code application logichere          javaapplication2 ja=new javaapplication2();         ja.palindrome();         ja.ans();         boolean b1= ja.ans();         system.out.println(b1);     }      public void palindrome()     {         for(i=s.length()-1,j=0;i>=0;i--)         {             c1[j]=s.charat(i);             j++;         }     }      public boolean ans()     {         string s2= new string(c1);         if(s2.equals(s))         {             return true;         }         else             return false;      } } 

i can't figure out how deal , why error occuring.

the problem char c1[]; not inizalized. therefore line give nullpointer:

string s2 = new string(c1); 

inizalized variable:

char c1[] = {}; 

now nullpointer gone, thats not final version, need fill logic.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo