Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[pde-dev] NullPointerException when creating IProgressMonitor!!!

Hi,as you know,eclipse provides us a class "org.eclipse.ant.core.AntRunner",with this class,we can run ant tasks from our program.To make a quick start,i just added all the needed jar files to my project,and i wrote a class to create an IProgressMonitor instance and to run a simple ant task,the code is below:

package robin.task1;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.ant.core.AntCorePlugin;
import org.eclipse.core.runtime.IProgressMonitor;

import java.util.Hashtable;
/**
* @author Robin Zou
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class IProgressMonitorCreator extends Task
{
public IProgressMonitor create()
{
IProgressMonitor monitor=null;
try
{
monitor=(IProgressMonitor)getProject().getReferences().
get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
}
catch(BuildException be)
{
be.printStackTrace();
}
return monitor;
}
}

But every time,there is a NullPointerException which indicates that the "getProject()" returns a null object.I don't know why.is it that such code only works with plugin,not general java project code?Please help!
Best Regards:)






  已有1亿用户选择了网易邮箱,你呢?
  网易163免费邮已全面升级至2000兆超大空间,支持收发超大附件!


Back to the top