Wednesday, September 5, 2012

[android-developers] Re: Concatenate EditText gives NullPointer Error

Plasma wrote:
Here are lines that give the error.

 No way that's true.

editTextProducer = (EditText)findViewById(R.id.editTextProducer);
producer = editTextProducer.getText().toString();
Private String fullname = "Name: ";

because this line isn't legal Java.
 
Private String ConcatFixedTextsValue = fullname.concat(producer);

You can tend to avoid such errors by following the Java Coding 
Conventions especially with respect to naming conventions.
 
I also get the error when I used "Private String ConcatFixedTextsValue
= fullname +  producer;"

You should get a compilation error.
 

editTextProducer is a "text" entered by a user via an input field. I
can print its value on console using  Log.d() but I can't concatenate
it with another string. I would say it's the variable that is null
(but prints out the entered value via a console).


The variable that's null is indicated by the error message, so "would" 
say is weaker than it needs to be.
 
Justin Anderson wrote:
> Sorry... but I'm not going to search through your entire class file to
> figure out what is wrong.  Judging from your error though, the problem is
> on line 109 of Searchnolly.java.
>
> That would mean that you are using a variable that is null.  Try debugging
> to figure out what is null and why... and then fix it.
 
> Plasma <micadey...@gmail.com> wrote:
>> Please help me fix the error in the code here -
>>http://www.fpaste.org/HzoM/.
>
>> The error I am gettting is:
>
> > 09-04 08:32:40.524: E/AndroidRuntime(644): FATAL EXCEPTION: main 09-04
> > 08:32:40.524: E/AndroidRuntime(644): java.lang.NullPointerException
> > 09-04 08:32:40.524: E/AndroidRuntime(644): at
> > com.vodacom.nollyviewer.Searchnolly.SearchVideos(Searchnolly.java:109)

It's the variable that's dereferenced here, as Justin pointed out.
 
> > 09-04 08:32:40.524: E/AndroidRuntime(644): at
> > com.vodacom.nollyviewer.Searchnolly$1.onClick(Searchnolly.java:71)
> > 09-04 08:32:40.524: E/AndroidRuntime(644): at
> > android.view.View.performClick(View.java:2485) 

-- 
Lew
 

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment