我有以下代码:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.ui.DebugUITools;
public class Main {
public static void main(String... strings) throws IOException {
try {
String path = "E:\\Java\\Projects\\.metadata\\.plugins\\org.eclipse.debug.core\\.launches\\MedicineFrame.launch";
ILaunchManager launchManager = DebugPlugin.getDefault()
.getLaunchManager();
ILaunchConfigurationType type = launchManager
.getLaunchConfigurationType(ILaunchManager.RUN_MODE);
ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(
null, path);
workingCopy.setAttribute("PATH_MY", path);
ILaunchConfiguration configuration = workingCopy.doSave();
DebugUITools.launch(configuration, ILaunchManager.RUN_MODE);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
实际上,我只想运行绝对路径定义的文件中指定的启动配置。我收到一个 NPE,因为 DebugPlugin.getDefault() 返回 null。我该怎么办?我发现了很多类似的例子,但没有一个是关于 NPE 的,就像在我之前没有人得到它一样。