Saving Model to file.

40 views
Skip to first unread message

arndtn

unread,
Jun 30, 2010, 4:57:44 PM6/30/10
to androjena
Hello,
I try to create a model with a FileModelMaker and want to save its
changes to the filesystem.

String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
File storage = Environment.getExternalStorageDirectory();

if (storage.isDirectory()) {
File modelsPath = new File(storage, "models");
modelsPath.mkdirs();
ModelMaker models =
ModelFactory.createFileModelMaker(modelsPath.getAbsolutePath());
model = models.openModel("model");

return true;
} else {
return false;
}
}

but when I want to save it with model.commit() I get

E/DatabaseUtils( 346): Writing exception to parcel
E/DatabaseUtils( 346): java.lang.NullPointerException
E/DatabaseUtils( 346): at
com.hp.hpl.jena.graph.impl.FileGraphTransactionHandler.commit(FileGraphTransactionHandler.java:
63)
E/DatabaseUtils( 346): at
com.hp.hpl.jena.rdf.model.impl.ModelCom.commit(ModelCom.java:1083)
E/DatabaseUtils( 346): at
org.aksw.msw.TripleProvider.importResource(TripleProvider.java:321)
...

Do you have an example, which creates a FileModel and saves it to the
filesystem?

Best regards
Natanael

arndtn

unread,
Jun 30, 2010, 7:19:31 PM6/30/10
to androjena
I have pulled the File from the sdcard of the emulator and saw, that
it contains all data I had in the model serialized in RDF/XML.
But I don't understand the NullPointerException, does Jena try to
write some other files somewhere?

Natanael

lencinhaus

unread,
Jul 1, 2010, 3:42:59 AM7/1/10
to androjena
Yes, Jena creates and deletes some so called "checkpoint files" on the
fly during write operations on FileGraphs, as to maintain consistent
state during transactions. The problem seems to be that the checkpoint
file is not created when transaction begins so, when committing, Jena
tries to delete a null File reference and so the exception.
You say that the model file is created correctly: the checkpoint file
should be created in the same folder as the model file, so this
shouldn't be a matter of permissions, or at least I think.
Later I'll look deeper into it, in the meantime could you please send
some detailed information about your application (such as granted
permissions or the whole manifest and some more logcat)?
Thank you Natanael, regards
lorenzo

arndtn

unread,
Jul 2, 2010, 10:39:48 AM7/2/10
to androjena
This is my Manifest:
http://code.google.com/p/mssw/source/browse/msw/AndroidManifest.xml
It doesn't need ... permissions, because it uses API-Level 3.

And here some more traces:

