0

I want to import and list semantic web (owl) file's classes into the eclipse. I am new to eclipse hence i might make simple mistakes but in my position it is not that simple. Throughout some research i found a code which i have used in eclipse. I am getting an error on public void testAddAxioms() specifically on the void. The code is below:

public static void main(String[] args) {
 File file = new File("file:c:/Users/DTN/Desktop/Final SubmissionFilteringMechanism_Ontology.owl");
 OWLOntologyManager m = OWLManager.createOWLOntologyManager();
 OWLDataFactory f = OWLManager.getOWLDataFactory();
 OWLOntology o = null;
 public void testAddAxioms() {
 try {
 o = m.loadOntologyFromOntologyDocument(Ont_Base_IRI);
 OWLClass clsA = f.getOWLClass(IRI.create(Ont_Base_IRI + "ClassA"));
 OWLClass clsB = f.getOWLClass(IRI.create(Ont_Base_IRI + "ClassB"));
 OWLAxiom ax1 = f.getOWLSubClassOfAxiom(clsA, clsB);
 AddAxiom addAxiom1 = new AddAxiom(o, ax1);
 m.applyChange(addAxiom1);
 for (OWLClass cls : o.getClassesInSignature()) {
 EditText edit = (EditText) findViewById(R.id.editText1);
 edit.setText((CharSequence) cls);
 }
 m.removeOntology(o);
 } catch (Exception e) {
 EditText edit = (EditText) findViewById(R.id.editText1);
 edit.setText("Not successfull");
 }
 }
}
MrMike
1,5402 gold badges17 silver badges24 bronze badges
asked Mar 2, 2014 at 19:47
5
  • You can't have a void in your main method. Commented Mar 2, 2014 at 19:55
  • 3
    The compiler is complaining because you were trying to define your "public void testAddAxioms" method inside of the main method. In Java, methods do not nest. Commented Mar 2, 2014 at 19:55
  • Java does not support "directly" nested methods Commented Mar 2, 2014 at 19:55
  • 1
    Use new File("c:/Users/D... without full URL syntax. Commented Mar 2, 2014 at 19:58
  • Try to write your testAddAxioms method outside the main function. Commented Mar 2, 2014 at 20:02

2 Answers 2

3

You can't declare a method inside of another method. That's essentially what you're doing inside of main.

Move your declaration of testAddAxioms outside of main, as such:

public static void main(String[] args) {
 // code omitted for brevity
}
public void testAddAxioms() {
 // code omiited for brevity
}
answered Mar 2, 2014 at 20:12
Sign up to request clarification or add additional context in comments.

Comments

1

To call your testAddAxioms() method you need to first declare it outside your main() method. It can be in the same class, or in a new class.

public class YourClass {
 public static void main(String[] args) {
 File file = new File("...");
 OWLOntologyManager m = OWLManager.createOWLOntologyManager();
 OWLDataFactory f = OWLManager.getOWLDataFactory();
 OWLOntology o = null;
 // removed your method from here
 }
 public void testAddAxioms() {
 ...
 }
}

To call it (from the same place where you had placed it), you will have to change its declaration to accept the types you are sending to it:

public void testAddAxioms(OWLOntology o, OWLOntologyManager m, OWLDataFactory f) { ...}

And then, in your main() method, to instantiate an object of your class to be able to call it.

YourClass obj = new YourClass();
obj.testAddAxioms(o, m, f);

Another way to call it is to declare the method static:

public static void testAddAxioms(OWLOntology o, OWLOntologyManager m, OWLDataFactory f) { ...}

Then you don't need to create any object and can simply call:

testAddAxioms(o, m, f);

But you should review your code carefully. You are declaring File file but are not using it. Perhaps you need to pass it to some method or constructor when initializing the objects you pass to the method. If you need it inside the method, you will have to add an extra argument to it.

answered Mar 2, 2014 at 20:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.