gpt4 book ai didi

java - 无法在 Android Studio 中解析方法 'findViewByID(int)'

转载 作者:行者123 更新时间:2023-12-02 03:40:10 25 4
gpt4 key购买 nike

我刚刚开始为 android 编码,但我收到了错误:android studio 中“无法解析方法‘findViewByID(int)’”

我似乎无法找出问题所在,尝试设置 contentView,实现 OnClickListener,但这些都没有修复任何问题。

下面是完整的代码,MainActivity 方法是这一切发生的地方:

package aprivate.contract.jdeko.dww_registration;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;


public class MainActivity extends AppCompatActivity{
private GoogleApiClient client;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button clickButton = (Button) findViewByID(R.id.Btn);
clickButton.setOnClickListener( new OnClickListener() {

@Override
public void onClick(View v) {
//todo
}
});
}

@Override
public void onStart() {
super.onStart();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://aprivate.contract.jdeko.dww_registration/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}

@Override
public void onStop() {
super.onStop();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://aprivate.contract.jdeko.dww_registration/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}

}

最佳答案

这只是你打错了。您应该使用“Id”而不是“ID”。

所以你的

Button clickButton = (Button) findViewByID(R.id.Btn);

成为

Button clickButton = (Button) findViewById(R.id.Btn);

关于java - 无法在 Android Studio 中解析方法 'findViewByID(int)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36915506/

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