I was wondering if anyone could help. Every time I run my android app project it crashes. I\'ve narrowed it down to a single function but I have no idea why it\'s crashing!
There is a major flaw in your design. The error is obvious. In this line
final helpers helpers = new helpers();
you are trying to create an object of an activity which is a very very bad practice. You cannot simply create an object of an activity like this. All Activities in Android must go through the Activity lifecycle so that they have a valid context attached to them. In this case a valid context is not attached to the helper instance. So as a result the line
SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
causes a null pointer as 'this' is null. (Why? Because this refers to the context which has not yet been created as the activity is not started using startActivity(intent))
Another thing though this is not an error, you must use activity names starting with an upper case letter. It is the convention followed and will make your code more readable. Your code is pretty confusing due to the weird use of upper and lower case names. You declare your class with a lower case letter while at some places the variables are upper case. which causes confusion. The rule is that classes, interfaces, etc should start with upper case letters and variables as lower case.
So in this case what do you do?
You never start your Helper activity and I think you do not need to show it to the user. That is it needs to do some work without user interaction. You should make it a service. And then start it using startService(intent).
Or you may also create it as a Java class, depends on your use case.
Edit: By the way I answered another similar question having the same problem but involving services later today.