java - XML Serialization with Simple Framework -


i using framework called simple, helpful serializing , deser. xml content. not able serialize xml file object. output object should filled information, null pointer exception.

here java code:

    inputstream = getresources().openrawresource(r.xml.startingdata);     serializer ser = new persister();     data data = ser.read(data.class, is); 

i have file in res/xml/ called startingdata.xml. trying serilize data "data" object. getting nullpointerexception related data object.

here startingdata.xml:

<data> <categories>     <category>inbox</category>     <category>private</category>     <category>work</category>     <category>business</category> </categories>  <todos>     <todo>         <id>1</id>         <text>explore app!</text>     </todo>      <todo>         <id>2</id>         <text>add more todos!</text>         <date>2013-05-09 12:21:55 cet</date>     </todo> </todos> 

i think xml model classes ok, , there no problem them, can post them if need see them.

here model classes:

data.java

@root public class data {   @elementlist  public list<category> categories;   @elementlist  public list<todo> todos;  }  @element(name="todo")  public class todo {  @element(required=true) public string id;  @element(required=true) public string text;  @element(required=false) public date date;   }  @element(name="category") public class category {      @element(required=true)     public string text;  } 

i using toast check if created data object created.

toast toast = toast.maketext(getapplicationcontext(), data.tostring(), toast.length_long);         toast.show(); 

here full stack trace:

05-09 14:13:38.407: e/androidruntime(9246): fatal exception: main 05-09 14:13:38.407: e/androidruntime(9246): java.lang.runtimeexception: unable start     activity componentinfo{com.todo.wanttodo/com.todo.wanttodo.mainactivity}: java.lang.nullpointerexception 05-09 14:13:38.407: e/androidruntime(9246):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.app.activitythread.access$600(activitythread.java:141) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.os.handler.dispatchmessage(handler.java:99) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.os.looper.loop(looper.java:137) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.app.activitythread.main(activitythread.java:5041) 05-09 14:13:38.407: e/androidruntime(9246):     @ java.lang.reflect.method.invokenative(native method) 05-09 14:13:38.407: e/androidruntime(9246):     @ java.lang.reflect.method.invoke(method.java:511) 05-09 14:13:38.407: e/androidruntime(9246):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-09 14:13:38.407: e/androidruntime(9246):     @     com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-09 14:13:38.407: e/androidruntime(9246):     @ dalvik.system.nativestart.main(native     method) 05-09 14:13:38.407: e/androidruntime(9246): caused by: java.lang.nullpointerexception 05-09 14:13:38.407: e/androidruntime(9246):     @ com.todo.wanttodo.mainactivity.oncreate(mainactivity.java:77) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.app.activity.performcreate(activity.java:5104) 05-09 14:13:38.407: e/androidruntime(9246):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 05-09 14:13:38.407: e/androidruntime(9246):     @         android.app.activitythread.performlaunchactivity(activitythread.java:2144) 05-09 14:13:38.407: e/androidruntime(9246):     ... 11 more 

thank in advance!

are sure startingdata.xml file?

<?xml version="1.0" encoding="utf-8"?> <data>     <categories>         <category>inbox</category>         <category>private</category>         <category>work</category>         <category>business</category>     </categories>      <todos>         <todo>             <id>1</id>             <text>explore app!</text>         </todo>          <todo>             <id>2</id>             <text>add more todos!</text>            <date>2013-05-09 12:21:55 cet</date>        </todo>     </todos> </data> 

you can try different way using xmlpullparser: android - training, android - reference


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -