OnClickListener不能被解析为一个类型(Eclipse中) [英] OnClickListener cannot be resolved to a type (Eclipse)

查看:500
本文介绍了OnClickListener不能被解析为一个类型(Eclipse中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好即时通讯新的节目,我尝试建立我的第一个简单的应用程序,即时寻找到上的ImageButton的推打短soundclip。

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.

在打字时我的codeI得到的说法错误;

while typing out my code i get an error with the statement;

 Button.setOnClickListener(new OnClickListener() {

上点击侦听强调,当我去到错误日食告诉我,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.

下面是我的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;

藏汉为

import android.view.view.OnClickListener;

这些import语句也被突出显示。 难道这些错误所致Eclipse是如何设置我的电脑上?

These import statements are also highlighted. Could these errors be caused by how eclipse is set up on my computer?

任何帮助将大大AP preciated

Any help would be greatly appreciated

推荐答案

对于初学者来说,它总是最好让Eclipse中通过点击管理所有进口按Ctrl + Shift + O,当你看到一个导入错误。

For starters, it's always best to let Eclipse manage all imports by tapping Ctrl+Shift+O when you see an import error.

看来你的问题是由于:

import android.view.view;

应该是:

import android.view.View;

同样还有android.view.View.OnClickListener。

Same goes with android.view.View.OnClickListener.

如果您删除您手动添加两行,然后按Ctrl + Shift + O,一切都应该自我修复。

If you remove the two lines you've manually added and hit Ctrl+Shift+O, everything should fix itself.

这篇关于OnClickListener不能被解析为一个类型(Eclipse中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