XMLCSPReader null point error

來源:互聯網
上載者:User

package queens;<br />import java.io.FileNotFoundException;<br />import java.io.IOException;<br />import org.sat4j.csp.SolverFactory;<br />import org.sat4j.reader.ParseFormatException;<br />import org.sat4j.reader.XMLCSPReader;<br />import org.sat4j.specs.ContradictionException;<br />import org.sat4j.specs.IProblem;<br />import org.sat4j.specs.ISolver;<br />import org.sat4j.specs.TimeoutException;<br />import org.sat4j.tools.ModelIterator;<br />public class Solver {<br />public static void main(String[] args) {<br />ISolver solver = SolverFactory.newDefault();<br />solver.setTimeout(360);<br />ModelIterator mi = new ModelIterator(solver);<br />XMLCSPReader reader = new XMLCSPReader(solver);<br />try {<br />if (reader != null)<br />reader.parseInstance("queens.xml");</p><p>IProblem problem = mi;<br />boolean unsat = true;<br />int count = 1;<br />while (problem.isSatisfiable()) {<br />unsat = false;<br />System.out.print("[" + count + "] ");<br />for (int i = 0; i < mi.model().length; i++) {<br />System.out.print(mi.model()[i] + " ");<br />}<br />System.out.println("");<br />// Call mi.model() to be sure you iterate to the next solution<br />mi.model();<br />count++;<br />}<br />if (unsat) {<br />System.out.println("Unsitisfied");<br />}<br />} catch (TimeoutException e) {<br />System.out.println("Timeout");<br />} catch (FileNotFoundException e) {<br />System.out.println("File not found");<br />} catch (IOException e) {<br />System.out.println("IO Exception");<br />} catch (ParseFormatException e) {<br />System.out.println("ParseFormatException");<br />} catch (ContradictionException e) {<br />System.out.println("Contradiction");<br />} catch (java.lang.NullPointerException e) {<br />System.out.print("NullPointerException");<br />}<br />}<br />}<br />

上面一段代碼不知道如何,一直報NULL Point Exception. 最後發現並非是代碼寫錯,而是因為jre不對。需要使用opensdk-1.6。

然後:

然後:

選中java-opensdk1.6 然後在外面選中剛才的JavaSE-1.6 :

 

有時候eclipse報出Class Not Found錯誤,可能是因為jar包應該放在external
jar的地方,但是你卻放錯了位置。添加external jar的地方。如果想添加external jars,需要在:

選中propertise,然後:

 

左邊add external jars, 添加需要的jar即可。

 

如果發生了selection dose not contain a main type, 那麼就需要重新建立一個Project,然後將你的檔案再重新匯入到新的Project中。或者粘貼過去。不知道為什麼eclipse經常發生這個錯誤。

上面一個XMLCSPReader的各種jar檔案需要在sat4j.org 上下載。該下模組的都下,但是注意版本號碼。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.