java.lang.NoClassDefFoundError 或 Caused by: java.lang.ClassNotFoundException

下面舉個例子,分析解決:

Exception in thread "main" java.lang.NoClassDefFoundError: freemarker/template/TemplateNotFoundException

    at com.luminal.greendao.daogenerator.DaoMaker.main(DaoMaker.java:16)

Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateNotFoundException

    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

    ... 1 more    

Process finished with exit code 1

首先我們一看意思就是沒有找到類的異常,像這種情況:要麼缺少jar包 或 包名寫錯,才找不到類。於是我們先要看報錯位置,它所在的類是否要引入此包類,沒有的話就有可能是jar包沒有引入其他相應的jar包而報錯。

錯誤定位行爲16,而DaoMaker類也並沒有引入“freemarker”相關的jar包,

於是我command點擊DaoGenerator去看它的源碼,搜索關鍵字“freemarker”,找到 “ import freemarker.template.TemplateNotFoundException; ” ,很顯然是項目引入的jar包裏面缺少引入的jar包

然後我們找到“freemarker”相關的jar包即可。

找到以前實踐成功的jar包,Reveal in Finder,複製到當前項目的libs目錄下,Add as Library即可

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章