使用SVN工具包无法将文件添加到存储库,以下代码抛出java.lang.NullPointerException

时间:2012-01-11 04:20:41

标签: java eclipse svnkit

我无法使用编辑器在存储库中添加任何文件,它会在行java.lang.NullPointerException处抛出editor.addFile(textfile, null, -1);例外

try {
    url = "https://XXX.yyy.zzzz";
    SVNRepository repository = null;
    String name = "testuser";
    String password = "testuserpassword";
    repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password);
    repository.setAuthenticationManager(authManager);
    System.out.println(repository.getLatestRevision());

    SVNClientInterface client = SVNClientImpl.newInstance();
} catch (Exception e) {
    System.out.println("error");
}               

try { 
    ISVNEditor editor = repository.getCommitEditor("This is a log message.", new CommitMediator()); 

    editor.openRoot(-1); 
    System.out.println("in DAV");
    editor.addFile(textfile, null, -1);
    editor.addFile("file1.txt", null, -1);       
    editor.applyTextDelta("file1.txt", null); 
    OutputStream os=null;
    os.close(); 
    editor.textDeltaEnd(file1.txt); 
    editor.closeFile(file1.txt, null); 
    editor.closeEdit(); 
} catch(Exception e) {
    System.out.println(e);
}

1 个答案:

答案 0 :(得分:0)

editor.addFile(textfile, null, -1);

什么是textfile

OutputStream os=null;
os.close();

可能想要考虑那里发生的事情。