Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cann‘t create a new epub files because of null pointer exception #125

Open
IceSakuraAzure opened this issue Dec 7, 2019 · 0 comments

Comments

@IceSakuraAzure
Copy link

IceSakuraAzure commented Dec 7, 2019

this is my code:

       EpubReader epubReader = new EpubReader();
       String filePath="src/example/test.epub";
       File file=new File(filePath);
       InputStream input = null ;
       input = new FileInputStream(file);
       Book book=epubReader.readEpub(input,"UTF-8");
       Spine spine = book.getSpine();
       List<SpineReference> spineReferences = spine.getSpineReferences();
       int i = 0;
       if (spineReferences != null && spineReferences.size() > 0) {
           System.out.println("Converting...");
           for (i = 0; i < spineReferences.size(); i++) {
           	dealResource(i,spineReferences.get(i).getResource());//change some text in every Resource  
   	    }
           System.out.println("Convert End,Total chapters:"+i);
       }else{
           System.out.println("EpubBook is null");
           System.exit(0);
       }               
       EpubWriter epubWriter = new EpubWriter();
       epubWriter.write(book, new FileOutputStream("src/example/test-t2s.epub"));

but when I run it,it throw a exception:

Convert End,Total chapters:751
Exception in thread "main" java.lang.NullPointerException
	at nl.siegmann.epublib.epub.PackageDocumentWriter.write(PackageDocumentWriter.java:36)
	at nl.siegmann.epublib.epub.EpubWriter.writePackageDocument(EpubWriter.java:112)
	at nl.siegmann.epublib.epub.EpubWriter.write(EpubWriter.java:53)
	at com.blue.core.convertMain.readbook(convertMain.java:75)
	at com.blue.core.convertMain.main(convertMain.java:49)

I don't know what happend.The test-t2s.epub is created,but it's broken.I use winRAR to open the epub files,and I find the content.opt only 0KB.WinRAR also warning me the content.opt is broken.
I want to know how to deal this problem.
My project depends this jar:
xmlpull-1.1.3.4d_b4_min.jar,epublib-core-3.1.3.jar,slf4j-api-1.7.2.jar,kxml2-2.3.0 and so on.I find these in Maven.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant