DroidForums.net is the original Verizon Android Forum! Registered Users do not see these ads. Please Register - It's Free!
Results 1 to 7 of 7

Thread: [help] OnClick Button Errors

  1. Droid
    Reneg4d3's Avatar
    Member #
    67708
    Join Date
    May 2010
    Location
    Kentucky
    Posts
    50
    Phone
    Motorola Droid
    #1

    [help] OnClick Button Errors

    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:
    package com.error33.test;
    import android.app.Activity;
    import android.os.Bundle;
    import android.webkit.WebView;
    import android.widget.EditText;
    import android.widget.RadioGroup;
    import android.widget.TextView;
    public class test extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
             Button loginBtn = (Button) findViewById(R.id.login_Button);
        }
    } 
    loginBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View pV) {
            LoginActivity.this.login();
        }
    });
    private void login() {
        WebView.loadUrl("http://www.google.com")
    }
    I am getting errors on the following lines in order:
    Line 15
    Code:
      Button loginBtn = (Button) findViewById(R.id.login_Button)
    - Button cannot be resolved to a type

    Line 16
    Code:
    }
    - Syntax error on token "}", { expected

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

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

    Line 25
    Code:
    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:
    }
    - Syntax error, insert "}" to complete ClassBody


    Here is my main.xml
    Code:
    <?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"
    >
    <Button
    android:id="@+id/login_Button"
    android:layout_width="300px"
    android:layout_height="wrap_content"
    android:text="Goto Login Page"
    android:textSize="18sp"
    android:textStyle="bold"
    android:textColor="#ffffff00"
    android:layout_x="10px"
    android:layout_y="120px"
    >
    </Button>
    <Button
    android:id="@+id/schedule_Button"
    android:layout_width="300px"
    android:layout_height="wrap_content"
    android:text="View Schedule"
    android:textSize="18sp"
    android:textStyle="bold"
    android:textColor="#ffffff00"
    android:layout_x="10px"
    android:layout_y="297px"
    >
    </Button>
    <TextView
    android:id="@+id/Title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Wal-Mart Schedule"
    android:textSize="25sp"
    android:typeface="sans"
    android:textStyle="bold"
    android:textColor="#ff0033ff"
    android:layout_x="40px"
    android:layout_y="36px"
    >
    </TextView>
    <EditText
    android:id="@+id/monthInput"
    android:layout_width="50px"
    android:layout_height="wrap_content"
    android:text="#"
    android:textSize="18sp"
    android:layout_x="48px"
    android:layout_y="220px"
    >
    </EditText>
    <EditText
    android:id="@+id/dayInput"
    android:layout_width="50px"
    android:layout_height="wrap_content"
    android:text="#"
    android:textSize="18sp"
    android:layout_x="131px"
    android:layout_y="220px"
    >
    </EditText>
    <EditText
    android:id="@+id/yearInput"
    android:layout_width="70px"
    android:layout_height="wrap_content"
    android:text="#"
    android:textSize="18sp"
    android:layout_x="210px"
    android:layout_y="220px"
    >
    </EditText>
    <TextView
    android:id="@+id/monthTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Month"
    android:layout_x="50px"
    android:layout_y="190px"
    >
    </TextView>
    <TextView
    android:id="@+id/dayTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Day"
    android:layout_x="141px"
    android:layout_y="190px"
    >
    </TextView>
    <TextView
    android:id="@+id/yearTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Year"
    android:layout_x="227px"
    android:layout_y="190px"
    >
    </TextView>
    <TextView
    android:id="@+id/widget224"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Created by: "
    android:layout_x="149px"
    android:layout_y="410px"
    >
    </TextView>
    </AbsoluteLayout>
    Any help would be greatly appriciated!
    MOTOROLA DROID
    Project Elite GB v5.0.2
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.32.9_RZ
    Build Number: GRH78C
    Overclocked at 1.0GHZ

    Nook Color
    Phiremod v4.1
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.29-omap1 erik@myhost #91
    Build Number: GRH78C
    Overclocked at 1.1GHZ
  2.  
     
     
     
  3. Droid
    Reneg4d3's Avatar
    Member #
    67708
    Join Date
    May 2010
    Location
    Kentucky
    Posts
    50
    Phone
    Motorola Droid
    #2
    -[BUMP]-
    Any help would be much appreciated!
    MOTOROLA DROID
    Project Elite GB v5.0.2
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.32.9_RZ
    Build Number: GRH78C
    Overclocked at 1.0GHZ

    Nook Color
    Phiremod v4.1
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.29-omap1 erik@myhost #91
    Build Number: GRH78C
    Overclocked at 1.1GHZ
  4. Droid
    Reneg4d3's Avatar
    Member #
    67708
    Join Date
    May 2010
    Location
    Kentucky
    Posts
    50
    Phone
    Motorola Droid
    #3
    Please someone ...
    MOTOROLA DROID
    Project Elite GB v5.0.2
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.32.9_RZ
    Build Number: GRH78C
    Overclocked at 1.0GHZ

    Nook Color
    Phiremod v4.1
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.29-omap1 erik@myhost #91
    Build Number: GRH78C
    Overclocked at 1.1GHZ
  5. Junior Droid
    WrightPC's Avatar
    Member #
    110448
    Join Date
    Aug 2010
    Posts
    28
    Phone
    Enter Current Phone Model Here
    #4
    Your imports is incomplete
    Import android.widget.Button

    The tutorials suggest Ctrl+Shift+O in Eclipse to automatically add imports.

    Also, you can point your cursor at red underlined errors in your code for suggestions to fix the problem.

    Sent from my DROID2 GLOBAL using DroidForums App
  6. Developer
    jrummy16's Avatar
    Member #
    31454
    Join Date
    Jan 2010
    Location
    Orange County, CA
    Posts
    1,213
    Liked
    13 times
    Phone
    Moto Droid
    DroidForums.net Developer
    DroidForums.net Theme Developer
    Premium Member
    #5
    Try something like this for the button.

    Code:
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class test extends Activity implements OnClickListener{
    
    	/** Called when the activity is first created. */
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		handler.sendEmptyMessage(0);
    	}
    
    	public void OnClickListen() {		
    		Button loginBtn =(Button)findViewById(R.id.login_Button);		
    		loginBtn.setOnClickListener(this);
    	}
    
    	private Handler handler = new Handler() {
    		@Override
    		public void handleMessage(Message msg) {
    			setContentView(R.layout.main);
    			OnClickListen();
    			return;
    		}
    	};
    
    	public void onClick(View view) {
    		
    		switch (view.getId()) {
    		case R.id.login_Button:
    			// do your work here
    		break;
    		}
    	}
    }
  7. Senior Droid
    crdnilfan's Avatar
    Member #
    18277
    Join Date
    Dec 2009
    Posts
    207
    Phone
    HTC Rezound
    #6
    jRummy is right. what you were missing is params in your onClick
    you NEED to have onClick(View view) {
    or
    runThis(View view) {

    you can't just do onClick() or runThis().

    edit----

    just realized i may have revived a dead thread. my bad! was trying to help :P
  8. Droid
    Reneg4d3's Avatar
    Member #
    67708
    Join Date
    May 2010
    Location
    Kentucky
    Posts
    50
    Phone
    Motorola Droid
    #7
    Quote Originally Posted by crdnilfan View Post
    jRummy is right. what you were missing is params in your onClick
    you NEED to have onClick(View view) {
    or
    runThis(View view) {

    you can't just do onClick() or runThis().

    edit----

    just realized i may have revived a dead thread. my bad! was trying to help :P
    You didn't revive a dead thread, I have been checking this for months trying to find an explanation. Thanks I will see what I can do now.

    So what do I need to change in my code? I am not just simply running onClick() I have 2 parameters listed in the onClick.
    MOTOROLA DROID
    Project Elite GB v5.0.2
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.32.9_RZ
    Build Number: GRH78C
    Overclocked at 1.0GHZ

    Nook Color
    Phiremod v4.1
    Android Version: 2.3.2
    Kernel: Linux Version 2.6.29-omap1 erik@myhost #91
    Build Number: GRH78C
    Overclocked at 1.1GHZ

Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Similar Threads

  1. Rom errors and issues
    By joleme in forum Android Roms
    Replies: 2
    Last Post: 06-12-2010, 07:57 PM
  2. Navigation Errors
    By drewful1013 in forum Android Tech Support
    Replies: 1
    Last Post: 03-08-2010, 11:24 PM
  3. facebook errors
    By JTDroid in forum Android General Discussions
    Replies: 12
    Last Post: 01-15-2010, 07:32 PM
  4. pic message errors?
    By Dan.Droid in forum Android Applications
    Replies: 3
    Last Post: 12-27-2009, 11:21 AM
  5. Any way to remap the camera/volume button to be the power button?
    By Flowah in forum Android Hacks and Help
    Replies: 2
    Last Post: 12-13-2009, 08:12 AM

Search tags for this page

android button cannot be resolved to a type

,
android button onclick error
,

android onclick error

,
android onclick not working droid x2
,

android:onclick error

,

button cannot be resolved to a type

,
button cannot be resolved to a type android
,

onclicklistener cannot be resolved to a type

,

syntax error on token setonclicklistener, = expected after t

,

syntax error on token webview, import expected

Click on a term to search our site for related topics.

Tags for this Thread

Find us on Google+