lundi 23 février 2015

android - java.lang.ExceptionInIntiliazerError Help needed urgently



I'm very new to Android programming and I'm trying to write an Android app that would parse an OWL file (.owl file) and display the classes and subclasses. When ever the user clicks the button, the file is read from the assets folder of the Eclipse Project, the OWL file is parsed and the names of the classes are printed on to the console.


But whenever I click the button, the emulator crashes throwing the following exceptions:



02-23 16:49:36.430: E/AndroidRuntime(597): FATAL EXCEPTION: main
02-23 16:49:36.430: E/AndroidRuntime(597): java.lang.ExceptionInInitializerError
02-23 16:49:36.430: E/AndroidRuntime(597): at com.Sample.SampleApp.StartingPoint.parseOWLFile(StartingPoint.java:105)
02-23 16:49:36.430: E/AndroidRuntime(597): at com.Sample.SampleApp.StartingPoint$3.onClick(StartingPoint.java:68)


Here is my the Java code I wrote:



public class StartingPoint extends ActionBarActivity {

private static final int REQUEST_PATH = 1;
String currentFile;
EditText et1;
Button browse, ok, exit;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

et1 = (EditText)findViewById(R.id.editText);

browse = (Button) findViewById(R.id.browseButton);
browse.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v)
{
getfile(v);
}

});

exit = (Button)findViewById(R.id.ExitButton);
exit.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v)
{
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}

});

ok = (Button)findViewById(R.id.OKButton);
ok.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v)
{
parseOWLFile();
}

});
}

public void getfile(View view)
{
Intent i1 = new Intent(this, FileChooser.class);
startActivityForResult(i1, REQUEST_PATH);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == REQUEST_PATH)
{
if(resultCode == RESULT_OK)
{
currentFile = data.getStringExtra("GetFileName");
et1.setText(currentFile);
}
}
}

public void parseOWLFile()
{
//String file = et1.getText().toString(); //Uncomment this when using on phone/tablet

String file = "antibiotics.owl";

try
{
//System.out.println("File name is "+file);

//File f = new File(file);
InputStream fis = getAssets().open(file);

OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM );
base.read(fis, null);

String ns = base.getNsPrefixURI("Ontology");

Resource r = base.getResource(ns+" Concept");
OntClass theClass = r.as(OntClass.class);

Individual indiv = base.createIndividual(ns+"IndivTest", theClass);

for (Iterator<Resource> i = indiv.listRDFTypes(true); i.hasNext(); )
System.out.println( indiv.getURI() + " is asserted in class " + i.next() );

OntModel inf = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF, base );

Individual ind = inf.getIndividual( ns + "indivTest" );
for (Iterator<Resource> i = ind.listRDFTypes(true); i.hasNext(); )
System.out.println( ind.getURI() + " is inferred to be in class " + i.next() );
}
catch(Exception e)
{
e.printStackTrace();
}
}

}


I have imported the AndroJena 0.5 version jars into my Eclipse Project.


Here are some more exceptions that I got:



02-23 16:49:36.430: E/AndroidRuntime(597): Caused by: java.lang.ExceptionInInitializerError
02-23 16:49:36.430: E/AndroidRuntime(597): at com.hp.hpl.jena.ontology.OntModelSpec.<clinit>(OntModelSpec.java:54)
02-23 16:49:36.430: E/AndroidRuntime(597): Caused by: java.lang.ExceptionInInitializerError
02-23 16:49:36.430: E/AndroidRuntime(597): at com.hp.hpl.jena.ontology.ProfileRegistry.<clinit>(ProfileRegistry.java:48)
02-23 16:49:36.430: E/AndroidRuntime(597): Caused by: java.lang.ExceptionInInitializerError
02-23 16:49:36.430: E/AndroidRuntime(597): at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:122)
02-23 16:49:36.430: E/AndroidRuntime(597): at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:116)


Could someone please help me eliminate this exception and get to parse the OWL file?


Thank you in advance! :)




Aucun commentaire:

Enregistrer un commentaire