gpt4 book ai didi

java - 电话应用 : item cannot be resolved or is not a field

转载 作者:搜寻专家 更新时间:2023-11-01 08:56:13 25 4
gpt4 key购买 nike

<分区>

我正在尝试遵循手册(其中有一些错误,我修复了它)但是我收到此错误 btstart cannot be resolved or is not a field 我不知道如何修理它。这是 LINK该手册(但我已经对布局以及字符串 xml 文件进行了更改)这是 MainActivity.java 代码:

 package com.example.stopwatch;
//import com.example.stopwatch.R;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;

public class MainActivity extends Activity implements OnClickListener {
private Button start;
private Button stop;
private Button reset;

private Chronometer mydChronometer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uI();
}

public void uI() {
start = (Button) findViewById(R.id.btstart);
start.setOnClickListener(this);
stop = (Button) findViewById(R.id.btstop);
stop.setOnClickListener(this);
reset = (Button) findViewById(R.id.btreset);
reset.setOnClickListener(this);
mydChronometer = (Chronometer) findViewById(R.id.chronometer1);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onClick(View v) {
if (v == start) {
mydChronometer.start();

} else if (v == stop) {

mydChronometer.stop();
} else if (v== reset) {
mydChronometer.setBase(SystemClock.elapsedRealtime());

}

}

}

这是我的“activity_main.xml”:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/chronometer1"
android:layout_centerHorizontal="true"
android:layout_marginTop="67dp"
android:src="@drawable/myd" />

<Chronometer
android:id="@+id/chronometer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:gravity="center"
android:text="Chronometer"
android:textSize="35dp" />

<Button
android:id="@+id/btstart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_below="@+id/chronometer1"
android:layout_marginTop="18dp"
android:text="@string/start" />

<Button
android:id="@+id/btreset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btstop"
android:layout_alignBottom="@+id/btstop"
android:layout_toRightOf="@+id/btstop"
android:text="@string/reset" />

<Button
android:id="@+id/btstop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btstart"
android:layout_alignBottom="@+id/btstart"
android:layout_toRightOf="@+id/btstart"
android:text="@string/stop" />

</RelativeLayout>

这是“strings.xml”文件:

    <?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">stopwatch</string>
<string name="btn1">Start</string>
<string name="btn2">Stop</string>
<string name="btn3">Reset</string>
<string name="menu_settings">Settings</string>
<string name="action_settings">Settings</string>

</resources>

我没有对 main.xml 做任何更改,这是我的 main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>

能否请您告诉我我遗漏了什么以及如何解决此错误?

P.S.:我收到这些行的类似错误:

btstop cannot be resolved or is not a field in stop = (Button) findViewById(R.id.btstop);
btreset cannot be resolved or is not a field in reset = (Button) findViewById(R.id.btreset);
chronometer1 cannot be resolved or is not a field in mydChronometer = (Chronometer) findViewById(R.id.chronometer1);

非常感谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com