Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:00:57+00:00 2026-06-02T09:00:57+00:00

I am testing tuProlog in Android. I have an Activity TuProlog, class Parser to

  • 0

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

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 => SpyEvent Occured ** " );
    System.out.println("** onSpy => SpyEvent Occured ** \n ");
    myResult =  e.getMsg();
}


@Override
public void onOutput(OutputEvent e) {
    // TODO Auto-generated method stub
     Log.d("TAG", "** LG'd: onOutput => OutputEvent Occured ** " );
        System.out.println("** onOutput => OutputEvent Occured ** \n ");
        myResult =  e.getMsg();

}


@Override
public void onWarning(WarningEvent e) {
    // TODO Auto-generated method stub
    Log.d("TAG", "** LG'd: onWarning => WarningEvent Occured ** " );
    System.out.println("** onWarning => WarningEvent Occured ** \n ");
    myResult = e.getMsg();
}
}

Data.pl

likes(john,mary).
likes(mary,wine).

Here is my logcat output, I dont know about System.err

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.<init>(FileInputStream.java:80)
04-15 18:51:25.484: W/System.err(23813): at java.io.FileInputStream.<init>(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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:01:06+00:00Added an answer on June 2, 2026 at 9:01 am

    I’ve done it before and have posted the (very, very beta proof of concept only) source code for interrogation, pls see below.

    To download the Eclipse (Helios) project Source Code, goto: versaggi.biz, Downloads Adrea, TuProlog Dev Project, Eclipse (Helios) Java Source Project, and finally to TuProlog Android Eclipse Porject Source. That should get you started. Please keep in mind that this is proof of concept code ONLY and is will be completely rewritten before the final version is released. Given that, it does work well enough for you to get some insights into how I did what I did. If you want any assistance at all just contact me directly and I’ll be glad to help you along. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Testing environment: netbeans7.11 + glassfish 3.11 here is the jsp, class code: <%@page contentType=text/html
Testing out someone elses code, I noticed a few JSP pages printing funky non-ASCII
During testing, I'm stuck with testing a piece of code that receives a list
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
For testing purposes I have and SSL certificate set up on a dev site
For testing I have 1 isolated page - no masters, controls, …. My sessions
Testing can be mainly classified into manual and automated testing. With regard to this
For testing I used a Console application with the following source code: public string
For testing purposes of a RandomGen -reliant function I need a RandomGen instance which
while testing with different version of g++, the following problem came up template<class bra>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.