EditText return null


  1. pramod.deore

    pramod.deore Member

    Hello everybody,

    I had write one application which takes data from user as a input field and store that into string varible but when I tried to ptint that String varible it gives me null.

    my Test1.java is like
    Code (Text):
    1.  
    2. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]package[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] com.micro;
    3. [/LEFT]
    4. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.app.Activity;[/LEFT]
    5. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.app.PendingIntent;[/LEFT]
    6. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.content.BroadcastReceiver;[/LEFT]
    7. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.content.Context;[/LEFT]
    8. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.content.Intent;[/LEFT]
    9. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.content.IntentFilter;[/LEFT]
    10. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.os.Bundle;[/LEFT]
    11. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.telephony.gsm.SmsManager;[/LEFT]
    12. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.View;[/LEFT]
    13. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.View.OnClickListener;[/LEFT]
    14. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.widget.Button;[/LEFT]
    15. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.widget.EditText;[/LEFT]
    16. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.widget.Toast;
    17. [/LEFT]
    18. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Test1 [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity
    19. {
    20. EditText [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]name1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]no1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    21. Button [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ok[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    22. String [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]nm[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mob1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    23. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mob[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    24. [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/**[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]Called[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]when[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]the[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]activity[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]is[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]first[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]created.[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]*/[/LEFT]
    25. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
    26. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onCreate(Bundle savedInstanceState)
    27. {
    28. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);
    29. setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    30.  
    31. [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]name1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (EditText)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]name[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    32. [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]no1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (EditText)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]no[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    33. Button ok = (Button)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ok[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    34.  
    35.  
    36. [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]nm[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]name1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText().toString();
    37. [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mob1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]no1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText().toString();
    38. // mob = Integer.parseInt(no.getText().toString());
    39.  
    40. ok.setOnClickListener([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]okListener[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    41.  
    42. print();
    43.  
    44. }
    45.  
    46. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnClickListener [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]okListener[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnClickListener()
    47. {
    48.  
    49. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onClick(View v)
    50. {
    51.  
    52. sendSMS([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"9960510915"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]nm[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"......."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mob1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    53.  
    54.  
    55. }
    56.  
    57. };
    58.  
    59.  
    60. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] print()
    61. {
    62. System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].println ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"name is"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]nm[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    63. System.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]out[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].println ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Mobile no is"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mob[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
    64.  
    65. }
    66.  
    67.  
    68. [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sendSMS(String phoneNumber, String message)[/LEFT]
    69. {
    70.      //send message
    71. }
    72. }
    73. [/SIZE]
    //main.xml is

    Code (Text):
    1.  
    2. [SIZE=2][LEFT]<?[U]xml[/U] version="1.0" encoding="[U]utf[/U]-8"?>
    3. <AbsoluteLayout
    4. android:id="@+id/widget0"
    5. android:layout_width="fill_parent"
    6. android:layout_height="fill_parent"
    7. xmlns:android="http://schemas.android.com/apk/res/android"
    8. >
    9. <LinearLayout
    10. android:id="@+id/widget28"
    11. android:layout_width="252px"
    12. android:layout_height="340px"
    13. android:orientation="vertical"
    14. android:layout_x="36px"
    15. android:layout_y="31px"
    16. >
    17. <TextView
    18. android:id="@+id/widget29"
    19. android:layout_width="226px"
    20. android:layout_height="44px"
    21. android:text="Name"
    22. >
    23. </TextView>
    24. <EditText
    25. android:id="@+id/name"
    26. android:layout_width="225px"
    27. android:layout_height="44px"
    28. android:text="EditText"
    29. android:textSize="18sp"
    30. >
    31. </EditText>
    32. <TextView
    33. android:id="@+id/widget31"
    34. android:layout_width="223px"
    35. android:layout_height="40px"
    36. android:text="Mob No"
    37. >
    38. </TextView>
    39. <EditText
    40. android:id="@+id/no"
    41. android:layout_width="226px"
    42. android:layout_height="48px"
    43. android:textSize="18sp"
    44. >
    45. </EditText>
    46. <Button
    47. android:id="@+id/[U]ok[/U]"
    48. android:layout_width="wrap_content"
    49. android:layout_height="wrap_content"
    50. android:text="[U]Ok[/U]"
    51. >
    52. </Button>
    53. </LinearLayout>
    54. </AbsoluteLayout>[/LEFT]
    55. [/SIZE]
    why EditText return null?

    Advertisement
    :
Loading...

Share This Page