【发布时间】:2014-03-16 21:48:31
【问题描述】:
我正在创建一个 Android 应用程序,在我的最后一个问题 (Android app not able to open web link) 之后,我在 Eclipse 中遇到了这个语法错误:
Cannot instantiate the type View.OnClickListener
我的代码如下:
package com.example.ldsm3;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Finished extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_finished);
// tv is the ID for the TextView in the XML file
TextView tv = (TextView) findViewById(R.id.textView2);
// set the TextView to show the score
tv.setText(Misc.correct + "/" + Misc.total);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new Button.OnClickListener());
}
public void onClick(View v)
{
// Open up the system's default browser to whackamole.ajav-games.tk, where the Whack A Mole game is.
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://whackamole.ajav-games.tk"));
startActivity(browserIntent);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.finished, menu);
return true;
}
}
我该如何解决这个问题?我知道这可能是一个简单的 Java 错误,但我之前没有使用过 Java,请在提到 Java 语法、术语等时解释一下。
【问题讨论】:
标签: android syntax syntax-error