D/AndroidRuntime( 234): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
D/AndroidRuntime( 234): CheckJNI is ON
W/ResourceType( 61): Resources don't contain package for resource
number 0x7f0700e5
W/ResourceType( 61): Resources don't contain package for resource
number 0x7f020031
W/ResourceType( 61): Resources don't contain package for resource
number 0x7f020030
W/ResourceType( 61): Resources don't contain package for resource
number 0x7f050000
W/ResourceType( 61): Resources don't contain package for resource
number 0x7f060000
W/ResourceType( 61): Resources don't contain package for resource
number 0x7f060001
D/AndroidRuntime( 234): --- registering native functions ---
I/ActivityManager( 61): Starting activity: Intent
{ act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] flg=0x10000000
cmp=org.aksw.mssw/.browser }
D/AndroidRuntime( 234): Shutting down VM
D/dalvikvm( 234): DestroyJavaVM waiting for non-daemon threads to
exit
D/dalvikvm( 234): DestroyJavaVM shutting VM down
D/dalvikvm( 234): HeapWorker thread shutting down
D/dalvikvm( 234): HeapWorker thread has shut down
D/jdwp ( 234): JDWP shutting down net...
I/jdwp ( 234): adbd disconnected
D/dalvikvm( 234): VM cleaning up
E/AndroidRuntime( 234): ERROR: thread attach failed
I/ActivityManager( 61): Start proc org.aksw.mssw for activity
org.aksw.mssw/.browser: pid=241 uid=10025 gids={3003, 1015}
D/dalvikvm( 234): LinearAlloc 0x0 used 637292 of 5242880 (12%)
D/ddm-heap( 241): Got feature list request
I/ARMAssembler( 61): generated
scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at
[0x37b1c0:0x37b33c] in 1335784 ns
V/msswBrowser( 241): Starting Query with uri: <content://
org.aksw.msw.tripleprovider/resource/tmp/http%3A%2F%2Fcomiles.eu%2F
%7Enatanael%2Ffoaf.rdf%23me>.
I/ActivityManager( 61): Start proc org.aksw.msw for content provider
org.aksw.msw/.TripleProvider: pid=247 uid=10024 gids={3003, 1015}
I/ActivityThread( 247): Publishing provider
org.aksw.msw.tripleprovider: org.aksw.msw.TripleProvider
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.rdf.model.impl.PropertyImpl is too long, using
model.impl.PropertyImpl instead
D/ddm-heap( 247): Got feature list request
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.util.Metadata is too long,
using .hpl.jena.util.Metadata instead
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.util.SystemUtils is too long, using
l.jena.util.SystemUtils instead
V/l.jena.util.SystemUtils( 247): Using thread classloader
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.rdf.model.impl.RDFListImpl is too long,
using .model.impl.RDFListImpl instead
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.ontology.impl.OntResourceImpl is too long, using
gy.impl.OntResourceImpl instead
D/ddm-heap( 215): Got feature list request
D/dalvikvm( 247): GC freed 2592 objects / 215344 bytes in 295ms
V/TripleProvider( 247): Created TripleProvider
V/TripleProvider( 247): Starting query
V/TripleProvider( 247): path(1): tmp.
V/TripleProvider( 247): path(2): http://comiles.eu/~natanael/foaf.rdf#me.
V/TripleProvider( 247): Matching URI <content://
org.aksw.msw.tripleprovider/resource/tmp/http%3A%2F%2Fcomiles.eu%2F
%7Enatanael%2Ffoaf.rdf%23me> match: (12).
V/TripleProvider( 247): getResource: <http://comiles.eu/~natanael/
foaf.rdf#me>
V/TripleProvider( 247): The resource <http://comiles.eu/~natanael/
foaf.rdf#me> has no properties in the given model.
V/TripleProvider( 247): The resource <http://comiles.eu/~natanael/
foaf.rdf#me> has no properties in the given model.
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler is too long,
using .RDFDefaultErrorHandler instead
D/ddm-heap( 122): Got feature list request
D/dalvikvm( 247): GC freed 939 objects / 68104 bytes in 254ms
D/dalvikvm( 247): GC freed 78 objects / 3616 bytes in 205ms
W/ActivityManager( 61): Launch timeout has expired, giving up wake
lock!
D/dalvikvm( 247): GC freed 14 objects / 1088 bytes in 265ms
D/ddm-heap( 182): Got feature list request
D/ddm-heap( 149): Got feature list request
D/dalvikvm( 247): GC freed 18 objects / 1496 bytes in 261ms
D/ddm-heap( 164): Got feature list request
W/ExpatReader( 247): DTD handlers aren't supported.
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.rdf.arp.SAX2RDF is too long, using
pl.jena.rdf.arp.SAX2RDF instead
W/pl.jena.rdf.arp.SAX2RDF( 247): http://apache.org/xml/features/allow-java-encodings
feature not supported by XMLReader
D/ddm-heap( 198): Got feature list request
W/ExpatReader( 247): DTD handlers aren't supported.
W/pl.jena.rdf.arp.SAX2RDF( 247): http://apache.org/xml/features/allow-java-encodings
feature not supported by XMLReader
W/ActivityManager( 61): Activity idle timeout for
HistoryRecord{43d6b160 org.aksw.mssw/.browser}
D/dalvikvm( 247): GC freed 3578 objects / 244272 bytes in 231ms
D/dalvikvm( 247): GC freed 2761 objects / 565240 bytes in 259ms
D/dalvikvm( 247): GC freed 4602 objects / 519456 bytes in 299ms
D/dalvikvm( 108): GC freed 4457 objects / 258680 bytes in 5661ms
V/TripleProvider( 247): The resource <http://comiles.eu/~natanael/
foaf.rdf#me> has at leased one property in the given model.
V/TripleProvider( 247): Cursor created
...
I/ActivityManager( 61): Displayed activity org.aksw.mssw/.browser:
26557 ms (total 26557 ms)
I/ARMAssembler( 61): generated
scanline__00000077:03545404_00000A04_00000000 [ 29 ipp] (51 ins) at
[0x37b340:0x37b40c] in 2718782 ns
D/dalvikvm( 215): GC freed 780 objects / 55664 bytes in 6325ms
V/msswBrowser( 241): Starting Query with uri: <content://
org.aksw.msw.tripleprovider/resource/save/http%3A%2F%2Fcomiles.eu%2F
%7Enatanael%2Ffoaf.rdf%23me>.
V/TripleProvider( 247): Starting query
V/TripleProvider( 247): path(1): save.
V/TripleProvider( 247): path(2): http://comiles.eu/~natanael/foaf.rdf#me.
V/TripleProvider( 247): Matching URI <content://
org.aksw.msw.tripleprovider/resource/save/http%3A%2F%2Fcomiles.eu%2F
%7Enatanael%2Ffoaf.rdf%23me> match: (11).
V/TripleProvider( 247): getResource: <http://comiles.eu/~natanael/
foaf.rdf#me>
V/TripleProvider( 247): The resource <http://comiles.eu/~natanael/
foaf.rdf#me> has no properties in the given model.
V/TripleProvider( 247): The resource <http://comiles.eu/~natanael/
foaf.rdf#me> has at leased one property in the given model.
I/AndroidLoggerFactory( 247): Logger name
com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter is too long, using
tput.impl.BaseXMLWriter instead
E/DatabaseUtils( 247): Writing exception to parcel
E/DatabaseUtils( 247): java.lang.NullPointerException
E/DatabaseUtils( 247): at
com.hp.hpl.jena.graph.impl.FileGraphTransactionHandler.commit(FileGraphTransactionHandler.java:
63)
E/DatabaseUtils( 247): at
com.hp.hpl.jena.rdf.model.impl.ModelCom.commit(ModelCom.java:1083)
E/DatabaseUtils( 247): at
org.aksw.msw.TripleProvider.importResource(TripleProvider.java:321)
E/DatabaseUtils( 247): at
org.aksw.msw.TripleProvider.getResource(TripleProvider.java:280)
E/DatabaseUtils( 247): at
org.aksw.msw.TripleProvider.query(TripleProvider.java:218)
E/DatabaseUtils( 247): at
org.aksw.msw.TripleProvider.query(TripleProvider.java:1)
E/DatabaseUtils( 247): at android.content.ContentProvider
$Transport.bulkQuery(ContentProvider.java:117)
E/DatabaseUtils( 247): at
android.content.ContentProviderNative.onTransact(ContentProviderNative.java:
98)
E/DatabaseUtils( 247): at android.os.Binder.execTransact(Binder.java:
287)
E/DatabaseUtils( 247): at dalvik.system.NativeStart.run(Native
Method)
D/AndroidRuntime( 241): Shutting down VM
W/dalvikvm( 241): threadid=3: thread exiting with uncaught exception
(group=0x4001b188)
E/AndroidRuntime( 241): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime( 241): java.lang.NullPointerException
E/AndroidRuntime( 241): at
android.os.Parcel.readException(Parcel.java:1224)
E/AndroidRuntime( 241): at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:
160)
E/AndroidRuntime( 241): at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:
114)
E/AndroidRuntime( 241): at
android.content.ContentProviderProxy.bulkQuery(ContentProviderNative.java:
326)
E/AndroidRuntime( 241): at
android.content.ContentProviderProxy.query(ContentProviderNative.java:
345)
E/AndroidRuntime( 241): at
android.content.ContentResolver.query(ContentResolver.java:202)
E/AndroidRuntime( 241): at
android.app.Activity.managedQuery(Activity.java:1495)
E/AndroidRuntime( 241): at
org.aksw.mssw.browser.loadRes(browser.java:118)
E/AndroidRuntime( 241): at org.aksw.mssw.browser
$2.onClick(browser.java:74)
E/AndroidRuntime( 241): at android.view.View.performClick(View.java:
2364)
E/AndroidRuntime( 241): at android.view.View.onTouchEvent(View.java:
4179)
E/AndroidRuntime( 241): at
android.widget.TextView.onTouchEvent(TextView.java:6541)
E/AndroidRuntime( 241): at
android.view.View.dispatchTouchEvent(View.java:3709)
E/AndroidRuntime( 241): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 241): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 241): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 241): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 241): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
E/AndroidRuntime( 241): at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
E/AndroidRuntime( 241): at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:
1107)
E/AndroidRuntime( 241): at
android.app.Activity.dispatchTouchEvent(Activity.java:2061)
E/AndroidRuntime( 241): at
com.android.internal.policy.impl.PhoneWindow
$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
E/AndroidRuntime( 241): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
E/AndroidRuntime( 241): at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 241): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 241): at
android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 241): at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 241): at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 241): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 241): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 241): at dalvik.system.NativeStart.main(Native
Method)
I/Process ( 61): Sending signal. PID: 241 SIG: 3
I/dalvikvm( 241): threadid=7: reacting to signal 3
I/dalvikvm( 241): Wrote stack trace to '/data/anr/traces.txt'
I/Process ( 241): Sending signal. PID: 241 SIG: 9
I/ActivityManager( 61): Process org.aksw.mssw (pid 241) has died.
I/WindowManager( 61): WIN DEATH: Window{43e75c08 org.aksw.mssw/
org.aksw.mssw.browser paused=false}
I/UsageStats( 61): Unexpected resume of com.android.launcher while
already resumed in org.aksw.mssw
W/InputManagerService( 61): Got RemoteException sending
setActive(false) notification to pid 241 uid 10025
D/dalvikvm( 247): GC freed 9192 objects / 506760 bytes in 405ms


Thank you
Natanael

lencinhaus

unread,
Jul 5, 2010, 11:26:25 AM7/5/10
to androjena
Hi,
I've looked into your project's code, and I think the problem is that
you never call model.begin() on the file-backed model. In fact, the
checkpoint file is created inside the begin() method, and that's why
you get an NPE when you try to commit your changes. So, you should
call model.begin() before any change to the model, and model.commit()
(or abort()) after. Hope this solves your problem, please let me know!
Bye,
lorenzo
> com.android.internal.policy.impl.PhoneWindow ...
>
> read more »

arndtn

unread,
Jul 6, 2010, 8:57:13 AM7/6/10
to androjena
Thank you, that works.
But the MemModels are without transaction support, am I right?

Natanael
> ...
>
> Erfahren Sie mehr »

lorenzo carrara

unread,
Jul 6, 2010, 9:05:41 AM7/6/10
to andr...@googlegroups.com
Yes: if you were using a MemModel, you would get an UnsupportedOperationException whenever calling one of the transaction-related methods.
Bye,
lorenzo

2010/7/6 arndtn <arn...@gmail.com>
Reply all
Reply to author
Forward
0 new messages