执行我的Android应用程序时出现此错误:
FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: com.hp.hpl.jena.query.Syntax
at com.example.testtvprg.QueryDBpedia.doInBackground(QueryDBpedia.java:56)
at com.example.testtvprg.QueryDBpedia.doInBackground(QueryDBpedia.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
这是我的AsyncTask类:我尝试连接到DBpedia并使用Jena Api发送查询,然后我在My MainActivity类上调用此类:
import java.util.ArrayList;
import android.os.AsyncTask;
import android.util.Log;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode;
public class QueryDBpedia extends AsyncTask <String, Void, Void>{ArrayList<String> list= new ArrayList<String>();
@Override
protected Void doInBackground(String... keyword) {
try{
String sparqlQuery="PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"SELECT DISTINCT ?film_URI \n" +
"WHERE {\n" +
"?film_URI rdf:type <http://dbpedia.org/ontology/Film> . \n" +
"} Limit 10" ;
String service= "http://dbpedia.org/sparql";
Query qur=QueryFactory.create(sparqlQuery,Syntax.syntaxARQ);
QueryExecution exec = QueryExecutionFactory.sparqlService(service,qur );
ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );
while ( results.hasNext() ) {
RDFNode s= results.next().get( "resource" );
list.add(s.toString());
}
} catch (Exception e) {
Log.e("Jena", "Error parsing data " + e.toString());
}
return null;
} }
以及我调用asyncTask类的函数下面:
public void ExplorButton( View v) throws InterruptedException, ExecutionException, IOException
{
QueryDBpedia qdb= new QueryDBpedia();
qdb.execute("");
}
我不明白问题出在哪里。请帮帮我。
答案 0 :(得分:0)
com.hp.hpl.jena.query.Syntax ,请尝试发布代码。