我该怎么办这些错误?

时间:2011-12-05 15:55:00

标签: android eclipse button

package com.duncan.hello.world;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.duncan.hello.world.R;

public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Button aButton;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    aButton = (Button) this.findViewById(R.id.button1);

    aButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(HelloWorld.this, OtherActivity.class);
            startActivity(i);
        }});
}
}

我现在只有一个错误,因为我导入了按钮。该错误在第23行,并说“HelloWorld无法解析为类型”

2 个答案:

答案 0 :(得分:1)

您需要导入正在使用的类。按钮无法解析为类型,因为您尚未导入它。

在你甚至可以运行错误之前,它应该给你一个错误。

答案 1 :(得分:0)

您的活动名称为HelloWorldActivity,但您在意图中使用了HelloWorld。 替换此代码,

Intent i = new Intent(HelloWorld.this, OtherActivity.class);

通过以下代码替换上面的内容,

Intent i = new Intent(HelloWorldActivity.this, OtherActivity.class);
相关问题