'null' in a TextView

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

'null' in a TextView

Postby robin92 » Thu Mar 03, 2011 5:21 pm

Good Afternoon everybody,

I've just started learning how to program Android devices and wanted to create a simple application that will display text in a TextView object. However simple it may seem, it apparently isn't. My problem is a "null" appearing in front of my proper text. The issue is shown on a attached screenshot.

Image

Part of my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private TextView Ekran;
  2. private String eq;
  3.  
  4. public OnClickListener numListener = new OnClickListener() {
  5.     public void onClick(View v) {
  6.         if (v == b1) eq += "1";
  7.         Ekran.setText(eq);
  8.     }
  9. };
  10.  
Parsed in 0.046 seconds, using GeSHi 1.0.8.4


PS. b1 is a button initialized earlier in the code; it stands for 'button of number one'.
robin92
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 03, 2011 5:10 pm

Top

Re: 'null' in a TextView

Postby strider2023 » Thu Mar 03, 2011 5:57 pm

Does you activity implement OnClickListener and have you checked if your button b1 is set to receive onClick events like b1.setOnClickListener(this) ??
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Re: 'null' in a TextView

Postby robin92 » Thu Mar 03, 2011 6:38 pm

Yep, I double-checked that and this isn't a problem... I really dunno what comes that null from. I suppose it may be related to the String data type ('cos Android has its own - CharSequence), but for me Strings are more user-friendly and more familiar than CharSequence so when it's only possible I wanted to use them in spite of CharSequence.

In addition, as you can see the whole code is working - TextView displays my '1' but precedes it with that damned 'null'.

EDIT: I've just discovered that when I display my String in a Toast before displaying it in a TextView it is shown as a casual empty string ("" => means nothing inside), but displaying it in a Toast just after having set it in a TextView causes 'null' to appear before my text...
robin92
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 03, 2011 5:10 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 9 guests