| Author |
How to retrieve string from EditText?
|
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
I am writing one application in that I am taking input from user and sending it through sms, but my problem is that I am not able to get that string(i.e. which is given from user as a input )
suppose I have following in the main.xml file
It have one TextField, one EditText and one Button.
Now when user write input to EditText then that String I want to send through the sms.
my Test.java contains
Now when I run this and if I supplied input to form as "Pramod Deore" but when I I click on ok button it throws Exception
|
Life is easy because we write the source code.....
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
|
Can you post the exception?
|
[List of FAQs] | [Android FAQ] | [My Blog] | [Samuh Varta]
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
Actually It only show following attached screen but on Logcat it does not shows exception.
Thanks for quick reply
|
| Filename |
error.jpeg |
Download
|
| Description |
|
| Filesize |
172 Kbytes
|
| Downloaded: |
91 time(s) |
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
It shows following error as IllegalArgumentException
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
|
I suspect, you have not pasted the piece of code that is causing that exception. I do not see SmsManager.sendTextMessage being called anywhere in your code.
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
my method which send sms is as follows
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
If I had write
instead of
Then I get message successfully,
i.e username is not converted into String but how?
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
Does the API permit any of the addresses to be null? What does the documentation say?
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
|
But when I pass second argument as "Pramod Deore" i.e. String then it runs successfully. But if I pass username (i.e which is get from EditText) then it throws Exception.
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
But when I pass second argument as "Pramod Deore" i.e. String then it runs successfully. But if I pass username (i.e which is get from EditText) then it throws Exception.
Have you tried to print the value you read from the EditText and see what you are getting? Is it null? Is it empty? Are you passing what you are actually reading to the sendSMS() method?
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
Hello , today I write new application
My Test1.java is like
AndroidManifest file is
and main.xml is
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:id="@+id/widget28"
android:layout_width="252px"
android:layout_height="340px"
android  rientation="vertical"
android:layout_x="36px"
android:layout_y="31px"
>
<TextView
android:id="@+id/widget29"
android:layout_width="226px"
android:layout_height="44px"
android:text="Name"
>
</TextView>
<EditText
android:id="@+id/name"
android:layout_width="225px"
android:layout_height="44px"
android:text="EditText"
android:textSize="18sp"
>
</EditText>
<TextView
android:id="@+id/widget31"
android:layout_width="223px"
android:layout_height="40px"
android:text="Mob No"
>
</TextView>
<EditText
android:id="@+id/no"
android:layout_width="226px"
android:layout_height="48px"
android:textSize="18sp"
>
</EditText>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
>
</Button>
</LinearLayout>
</AbsoluteLayout>
But when I run application in the form it shows value of first EditText as EditText. and second fileld which is Mob no is blank.
when I pressed on ok button . The Logcat shows output as
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
Have you tried to print the value you read from the EditText and see what you are getting? Is it null? Is it empty? Are you passing what you are actually reading to the sendSMS() method?
I had print values but I get null in both textfield.
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
Hello everybody!!!
Why EditText returns null instead of String even after calling getText.toString();
|
 |
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
Because you are printing their values inside onCreate(). The View is not drawn until the window receives focus.
You should copy the following inside the button click callback method(inside onClick of Ok button):
|
 |
Pramod P Deore
Ranch Hand
Joined: Jul 15, 2008
Posts: 623
|
|
Thanks Monu.
for your great help.
|
 |
 |
|
|
subject: How to retrieve string from EditText?
|
|
|