• 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

ERROR/AndroidRuntime(706): java.lang.RuntimeException: Unable to start activity

 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody, I have write one application that writes data to the text file, but when I run application it throws following exception
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.micro/com.micro.MyProject}: java.lang.NullPointerException

what's wrong in my code.

MyProject.java file contains following code



and I have .txt file under src/com/micro/setting.txt file.
following is error part from Logcat file.




Thanks
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you setting the 'con' member ?

It looks like there is no context being passed to the Toast call, hence the null pointer exception..

Try changing



to



 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or even just change your

Toast.makeText(context, "Settings not saved",Toast.LENGTH_SHORT).show();

to use 'this' instead of 'context' then you don't need to pass in the context into the method, unless you are planning on calling that method from other Activitys/Dialogs...

 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But still it gives the same error.
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I will not get any exception but still the data is not saved under settings.txt file.
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody, now I think data is stored under
data/data/com/micro/Settings.txt file ,(because Now size of Settings.txt is increased,)but I don't understand how to see content of this file. And when I will install this application under phone then where I will get this file.
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are storing application settinings, any reason you're not using the Preferences API rather than rolling our own?

Dave
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pramod P Deore wrote:Hello Everybody, now I think data is stored under
data/data/com/micro/Settings.txt file ,(because Now size of Settings.txt is increased,)but I don't understand how to see content of this file. And when I will install this application under phone then where I will get this file.


It is stored there because you chose to do so when you said: openFileOutput("settings.txt",MODE_PRIVATE); Read the documentation of the afore mentioned method.
It will be stored under same location when you install your application on the phone, I think. Note that, you will not be able to browse to this folder on the phone unless you have logged in as root.

To see the contents of the file, try pulling it out of SDcard onto your development machine. (Use adb pull or DDMS for this).

If you are just persisting some settings, you should consider using the Preferences API as was mentioned by Dave.
 
reply
    Bookmark Topic Watch Topic
  • New Topic