java - 按钮无法解析为类型 - Android 开发

标签 java android xml eclipse debugging

我是 Android 开发新手,遇到一些调试问题。我正在从一个名为“TheNewBoston”的 YouTube channel 学习,并且在第 10 课中遇到了问题。我没有使用与教程中的人相同的 src 包,因为我找不到它,所以我想知道这是否造成了这个问题。

添加按钮和子按钮在 OnCreate 方法中都具有相同的“此行有多个标记 - 按钮无法按类型解析”错误。

Java:

package com.example.thenewboston.sam;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.thenewboston.sam.util.SystemUiHider;
public class FullscreenActivity extends Activity {
/**
 * Whether or not the system UI should be auto-hidden after
 * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
 */

int counter;
Button add, sub;
TextView Display;
private static final boolean AUTO_HIDE = true;
/**
 * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
 * user interaction before hiding the system UI.
 */
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

/**
 * If set, will toggle the system UI visibility upon interaction. Otherwise,
 * will show the system UI visibility upon interaction.
 */
private static final boolean TOGGLE_ON_CLICK = true;

/**
 * The flags to pass to {@link SystemUiHider#getInstance}.
 */
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

/**
 * The instance of the {@link SystemUiHider} for this activity.
 */
private SystemUiHider mSystemUiHider;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fullscreen);
    counter = 0;
    add = (button) findViewById(R.id.bAdd);
    sub = (button) findViewbyId(R.id.bSub);
    Display = (TextView) findViewById(R.id.tvDisplay);
    add.SetOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter++;
            Display.setText("your total is " + counter);


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

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter--;
        }
    });

    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    final View contentView = findViewById(R.id.fullscreen_content);

    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mSystemUiHider = SystemUiHider.getInstance(this, contentView,
            HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider
        .setOnVisibilityChangeListener(new               SystemUiHider.OnVisibilityChangeListener() {
                // Cached values.
                int mControlsHeight;
                int mShortAnimTime;

XML:

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

    >

    <!--
     The primary full-screen view. This can be replaced with whatever view
     is needed to present your content, e.g. VideoView, SurfaceView,
     TextureView, etc.
    -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45sp"
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"
android:id="@+id/tvDisplay"


      />

  <Button
    android:layout_width="250sp"
    android:layout_height="wrap_content"
    android:text="Add one" 
    android:layout_gravity="center"
    android:textSize="20sp"
    android:id="@+id/bAdd"
    ></Button>
  <Button
    android:layout_width="250sp"
    android:layout_height="wrap_content"
    android:text="Subtract one" 
    android:layout_gravity="center"
    android:textSize="20sp"
    android:id="@+id/bSub"
    ></Button>

       </LinearLayout>
       <!--
       This FrameLayout insets its children based on system windows using
       android:fitsSystemWindows.
       -->  

最佳答案

add.SetOnClickListener

SetOnClickListener 的 s 必须小写。

还有 Actor :

(button)

是错误的,如评论框中所述。它应该是按钮

关于java - 按钮无法解析为类型 - Android 开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22041989/

相关文章:

javascript - 按字母顺序对 <li> 元素进行排序

xml - Maven 2 原型(prototype)创建 : how to concatenate variables in folder/file names

xml - 使用XML添加水印:FO or XML Transform

java - 如何从 IntStream 填充 List<Integer>?

java - 从 Swing 应用程序中的 JFXPanel 创建模态舞台

java - 哪个更好?在每个其他函数定义的末尾使用 while 循环或调用 main 函数

Android 操作栏可检查菜单项无法正常工作/显示?

Spring Boot、Docker 和 EC2 中的 Java 版本

android - 服务未注册 : android. speech.tts.TextToSpeech

android - Scrollview 作为 CoordinatorLayout 的子项时,工具栏不会折叠