Hello im new to programming, im trying to construct my first simple application, im looking to play a short soundclip on the push of an ImageButton.
你好,我是编程新手,我正在尝试构造我的第一个简单的应用程序,我想在一个ImageButton的push上播放一个短的声音剪辑。
while typing out my code i get an error with the statement;
在输入代码时,我在语句中得到一个错误;
Button.setOnClickListener(new OnClickListener() {
The on click listener is underlined and when i go to the error eclipse tells me that OnClickListener cannot be resolved to a type.
在单击监听器上加下划线,当我访问错误时,eclipse告诉我OnClickListener不能被解析为类型。
Here is my code:
这是我的代码:
import android.app.Activity;
import android.os.Bundle;
import android.view.view;
import android.view.view.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton Button = (ImageButton) findViewById(R.id.imageButton1);
Button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
}
});
I read a suggestion that said to add;
我读了一个建议,说要加上;
import android.view.view;
aswell as
以及
import android.view.view.OnClickListener;
These import statements are also highlighted. Could these errors be caused by how eclipse is set up on my computer?
这些导入语句也被突出显示。这些错误可能是由于eclipse是如何在我的计算机上设置的吗?
Any help would be greatly appreciated
非常感谢您的帮助。
6 个解决方案
#1
12
For starters, it's always best to let Eclipse manage all imports by tapping Ctrl+Shift+O when you see an import error.
对于初学者来说,当您看到导入错误时,最好让Eclipse通过按Ctrl+Shift+O来管理所有导入。
It seems that your problem is due to:
看来你的问题是由于:
import android.view.view;
Which should be:
这应该是:
import android.view.View;
Same goes with android.view.View.OnClickListener.
android.view.View.OnClickListener一样。
If you remove the two lines you've manually added and hit Ctrl+Shift+O, everything should fix itself.
如果你删除了你手动添加的两行并按下Ctrl+Shift+O,所有的东西都应该修正。
#2
4
Add
添加
import android.view.View.OnclickListener
to your import
section and it should work.
对于您的导入部分,它应该起作用。
#3
0
The second "view" in the import statement is a class (hence, OnClickListener
is an inner class/interface) and should be capitalised:
import语句中的第二个“视图”是一个类(因此,OnClickListener是一个内部类/接口),应该大写:
import android.view.View.OnClickListener;
#4
0
make sure your class implements OnClickListener
确保您的类实现了OnClickListener。
public class main extends Activity implements OnClickListener {
#5
0
if you still have error you can make the class abstract like this public abstract class MainActivity extends Activity implements OnClickListener {
如果您仍然有错误,您可以使类抽象像这个公共抽象类MainActivity扩展活动实现OnClickListener {
#6
0
If you are using the new Android Studio you must declare your new OnClickListener as View.OnClickListener. Otherwise Android Studio gets confused and won't understand.
如果您正在使用新的Android Studio,那么必须将新的OnClickListener声明为View.OnClickListener。否则,Android Studio会感到困惑,无法理解。
#1
12
For starters, it's always best to let Eclipse manage all imports by tapping Ctrl+Shift+O when you see an import error.
对于初学者来说,当您看到导入错误时,最好让Eclipse通过按Ctrl+Shift+O来管理所有导入。
It seems that your problem is due to:
看来你的问题是由于:
import android.view.view;
Which should be:
这应该是:
import android.view.View;
Same goes with android.view.View.OnClickListener.
android.view.View.OnClickListener一样。
If you remove the two lines you've manually added and hit Ctrl+Shift+O, everything should fix itself.
如果你删除了你手动添加的两行并按下Ctrl+Shift+O,所有的东西都应该修正。
#2
4
Add
添加
import android.view.View.OnclickListener
to your import
section and it should work.
对于您的导入部分,它应该起作用。
#3
0
The second "view" in the import statement is a class (hence, OnClickListener
is an inner class/interface) and should be capitalised:
import语句中的第二个“视图”是一个类(因此,OnClickListener是一个内部类/接口),应该大写:
import android.view.View.OnClickListener;
#4
0
make sure your class implements OnClickListener
确保您的类实现了OnClickListener。
public class main extends Activity implements OnClickListener {
#5
0
if you still have error you can make the class abstract like this public abstract class MainActivity extends Activity implements OnClickListener {
如果您仍然有错误,您可以使类抽象像这个公共抽象类MainActivity扩展活动实现OnClickListener {
#6
0
If you are using the new Android Studio you must declare your new OnClickListener as View.OnClickListener. Otherwise Android Studio gets confused and won't understand.
如果您正在使用新的Android Studio,那么必须将新的OnClickListener声明为View.OnClickListener。否则,Android Studio会感到困惑,无法理解。