The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Mobile » Android
 
RSS feed
 
New topic
Author

How to retrieve string from EditText?

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

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

This message was edited 1 time. Last update was at by Pramod P Deore


Life is easy because we write the source code.....
Monu Tripathi
Ranch Hand

Joined: Oct 12, 2008
Messages: 966

Can you post the exception?

[List of FAQs] | [Android FAQ] | [My Blog]
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

Actually It only show following attached screen but on Logcat it does not shows exception.
Thanks for quick reply
[Thumb - error.jpeg]
 Filename error.jpeg [Disk] Download
 Description
 Filesize 172 Kbytes
 Downloaded:  7 time(s)


Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

It shows following error as IllegalArgumentException

Life is easy because we write the source code.....
Monu Tripathi
Ranch Hand

Joined: Oct 12, 2008
Messages: 966

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.

[List of FAQs] | [Android FAQ] | [My Blog]
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

my method which send sms is as follows

Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

If I had write



instead of


Then I get message successfully,
i.e username is not converted into String but how?

Life is easy because we write the source code.....
Monu Tripathi
Ranch Hand

Joined: Oct 12, 2008
Messages: 966


Does the API permit any of the addresses to be null? What does the documentation say?

[List of FAQs] | [Android FAQ] | [My Blog]
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

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.

This message was edited 1 time. Last update was at by Pramod P Deore


Life is easy because we write the source code.....
Monu Tripathi
Ranch Hand

Joined: Oct 12, 2008
Messages: 966

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?



[List of FAQs] | [Android FAQ] | [My Blog]
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

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"
androidrientation="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






Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184


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.

Life is easy because we write the source code.....
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

Hello everybody!!!!!

Why EditText returns null instead of String even after calling getText.toString();

Life is easy because we write the source code.....
Monu Tripathi
Ranch Hand

Joined: Oct 12, 2008
Messages: 966

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):



[List of FAQs] | [Android FAQ] | [My Blog]
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Messages: 184

Thanks Monu.
for your great help.

Life is easy because we write the source code.....
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Mobile » Android
 
RSS feed
 
New topic
IntelliJ open source