2016-08-14 61 views
0

我想使用jsoup,因此我下載了jsoup-1.9.2.jar文件並將其移至Android Studio中的libs文件夾中。當我試圖建立的項目,我得到以下錯誤:使用Jsoup構建錯誤和致命異常

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. 

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.jsoup/jsoup/pom.xml File1: /Users/David/AndroidStudioProjects/Vertretungsplan2/app/libs/jsoup-1.9.2.jar File2: /Users/David/.gradle/caches/modules-2/files-2.1/org.jsoup/jsoup/1.9.2/5e3bda828a80c7a21dfbe2308d1755759c2fd7b4/jsoup-1.9.2.jar

我試過幾件事情建議各地的谷歌。

exclude 'org/jsoup/nodes/entities-full.xml' 
exclude 'org/jsoup/nodes/entities-full.properties' 
exclude 'META-INF/maven/org.jsoup/jsoup/pom.xml' 
exclude 'META-INF/maven/org.jsoup/jsoup/pom.properties' 
exclude 'org/jsoup/nodes/entities-base.properties' 
exclude 'org/jsoup/nodes/entities-base.xml' 

這讓Android Studio中成功地構建項目,但每當我嘗試使用jsoup我收到以下錯誤:我在的build.gradle排除這些文件

08-14 18:52:53.852 8200-8906/de.gymnasium_beetzendorf.vertretungsplan E/AndroidRuntime: FATAL EXCEPTION: IntentService[RefreshService] 
                        Process: de.gymnasium_beetzendorf.vertretungsplan, PID: 8200 
                        java.lang.ExceptionInInitializerError 
                         at org.jsoup.nodes.Entities.access$000(Entities.java:17) 
                         at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Entities.java:20) 
                         at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:371) 
                         at org.jsoup.nodes.Document.<init>(Document.java:18) 
                         at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:29) 
                         at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:42) 
                         at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:52) 
                         at org.jsoup.parser.Parser.parseInput(Parser.java:30) 
                         at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:136) 
                         at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:653) 
                         at org.jsoup.helper.HttpConnection.get(HttpConnection.java:217) 
                         at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.doStuff(RefreshService.java:252) 
                         at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.onHandleIntent(RefreshService.java:93) 
                         at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66) 
                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                         at android.os.Looper.loop(Looper.java:148) 
                         at android.os.HandlerThread.run(HandlerThread.java:61) 
                        Caused by: java.lang.NullPointerException: in == null 
                         at java.util.Properties.load(Properties.java:246) 
                         at org.jsoup.nodes.Entities.loadEntities(Entities.java:241) 
                         at org.jsoup.nodes.Entities.<clinit>(Entities.java:225) 
                         at org.jsoup.nodes.Entities.access$000(Entities.java:17)  
                         at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Entities.java:20)  
                         at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:371)  
                         at org.jsoup.nodes.Document.<init>(Document.java:18)  
                         at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:29)  
                         at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:42)  
                         at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:52)  
                         at org.jsoup.parser.Parser.parseInput(Parser.java:30)  
                         at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:136)  
                         at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:653)  
                         at org.jsoup.helper.HttpConnection.get(HttpConnection.java:217)  
                         at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.doStuff(RefreshService.java:252)  
                         at de.gymnasium_beetzendorf.vertretungsplan.RefreshService.onHandleIntent(RefreshService.java:93)  
                         at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)  
                         at android.os.Handler.dispatchMessage(Handler.java:102)  
                         at android.os.Looper.loop(Looper.java:148)  
                         at android.os.HandlerThread.run(HandlerThread.java:61)  

我不知道是什麼我必須這樣做才能解決這個問題,所以任何幫助表示讚賞。如果我的文章缺少任何信息,你們需要讓我知道。謝謝!

使用jsoup

Java代碼:

public void doStuff() { 
    String url = "http://gymnasium-beetzendorf.de/uorganisation/vplan.html"; 

    try { 
     Document document = Jsoup.connect(url).get(); 

     Elements div = document.select("div.content"); 
     Elements a = div.select("a"); 

     Log.i(MainActivity.TAG, "anzahl der links " + String.valueOf(a.size())); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 
+0

實際看到您的JSoup代碼會很有用。錯誤說'由...引起:java.lang.NullPointerException:in == null',我認爲它是一個InputStream? –

+0

你可能可以使用Maven依賴而不是JAR文件來避免第一個錯誤 –

+0

我編輯了上面的代碼。從我讀過的猿不是我的錯,而是因爲我放入build.gradle的排除語句。 – Crosswind

回答

1

你的搖籃錯誤,說明有那些JAR文件之間的衝突的重複文件,並且編譯搖籃依賴,你可能有這樣的在你的依賴。

compile 'org.jsoup:jsoup:1.9.2' 

因此,您不應該需要下載JAR文件或排除任何內容,您可以簡單地使用該庫。

相關問題