[help] OnClick Button Errors


Last Updated:

  1. eNkrypt

    eNkrypt Member

    Hello guys, I have been teaching my self to "code" in the android language and java over the past few day. So I am new to this so please be patient.

    Basically, my problem is I am trying to get a button on my form to open a web page.

    Here is my java file.
    Code (Text):
    1. package com.error33.test;
    2. import android.app.Activity;
    3. import android.os.Bundle;
    4. import android.webkit.WebView;
    5. import android.widget.EditText;
    6. import android.widget.RadioGroup;
    7. import android.widget.TextView;
    8. public class test extends Activity {
    9.     @Override
    10.     public void onCreate(Bundle savedInstanceState) {
    11.         super.onCreate(savedInstanceState);
    12.         setContentView(R.layout.main);
    13.        
    14.          Button loginBtn = (Button) findViewById(R.id.login_Button);
    15.     }
    16. }
    17. loginBtn.setOnClickListener(new View.OnClickListener() {
    18.     @Override
    19.     public void onClick(View pV) {
    20.         LoginActivity.this.login();
    21.     }
    22. });
    23. private void login() {
    24.     WebView.loadUrl("http://www.google.com")
    25. }
    I am getting errors on the following lines in order:
    Line 15
    Code (Text):
    1.   Button loginBtn = (Button) findViewById(R.id.login_Button)
    - Button cannot be resolved to a type

    Line 16
    Code (Text):
    1. }
    - Syntax error on token "}", { expected

    Line 18
    Code (Text):
    1. loginBtn.setOnClickListener(new View.OnClickListener() {
    - View cannot be resolved to a type

    Line 23
    Code (Text):
    1. });
    - Syntax error, insert "}" to complete MethodBody and Line breakpoint:WalmartSchedule [line: 23] - onCreate

    Line 25
    Code (Text):
    1. WebView.loadUrl("http://www.google.com")
    - Syntax error, insert ";" to complete BlockStatements and Cannot make a static reference to the non-static method loadUrl(String) from the type WebView

    Line 26
    Code (Text):
    1. }
    - Syntax error, insert "}" to complete ClassBody


    Here is my main.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-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. <Button
    10. android:id="@+id/login_Button"
    11. android:layout_width="300px"
    12. android:layout_height="wrap_content"
    13. android:text="Goto Login Page"
    14. android:textSize="18sp"
    15. android:textStyle="bold"
    16. android:textColor="#ffffff00"
    17. android:layout_x="10px"
    18. android:layout_y="120px"
    19. >
    20. </Button>
    21. <Button
    22. android:id="@+id/schedule_Button"
    23. android:layout_width="300px"
    24. android:layout_height="wrap_content"
    25. android:text="View Schedule"
    26. android:textSize="18sp"
    27. android:textStyle="bold"
    28. android:textColor="#ffffff00"
    29. android:layout_x="10px"
    30. android:layout_y="297px"
    31. >
    32. </Button>
    33. <TextView
    34. android:id="@+id/Title"
    35. android:layout_width="wrap_content"
    36. android:layout_height="wrap_content"
    37. android:text="Wal-Mart Schedule"
    38. android:textSize="25sp"
    39. android:typeface="sans"
    40. android:textStyle="bold"
    41. android:textColor="#ff0033ff"
    42. android:layout_x="40px"
    43. android:layout_y="36px"
    44. >
    45. </TextView>
    46. <EditText
    47. android:id="@+id/monthInput"
    48. android:layout_width="50px"
    49. android:layout_height="wrap_content"
    50. android:text="#"
    51. android:textSize="18sp"
    52. android:layout_x="48px"
    53. android:layout_y="220px"
    54. >
    55. </EditText>
    56. <EditText
    57. android:id="@+id/dayInput"
    58. android:layout_width="50px"
    59. android:layout_height="wrap_content"
    60. android:text="#"
    61. android:textSize="18sp"
    62. android:layout_x="131px"
    63. android:layout_y="220px"
    64. >
    65. </EditText>
    66. <EditText
    67. android:id="@+id/yearInput"
    68. android:layout_width="70px"
    69. android:layout_height="wrap_content"
    70. android:text="#"
    71. android:textSize="18sp"
    72. android:layout_x="210px"
    73. android:layout_y="220px"
    74. >
    75. </EditText>
    76. <TextView
    77. android:id="@+id/monthTitle"
    78. android:layout_width="wrap_content"
    79. android:layout_height="wrap_content"
    80. android:text="Month"
    81. android:layout_x="50px"
    82. android:layout_y="190px"
    83. >
    84. </TextView>
    85. <TextView
    86. android:id="@+id/dayTitle"
    87. android:layout_width="wrap_content"
    88. android:layout_height="wrap_content"
    89. android:text="Day"
    90. android:layout_x="141px"
    91. android:layout_y="190px"
    92. >
    93. </TextView>
    94. <TextView
    95. android:id="@+id/yearTitle"
    96. android:layout_width="wrap_content"
    97. android:layout_height="wrap_content"
    98. android:text="Year"
    99. android:layout_x="227px"
    100. android:layout_y="190px"
    101. >
    102. </TextView>
    103. <TextView
    104. android:id="@+id/widget224"
    105. android:layout_width="wrap_content"
    106. android:layout_height="wrap_content"
    107. android:text="Created by: "
    108. android:layout_x="149px"
    109. android:layout_y="410px"
    110. >
    111. </TextView>
    112. </AbsoluteLayout>
    113.  
    114.  
    Any help would be greatly appriciated!

    Advertisement
  2. eNkrypt

    eNkrypt Member

    Bump!
    Anyone?
  3. eNkrypt

    eNkrypt Member

    BUMP!!
    I am sure this is a simple problem! Help please :(
  4. eNkrypt

    eNkrypt Member

    Pleasssse!!!

Share This Page