File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Dave Brown
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But still it gives the same error.
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • 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: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic