aspose file tools*
The moose likes Android and the fly likes storing a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "storing a file" Watch "storing a file" New topic
Author

storing a file

Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Hello

I'm having a problem with storing a file (string) on phone. Its only 1 file with temperatures in it. But when i store a file, it just doesn't show up anywhere. Its never made. Tried some java tehnics with ObjectOutputStream but it doesn't work eider. What am i doing wrong?

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
What do you mean by "show up anywhere"? Are you using a file manager like OpenIntents?

Storing on the SD card works differently: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Hmmm, then here is a problem.



So, this opens the file and gets all of the text from it and puts it in tempLocal text field. But this method throws a nullpoint exception according to LogCat. Also this is all happening in Timer (Handler), and every time he refreshes, he makes a new temperature.txt file and stores it with old and new value. I can't figure out what is null here in this method.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
The stack trace should tell you that. Or you can post it here.
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
11-04 19:47:35.103: WARN/System.err(277): java.lang.NullPointerException
11-04 19:47:35.122: WARN/System.err(277): at projekat.p1.ProjekatActivity.vratiTemperature(ProjekatActivity.java:113)
11-04 19:47:35.122: WARN/System.err(277): at projekat.p1.ProjekatActivity.access$0(ProjekatActivity.java:107)
11-04 19:47:35.122: WARN/System.err(277): at projekat.p1.ProjekatActivity$1.run(ProjekatActivity.java:73)
11-04 19:47:35.122: WARN/System.err(277): at android.os.Handler.handleCallback(Handler.java:587)
11-04 19:47:35.122: WARN/System.err(277): at android.os.Handler.dispatchMessage(Handler.java:92)
11-04 19:47:35.122: WARN/System.err(277): at android.os.Looper.loop(Looper.java:123)
11-04 19:47:35.122: WARN/System.err(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-04 19:47:35.122: WARN/System.err(277): at java.lang.reflect.Method.invokeNative(Native Method)
11-04 19:47:35.131: WARN/System.err(277): at java.lang.reflect.Method.invoke(Method.java:521)
11-04 19:47:35.131: WARN/System.err(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-04 19:47:35.131: WARN/System.err(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-04 19:47:35.131: WARN/System.err(277): at dalvik.system.NativeStart.main(Native Method)

cant' realy figure out anything here...
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So which is line 113? What object is null?
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
StringBuffer pom; line 113

so in method first it gets a number then, temperature = pom.toString(); It seems that here it throws a null, so pom doesn't append anything...
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So you should assign something to "pom" before you invoke methods on it.
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Im not sure i understand. I make StringBuffer pom as global variable. Then in method vratiTemperate() i do : pom.append((char)ch); In loop so i get all the text from file i open. Not sure what im doing wrong...
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So the relevant code is this:

Can you now see what you're missing?
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
So i needed to make = new StringBuffer(); So rookey mistake. I thought StringBuffer works like String... Thank you, now it works fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing a file