title: Running prolog in Android
body: <p>I am testing tuProlog in Android. I have an Activity TuProlog, class Parser to interact with prolog code and data.pl which contains prolog code. I can run it fine as a java project with output to console but I am facing trouble doing so as an Android project. For Android I get FileNotFoundException even though my file data.pl is copied in root of project, inside src and inside my package. I just want to fetch the result as string and display my result in TextView. Here are my codes</p>
  
  <pre><code>public class TuProlog extends Activity implements OnClickListener{
  
  TextView tv;
  Button b1;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      tv = (TextView)findViewById(R.id.label);
      b1 = (Button)findViewById(R.id.button1);
      b1.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View v) {
      Parser custom = new Parser();
      String result = custom.parse();
      tv.setText(result);
  }   
  }
  
  
  public class Parser {
  
  Prolog engine;
  PrintStream orgStream   = System.out;
  
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintStream psout = new PrintStream(baos, Boolean.TRUE); // Using autoFlush
  String myResult ;
  
  public String parse()
  {
      engine  = new Prolog();
      try{
          Theory t = new Theory(new FileInputStream("data.pl"));
          try{
              engine.setTheory(t);
              try{
                  SolveInfo answer = engine.solve("likes(john,X).");
                  try{
                      Term derivative = answer.getTerm("X");
                      return myResult;;
                  }
                  catch (NoSolutionException e){
                      e.printStackTrace();
                  }
                  catch (UnknownVarException e){
                      e.printStackTrace();
                  }
              }
              catch (MalformedGoalException e){
                  e.printStackTrace();
              }
          }
          catch (InvalidTheoryException e){
              e.printStackTrace();
          }
      } 
      catch (FileNotFoundException e){
          e.printStackTrace();
      }
      catch (IOException e){
          e.printStackTrace();
      }
      return null;
  }
      @Override
  public void onSpy(SpyEvent e) {
      // TODO Auto-generated method stub
      Log.d("TAG", "** LG'd onSpy =&gt; SpyEvent Occured ** " );
      System.out.println("** onSpy =&gt; SpyEvent Occured ** \n ");
      myResult =  e.getMsg();
  }
  
  
  @Override
  public void onOutput(OutputEvent e) {
      // TODO Auto-generated method stub
       Log.d("TAG", "** LG'd: onOutput =&gt; OutputEvent Occured ** " );
          System.out.println("** onOutput =&gt; OutputEvent Occured ** \n ");
          myResult =  e.getMsg();
  
  }
  
  
  @Override
  public void onWarning(WarningEvent e) {
      // TODO Auto-generated method stub
      Log.d("TAG", "** LG'd: onWarning =&gt; WarningEvent Occured ** " );
      System.out.println("** onWarning =&gt; WarningEvent Occured ** \n ");
      myResult = e.getMsg();
  }
  }
  </code></pre>
  
  <p>Data.pl</p>
  
  <pre><code>likes(john,mary).
  likes(mary,wine).
  </code></pre>
  
  <p>Here is my logcat output, I dont know about System.err</p>
  
  <pre><code>04-15 18:51:25.480: W/System.err(23813): java.io.FileNotFoundException: /data.pl (No such file or directory)
  04-15 18:51:25.484: W/System.err(23813): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
  04-15 18:51:25.484: W/System.err(23813): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
  04-15 18:51:25.484: W/System.err(23813): at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:80)
  04-15 18:51:25.484: W/System.err(23813): at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:132)
  04-15 18:51:25.484: W/System.err(23813): at com.tuprolog.alicia.Parser.parse(Parser.java:32)
  04-15 18:51:25.484: W/System.err(23813): at com.tuprolog.alicia.TuProlog.onClick(TuProlog.java:51)
  04-15 18:51:25.484: W/System.err(23813): at android.view.View.performClick(View.java:2485)
  04-15 18:51:25.484: W/System.err(23813): at android.view.View$PerformClick.run(View.java:9080)
  04-15 18:51:25.484: W/System.err(23813): at android.os.Handler.handleCallback(Handler.java:587)
  </code></pre>