Urgent: How to call a methord from non activity class?

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Urgent: How to call a methord from non activity class?

Postby newbieAndroidDev » Mon Mar 15, 2010 12:28 pm

First of all sorry about my English because English is my 2nd language.

i am trying to call a method from a activity class to a abstract class which extends from LinearLayout. When the method is called i get a error message such as

ERROR/AndroidRuntime(6068): java.lang.NullPointerException


but i have passing the parameter value to the method and eve though it returning null. is anyone know how to pass the parameter to a activity class from a non activity class?



e.g. Calling methord from activity class (.java)

public void storeData(int data, String filename) {
try {

fileOutPut = openFileOutput(filename, MODE_WORLD_WRITEABLE);
outStreamW = new OutputStreamWriter(fileOutPut );

tmpScore = Integer.toString(data);
osw.append(tmpScore);

osw.flush();
osw.close();

} catch (IOException ioe) {
ioe.printStackTrace();
}
}



to a non activity class (saveNote.java)

i have declared to call the method as below.

fileManager _fileManage = new fileManager();


public void saveNote() {
_fileManage.storeData(200, "savedata.txt");
}


when the saveNote() is called i get ERROR/AndroidRuntime(6068): java.lang.NullPointerException for the line from storeData(int data, String filename) is that fileOutPut = openFileOutput(filename, MODE_WORLD_WRITEABLE);

this mean the parameter is not passing to.

i try to use the Intent way but again because of the class not a activity class it not allowing me to do.


so could you please help me what need to be done to pass the parameter to a non activity class from a activity class.

thank you for take your time to read my thread.
newbieAndroidDev
Freshman
Freshman
 
Posts: 4
Joined: Mon Mar 15, 2010 12:04 pm

Top

Postby newbieAndroidDev » Mon Mar 15, 2010 4:25 pm

did you understand my question? i need urgent help for my question. could you please reply if anyone knew what is the problem. thank you advance.
newbieAndroidDev
Freshman
Freshman
 
Posts: 4
Joined: Mon Mar 15, 2010 12:04 pm

Postby pria » Mon Mar 29, 2010 1:28 pm

Have u added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

in your manifest file???
pria
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Mar 02, 2010 1:37 pm
Location: Pune

Postby newbieAndroidDev » Mon Apr 05, 2010 1:14 pm

i have added but i had the problem all the way. i found another way to fix this and problem is solved now. thank you for the help anyway.


pria wrote:Have u added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

in your manifest file???
newbieAndroidDev
Freshman
Freshman
 
Posts: 4
Joined: Mon Mar 15, 2010 12:04 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Google [Bot] and 12 guests