how can I solve a nullpointerexception java? [duplicate]

1

I'm having a problem with a java code. I use a .jar that I import into the class I want to program but the problem is that I get an error with a data type incompatibility when executing the code it throws an error of:

  

null pointer exception

The data type Element gives me problems. The problem is in the last assignment

    package extract;

    import java.io.FileInputStream;
    import java.io.InputStream;
    import org.jdom.Element;
    import pl.edu.icm.cermine.*;


    public class Extract {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws Exception{

     PdfNLMContentExtractor extractor= new PdfNLMContentExtractor();
     InputStream inputStream = new FileInputStream("/home/paul/cermine/sample2.pdf");
        Element result=extractor.extractContent(inputStream);
        System.out.println(result);


    }



    // TODO code application logic here
}

This is my java class in the result variable should store the metadata of the pdf that is passed in the address but on the contrary the result is:

    run:
     Exception in thread "main" java.lang.RuntimeException:     Uncompilable  source code - cannot find symbol
      symbol:   class Element
   location: class extract.Extract
at extract.Extract.main(Extract.java:28)
    
asked by Paul 08.05.2016 в 04:30
source

2 answers

1

Class pl.edu.icm.cermine.PdfNLMContentExtractor has been marked as deprecated . Instead, use pl.edu.icm.cermine.ContentExtractor . This is (for example):

ContentExtractor extractor = new ContentExtractor();
InputStream inputStream = new FileInputStream("/home/paul/cermine/sample2.pdf");
extractor.setPDF(inputStream);
String rawText = extractor.getRawFullText();
System.out.println(rawText);

You can also use the class pl.edu.icm.cermine.ExtractionUtils :

InputStream inputStream = new FileInputStream("/home/paul/cermine/sample2.pdf");
ContentExtractor extractor = new ContentExtractor();          
String rawText = ExtractionUtils.extractRawText(extractor.getConf(), inputStream);
System.out.println(rawText);

UPDATE

The extractTextAsNLM method of the ExtractionUtils class returns an instance of org.jdom.Element . It can be converted to XML string using an instance, but of org.jdom.output.XMLOutputter . That is:

InputStream inputStream = new FileInputStream("/home/paul/cermine/sample2.pd");
ContentExtractor extractor = new ContentExtractor();          
Element element = ExtractionUtils.extractTextAsNLM(extractor.getConf(), inputStream);
String xmlString = new XMLOutputter().outputString(element);
System.out.println(xmlString);
    
answered by 08.05.2016 / 18:15
source
0

I see you are using CERMINE, it is important to give more details, I can tell you that if you are using Netbeans simply delete the cache!

The cache is inside the folder:

USUARIO/.netbeans/var/cache/index

Linux

~/.cache/netbeans/${netbeans_version}/index/

Mac OS:

~/Library/Caches/NetBeans/${netbeans_version}/
    
answered by 08.05.2016 в 08:09