1.11M Members

Android development : Button cannot be resolved as a type error

 
0
 

I have just started android development and i cannot even compile a simple program because i get a error " button cannot be resolved to a type " in the .java file .

.java file :

package abcd.pack;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class Project1Activity extends Activity {
    /** Called when the activity is first created. */

   int Counter;
   Button add;
   Button sub;
   TextView display;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Counter = 0 ;
        add = (Buttton) findViewById(R.id.bAdd);
        sub = (Button) findViewById(R.id.bSub);
        display = (TextView) findViewById(R.id.tvDisplay);
        add.setOnClickListener(new View.OnClickListener() {

         public void onClick(View arg0) {
            Counter++;
            display.setText("Your total is " + Counter);
                        // TODO Auto-generated method stub

         }
      });
     sub.setOnClickListener(new View.OnClickListener() {

      public void onClick(View v) {

         Counter--;
         display.setText("Your total is " + Counter);

         // TODO Auto-generated method stub

      }
   });
    }
}

And this is my main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Your total is zero"
        android:textSize="45dp"
        android:id="@+id/tvDisplay"

         />

    <Button
        android:id="@+id/bAdd"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:text="add one"
        android:textSize="20dp" />

      <Button 
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:text="substract one"
        android:layout_gravity="center"
        android:textSize="20dp"
        android:id="@+id/bSub"

        />


</LinearLayout>

So what am i doing wrong ?

 
0
 

On line 23 in the program you try to set up a Button variable but declare it as (Buttton) {3 t's}
this typo will cause your error as the type is not recognised. I suspect your actual error message is Buttton not recognised as a type!

 
0
 

I found my error , i typed " buttton" instead of "button " :D . So it basically was a typing mistake on my side .

Question Answered as of 2 Years Ago by stevelg
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article