1

我试过这样的事情:

public boolean createTestProject(String projectName, IProject testedProject, int apiLevel){
        NewProjectWizardState mValues = new NewProjectWizardState(Mode.TEST);
        mValues.projectName = projectName;
        if(testedProject != null){
            mValues.testedProject = testedProject;
            mValues.testingSelf = false;
            mValues.useExisting = false;
        }
        else{
            mValues.testingSelf = true;
            mValues.useExisting = false;
        }
        mValues.minSdk = "1.5";
        mValues.minSdkModifiedByUser = true;
        mValues.useDefaultLocation = true;
        mValues.projectLocationModifiedByUser = false;
        mValues.createActivity = false;
        mValues.activityName = "sf";
        mValues.applicationName = "sf";
        mValues.packageName = "sf";
        NewProjectCreator creator = new NewProjectCreator(mValues, getContainer());

        return creator.createAndroidProjects();
    }

但它会在 com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectCreator.createEclipseProject(NewProjectCreator.java:561) 处引发 NullPointerException。我检查了那个文件(可能是旧版本),这一行是空的。我错过了什么?

编辑:好的,我解决了。我错过了几件事。现在它可以工作了,它甚至可以创建 android 项目(不是测试):

public IProject createProject(String projectName, IProject testedProject,
    boolean testMode, int apiLevel, IWizardContainer container,
    Type type, String packName) throws Exception {
    NewProjectWizardState mValues;
    if (testMode) {
        mValues = new NewProjectWizardState(Mode.TEST);
    } else {
        mValues = new NewProjectWizardState(Mode.ANY);
    }
    mValues.projectName = projectName;
    mValues.projectNameModifiedByUser = true;
    mValues.applicationName = capitalize(mValues.projectName);
    mValues.testApplicationName = projectName;
    mValues.createActivity = false;
    mValues.testedProject = testedProject;
    mValues.minSdk = apiLevel;
    mValues.updateSdkTargetToMatchMinSdkVersion();
    String value = Platform.getLocation().append(mValues.projectName)
            .toString();
    value = TextProcessor.process(value);
    mValues.projectLocation = new File(value);
    mValues.packageName = "com.example.android.apis.test";
    if (testedProject != null) {
        mValues.testProjectName = projectName;
        mValues.packageName = String.format("%1$s.test",
            Helper.getPackageName(testedProject));
        mValues.createPairProject = false;
        mValues.testTargetPackageName = Helper
            .getPackageName(testedProject);
    }
    if (testedProject == null && testMode) {
        mValues.createPairProject = false;
        mValues.testProjectName = projectName;
        mValues.testTargetPackageName = "com.example.android.apis";
    }
    if (packName != null && packName.length > 0) {
        mValues.packageName = packName;
    }
    NewProjectCreator creator = new NewProjectCreator(mValues,
            container);

    creator.createAndroidProjects();
    return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
4

0 回答 0