• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

storing a file

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The stack trace should tell you that. Or you can post it here.
 
Ivan Kesic
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So which is line 113? What object is null?
 
Ivan Kesic
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you should assign something to "pom" before you invoke methods on it.
 
Ivan Kesic
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the relevant code is this:

Can you now see what you're missing?
 
Ivan Kesic
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i needed to make = new StringBuffer(); So rookey mistake. I thought StringBuffer works like String... Thank you, now it works fine.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic