You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by subir bhaumik <su...@yahoo.co.in> on 2006/05/18 13:40:31 UTC

Taskdef NullPointerException

Hi
  
     I am trying to execute a simple java code for a build using
      Ant API rather than writing build.xml.When executing the code
  it throws NullPointerException for the line
  
  tinstaller.setClasspath(class_path); 
  
  in the code.
  It is for the class  "org.apache.tools.ant.taskdefs.Taskdef;"
  But for the other taskdefs e.g. Javac its O.K.
  Is there any problem to load classpath in Taskdef object?
  If not then where's the wrong with the code? 
  The Exception
  
  Exception in thread "main" java.lang.NullPointerException
          at org.apache.tools.ant.taskdefs.DefBase.setClasspath(DefBase.java:90)
          at Installer.main(Installer.java:35)
  
  Code
  
  
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.launch.Locator;
  import org.apache.tools.ant.taskdefs.Taskdef;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.types.Path;
  import com.izforge.izpack.ant.*;
  
  public class Installer  {
     
     public static void main(String args[]) {
              
              Project p = new Project();
              p.init();
              p.setName("Building");
              p.setDefault("installer") ;
              p.setBasedir(".");
              
              
               org.apache.tools.ant.types.Path class_path = new  org.apache.tools.ant.types.Path(p);             
               class_path.setPath("C:/Bishwakarma/BuildTemp/lib/standalone-compiler.jar");                          
               org.apache.tools.ant.taskdefs.Taskdef tinstaller = new  org.apache.tools.ant.taskdefs.Taskdef();
              tinstaller.setProject(p);
              tinstaller.setTaskName("izpack");
              
              tinstaller.setClasspath(class_path); 
              
              tinstaller.setClassname("com.izforge.izpack.ant.IzPackTask");
              tinstaller.execute();
              
          }
          
          
      }
  
  Any suggestion will be highly appreciated.
  
  Warm Regards
  Subir
				
---------------------------------
 Why was V. Sehwag warned by the BCCI? Share your knowledge on Yahoo! Answers India
 Send instant messages to your online friends - NOW

Re: Taskdef NullPointerException

Posted by Steve Loughran <st...@apache.org>.
subir bhaumik wrote:
> Hi
>   
>      I am trying to execute a simple java code for a build using
>       Ant API rather than writing build.xml.When executing the code
>   it throws NullPointerException for the line
>   
>   tinstaller.setClasspath(class_path); 
>   
>   in the code.
>   It is for the class  "org.apache.tools.ant.taskdefs.Taskdef;"
>   But for the other taskdefs e.g. Javac its O.K.
>   Is there any problem to load classpath in Taskdef object?
>   If not then where's the wrong with the code? 
>   The Exception
>   
>   Exception in thread "main" java.lang.NullPointerException
>           at org.apache.tools.ant.taskdefs.DefBase.setClasspath(DefBase.java:90)
>           at Installer.main(Installer.java:35)
>   

This exactly the kind of problem you will find the ant source so helpful 
for. Why not look at the line where the fault happened, work out what 
preconditions are not being met, and fix your program.

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org