findviewbyid returns null

Put your problem here if it does not fit any of the other categories.

findviewbyid returns null

Postby divendres » Thu Jun 04, 2009 7:42 pm

I'm calling a function of my main Activity from another Class:
The class is defined like this:
public class ProtocolButinet {

And the function from my main Activity is:
public void writeToChat(String missatge) {
TextView chat = (TextView) this.findViewById(R.id.Xat);
chat.append(missatge);
}

My problem is that findviewById causes a NullPointerException when I call it from the other Class but not
when i call the function from the Activity.
Can anyone help me? How can i can the function correctly?

Thanks
divendres
Freshman
Freshman
 
Posts: 3
Joined: Thu Jun 04, 2009 7:15 pm

Top

Postby padde » Thu Jun 04, 2009 9:11 pm

load the textview in your activity.. assign it there to your chat variable and then pass this
variable to the class.. where is the problem?!
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby divendres » Sat Jun 06, 2009 9:29 am

Ok, so I cannot call the function from another class? Just my main activity?
divendres
Freshman
Freshman
 
Posts: 3
Joined: Thu Jun 04, 2009 7:15 pm

Top

Return to Other Coding-Problems

Who is online

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