check the array initialization ...
char[] newName = null;
probably you would like to try something like
char[] newName = char[20]; or
char[] newName = new char[arr.length];
by the way, your code will only generate the newName from your last argument
(as the loop is pointing to the last argument).
maybe you need to revisit the homework again to achieve the correct
objective.
thank you.
2009/1/13 Ahmet Süreyya Rifaioğlu <[email protected]>
> Hi members,
> I wrote the homework of Built in Classes, but there is a problem in my
> function(Exception in thread "main" java.lang.NullPointerException at
> BuiltinClasses.generateNewName(BuiltinClasses.java:35) at
> BuiltinClasses.main(BuiltinClasses.java:27)). Here is my code.
> public class BuiltinClasses {
>
> /**
> * @param args the command line arguments
> */
> public static void main(String[] args) {
> // TODO code application logic here
> if(args.length<3)
> {
> System.out.println("You must enter at least three names!!!");
> }
> System.out.println("Names of the family members are ");
> for(int i=0;i<args.length;i++)
> {
> System.out.println(args[i]);
> }
> generateNewName(args);
> }
> public static void generateNewName(String arr[])
> {
> System.out.println("The new name is ");
> char[] newName = null;
> for (int i=0;i<arr.length;i++)
> {
> newName[i]=arr[i].charAt(1);
> System.out.print(newName[i]);
> }
> }
>
> }
>
> Regards
>
> >
>
--
Abu Sufian Mamat
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---