当在setText上使用onLongClick时出现类文件错误
|
我创建了这个小程序来尝试学习按钮和文本视图。尝试使用onLongClick设置setText时,我强制关闭。当我查看调试器时,在第45行holdMeAnswer.setText(\“ Nope!\”);中看到一个nullpointerexception。
我在nullpointer下方看到一大堆“类文件错误:找不到源”错误。我尝试将附加的源指向Java src.zip和android.jar文件,但似乎都无法解决任何问题。
代码是:
package com.PickSomeButtons;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Button;
import android.view.View.OnLongClickListener;
public class PickSomeButtons extends Activity {
RadioButton myButton0;
RadioButton myButton1;
TextView myAnswer;
TextView holdMeAnswer;
Button longClickButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton0=(RadioButton)findViewById(R.id.radio0);
myButton1=(RadioButton)findViewById(R.id.radio1);
myAnswer=(TextView)findViewById(R.id.textView1);
longClickButton=(Button)findViewById(R.id.button1);
myButton0.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myAnswer.setText(\"Me!\");
}
});
myButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myAnswer.setText(\"Not me!\");
}
});
longClickButton.setOnLongClickListener(new Button.OnLongClickListener() {
public boolean onLongClick(View v) {
holdMeAnswer.setText(\"Nope!\");
return true;
}
});
}
}
没有找到相关结果
已邀请:
1 个回复
坛沤疲撑拆