0

我有以下代码会给出 rdf 结果......但我遇到的问题是找不到方法......

package corese;

import static org.junit.Assert.assertEquals;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

 import com.corese.andro.R;

 import fr.inria.acacia.corese.api.IDatatype;
 import fr.inria.acacia.corese.exceptions.EngineException;
 import fr.inria.edelweiss.kgram.core.Mappings;
 import fr.inria.edelweiss.kgraph.core.Graph;
 import fr.inria.edelweiss.kgraph.query.QueryProcess;
 import fr.inria.edelweiss.kgtool.load.Load;
 import fr.inria.edelweiss.kgtool.print.RDFFormat;
 import fr.inria.edelweiss.kgtool.print.ResultFormat;


  public class andro extends Activity implements View.OnClickListener{
  /** Called when the activity is first created. */

Graph graph;
Load ld;
Mappings map;
QueryProcess exec;
ResultFormat f;
RDFFormat f3;

Button runbtn;
Button clearbtn;
Button test;
Button triple;
EditText et1;
TextView tv1;

@Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.query);


    clearbtn = (Button) findViewById(R.id.clear) ;
    runbtn = (Button) findViewById(R.id.run);
   test = (Button) findViewById(R.id.test);
    triple = (Button) findViewById(R.id.rdf);

   tv1 = (TextView) findViewById(R.id.output); 
   et1 = (EditText) findViewById(R.id.input);


   clearbtn.setOnClickListener(new OnClickListener(){
       public void onClick(View v){
           et1.setText("");
           tv1.setText("");


       }
    });
      test.setOnClickListener(new OnClickListener(){
     //runbtn.setOnClickListener(new OnClickListener(){
      public void onClick(View v){

   /*     String op = et1.getText().toString();   
      tv1.setText(op);  
   */
   // graph = Graph.create();    
     graph = Graph.create(true);

      ld = Load.create(graph);
      ld.load("/path/Roy/Home/DownLoad/foaf.rdf");
     // ld.load("dataset.rdf");
     /* 
      try {
        ld.loadWE("dataset.rdf");
    } catch (LoadException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
     */ 
     // String query = null;
      Mappings map = null;


      String query1 = "select more * (kg:similarity() as ?sim) where {" +
            "?x rdf:type c:Engineer " +
            "?x c:hasCreated ?doc " +
            "?doc rdf:type c:WebPage" +
            "}" +
            "order by desc(?sim)";

     exec = QueryProcess.create(graph);
     query1 = et1.getText().toString();
      try {
         map = exec.query(query1);
        IDatatype dt = getValue(map, "?sim");
        double sim = dt.getDoubleValue();

        assertEquals("Result", sim, .84, 1e-2);
            } catch (EngineException e) {
            // TODO Auto-generated catch block
            assertEquals("Result", true, e);
            e.printStackTrace();
        }
         f = ResultFormat.create(map);
        // f3 = TripleFormat.create(map);
         String f2 = f.toString();
         tv1.setText(f2);   
        // System.out.println(f);           

         }  
      });

   }  

protected IDatatype getValue(Mappings map2, String string) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}
  }

错误

05-14 09:50:47.364: I/dalvikvm(798): Could not find method  org.junit.Assert.assertEquals, referenced from method corese.andro$2.onClick
05-14 09:50:47.364: W/dalvikvm(798): VFY: unable to resolve static method 10020: Lorg/junit/Assert;.assertEquals (Ljava/lang/String;DDD)V
05-14 09:50:47.364: D/dalvikvm(798): VFY: replacing opcode 0x77 at 0x0059
05-14 09:50:47.364: I/dalvikvm(798): Could not find method org.junit.Assert.assertEquals, referenced from method corese.andro$2.onClick
05-14 09:50:47.364: W/dalvikvm(798): VFY: unable to resolve static method 10022: Lorg/junit/Assert;.assertEquals (Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
05-14 09:50:47.364: D/dalvikvm(798): VFY: replacing opcode 0x71 at 0x007b
05-14 09:50:47.364: D/dalvikvm(798): VFY: dead code 0x005c-0073 in Lcorese/andro$2;.onClick (Landroid/view/View;)V
05-14 09:50:47.374: D/dalvikvm(798): VFY: dead code 0x007e-0081 in Lcorese/andro$2;.onClick (Landroid/view/View;)V
05-14 09:50:49.004: W/System.err(798): log4j:WARN No appenders could be found for logger (fr.inria.edelweiss.kgtool.load.Load).
05-14 09:50:49.004: W/System.err(798): log4j:WARN Please initialize the log4j system properly.
05-14 09:50:49.004: W/System.err(798): log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
05-14 09:50:49.104: D/AndroidRuntime(798): Shutting down VM
05-14 09:50:49.104: W/dalvikvm(798): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-14 09:50:49.104: E/AndroidRuntime(798): FATAL EXCEPTION: main
05-14 09:50:49.104: E/AndroidRuntime(798): java.lang.NullPointerException
05-14 09:50:49.104: E/AndroidRuntime(798):  at corese.andro$2.onClick(andro.java:101)
05-14 09:50:49.104: E/AndroidRuntime(798):  at android.view.View.performClick(View.java:2485)
05-14 09:50:49.104: E/AndroidRuntime(798):  at android.view.View$PerformClick.run(View.java:9080)
05-14 09:50:49.104: E/AndroidRuntime(798):  at android.os.Handler.handleCallback(Handler.java:587)
05-14 09:50:49.104: E/AndroidRuntime(798):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 09:50:49.104: E/AndroidRuntime(798):  at android.os.Looper.loop(Looper.java:130)
05-14 09:50:49.104: E/AndroidRuntime(798):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-14 09:50:49.104: E/AndroidRuntime(798):  at java.lang.reflect.Method.invokeNative(Native Method)
05-14 09:50:49.104: E/AndroidRuntime(798):  at java.lang.reflect.Method.invoke(Method.java:507)
05-14 09:50:49.104: E/AndroidRuntime(798):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-14 09:50:49.104: E/AndroidRuntime(798):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-14 09:50:49.104: E/AndroidRuntime(798):  at dalvik.system.NativeStart.main(Native Method)

有人可以解决为什么错误出现“找不到方法 org.junit.Assert.assertEquals .....”吗???

4

1 回答 1

0

看起来您的代码中有两个问题:

  1. android 找不到 JUnit 库。检查 JUnit 库是否位于名为的文件夹中libs,并且该库是否位于您的类路径中
  2. 有些东西在第 101 行抛出 NullPointer 异常。我怀疑

    IDatatype dt = getValue(map, "?sim");
    

正在返回 null 所以下一行

    double sim = dt.getDoubleValue();

正在抛出错误。

于 2012-05-14T10:21:00.627 回答