我的朋友和我最近感到无聊,所以我创建了一个程序,使用Jsoup,从Redbox网站中选择一部随机电影供我们观看。这个程序在我的IDE(Eclipse Luna)中运行良好,但是当我导出它时,运行时出现以下错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Entities.java:20)
at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:221)
at org.jsoup.nodes.Document.<init>(Document.java:18)
at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:27)
at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:40)
at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:54)
at org.jsoup.parser.Parser.parseInput(Parser.java:30)
at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:120)
at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:51
7)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:168)
at RedboxRoulette.InfoGrabber.main(InfoGrabber.java:19)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at org.jsoup.nodes.Entities.loadEntities(Entities.java:151)
at org.jsoup.nodes.Entities.<clinit>(Entities.java:135)
... 11 more
该计划:
public class InfoGrabber {
public static void main(String... args) throws IOException{
String url = "http://www.redbox.com/movies/";
System.out.println("Loading redbox.com...");
ArrayList<String> movieList = new ArrayList<String>();
//Gets website using Jsoup
Document doc = Jsoup.connect(url).get();
//Finds the movies
Elements movies = doc.select(".box-wrapper");
//Adds them to a list
for (Element movie : movies) {
String name = movie.attr("name");
movieList.add(name);
}
//Picks a random movie
int movieNumber = (int) (Math.random()*movieList.size());
String finalMovie = movieList.get(movieNumber);
System.out.println("Movie: " + finalMovie);
}
}
我是Jsoup的初学者,我还在学习java,但是看看那里的所有教程,这似乎是事情应该有效的方式。
我尝试使用eclipse中的三个不同的导出选项将其导出为可运行的jar文件,但每个都提供相同的结果。我也尝试手动创建jar文件但是,就像eclipse制作的jar文件一样,会抛出错误。
非常感谢任何帮助。
更新: 在镜像评论中找到的过程后,我现在收到此错误:
Missing attributes for JarRsrcLoader in Manifest (Rsrc-Main-Class, Rsrc-Class-Path)
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:46)
eclipse创建的清单文件:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ jsoup-1.7.3.jar
Class-Path: .
Rsrc-Main-Class: RedboxRoulette.InfoGrabber
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
答案 0 :(得分:0)
我正在使用Eclipse Kepler
。
我用一个班级做了一个新项目。我粘贴了你的代码。
通过右键单击项目,我将jsoup-1.7.3.jar
包括在内
选择Properties->Java Build Path->Libraries(tab)->Add External JARs
我通过右键单击项目导出了jar
选择Export->Runnable JAR File->Select 'Package required libraries into generated JAR'.
打开cmd转到jar的位置并执行
java -jar <name of the jar>
它工作正常。
对于java命令,您首先要设置环境变量。