gpt4 book ai didi

java - 不兼容的 Java 方法

转载 作者:太空狗 更新时间:2023-10-29 16:37:57 25 4
gpt4 key购买 nike

我正在尝试通过 Aide 上的教程学习 Java,并输入了我认为正确的代码:

package com.aide.trainer.myapp;

import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;

public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

// Set main.xml as user interface layout
setContentView(R.layout.main);

final TextView textView = (TextView) findViewById(R.id.mainTextView1);
Button button = (Button) findViewById(R.id.mainButton1);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View p1)
{
// TODO: Implement this method
TextView textView = (TextView) findViewById(R.id.mainTextView1);
textView.setText("Clicked");
}
});
button.setOnLongClickListener(new OnLongClickListener()
{
@Override
public void onLongClick(View p1)
{

}
});
}
}

但是在 public void onLongClick(View p1) 中,void 有一个错误,它说:

The type of this method is incompatible with the type of the overridden method 'android.view.View.OnLongClickListener.onLongClick(android.view.View)'

我不知道我做错了什么。有人知道吗?

最佳答案

OnLongClickListener 中, onLongClick(...) 必须返回 boolean,而不是 void

关于java - 不兼容的 Java 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23645200/

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