如何修正错误:“不是封闭的类” [英] How to fixed error: “not an enclosing class"
问题描述
亲爱的,
我是Android应用程序的新手。我刚刚学习了 [这里。我已经完成了一步一步的指导。现在,我在ResultActivity类中得到一个异常,因为不是封闭类ConceptActivity 。
在ResultActivity.java中代码:
// 检查和下一步
btnNext.setOnClickListener( new View.OnClickListener(){
@ Override
< span class =code-keyword> public void onClick(查看v){
RadioGroup grp =(RadioGroup)findViewById(R.id .radioGroup1);
RadioButton answer =(RadioButton)findViewById(grp.getCheckedRadioButtonId());
Log.e( 答案ID, 选定的定位值 - + grp.getCheckedRadioButtonId());
if (answer!= null){
Log.e( Answer,currentQuestion.getANSWER()+ - + answer.getText());
// 添加答案列表
myAnsList.add( + answer.getText());
if (currentQuestion.getANSWER()。equals(answer.getText())){
gettingScore ++;
Log.e( comments, 正确答案);
Log.d( 得分, 获得的分数 +获得的分数);
} else {
Log.e( comments, 错误答案);
}
if (questionId< dbadapter.rowcount())
{
currentquestion = questionsList。得到(questionId);
setquestionsview();
}
else
{
intent(conceptactivity。 this ,resultactivity。 class );
bundle b = new bundle();
b.putint( 得分,获得得分);
b.putint( totalqs,questionslist.size());
b.putstringarraylist( myanslist,myanslist);
intent.putextras(b);
startactivity(intent);
完成();
}
log.e(评论, 无答案);
// 需要清除已检查的商品ID
grp.clearcheck() ;
// end onclick method
});
在行中:
Intent intent = new Intent(ConceptActivity) 。此,ResultActivity。 class );
这里没有启用Intent类。
有人可以帮我解决这个问题吗?
我试过的:
我改变了:
Intent intent = new Intent(ResultActivity。 class ,ConceptActivity。 this );
我在文件中更改了ResultActivity.java
来自:公共类ConceptActivity扩展AppCompatActivity {
To:公共类ResultActivity扩展AppCompatActivity {
除了其他错误外,有一点很明显,构建Intent是错误的,应该是:
Intent intent = new Intent(ResultActivity。 this , ConceptActivity。 class );
或
Intent intent = new Intent( this ,ConceptActivity。 class );
Quote:Intent构造函数有两个参数:
一个上下文作为它的第一个pa rameter(由于Activity类是Context的子类,因此使用它)
系统应向其传递Intent的应用程序组件的类(在本例中为应该启动的活动)。
参考:开始另一项活动| Android开发者 [ ^
Dear All,
I am a newbie in android application. I have just study a tutorial [here]. And I have completed step by step instruction. Now, I am getting an exception as not an enclosing class ConceptActivity in the class ResultActivity.
In ResultActivity.java Code:
//Check and Next
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioGroup grp=(RadioGroup)findViewById(R.id.radioGroup1);
RadioButton answer=(RadioButton)findViewById(grp.getCheckedRadioButtonId());
Log.e("Answer ID", "Selected Positioned value - "+grp.getCheckedRadioButtonId());
if(answer!=null){
Log.e("Answer", currentQuestion.getANSWER() + " -- " + answer.getText());
//Add answer to the list
myAnsList.add(""+answer.getText());
if(currentQuestion.getANSWER().equals(answer.getText())){
obtainedScore++;
Log.e("comments", "Correct Answer");
Log.d("score", "Obtained score " + obtainedScore);
}else{
Log.e("comments", "Wrong Answer");
}
if(questionId<dbadapter.rowcount())
{
currentquestion=questionsList.get(questionId);
setquestionsview();
}
else
{
intent(conceptactivity.this, resultactivity.class);
bundle b = new bundle();
b.putint("score",obtainedscore);
b.putint("totalqs", questionslist.size());
b.putstringarraylist("myanslist", myanslist);
intent.putextras(b);
startactivity(intent);
finish();
}
log.e(comments, "no answer");
// need to clear the checked item id
grp.clearcheck();
// end onclick method
});
In the line:
Intent intent = new Intent(ConceptActivity.this, ResultActivity.class);
And Intent class is not enable here.
Can anybody help me to solve this issue ?
What I have tried:
I have changed in:
Intent intent = new Intent(ResultActivity.class, ConceptActivity.this);
I have change in file ResultActivity.java
from: public class ConceptActivity extends AppCompatActivity {
To: public class ResultActivity extends AppCompatActivity {
Barring other mistakes, one thing is clear that the construction of Intent is wrong, it should be:
Intent intent = new Intent(ResultActivity.this, ConceptActivity.class);
or
Intent intent = new Intent(this, ConceptActivity.class);
Quote:The Intent constructor takes two parameters:
A Context as its first parameter (this is used because the Activity class is a subclass of Context)
The Class of the app component to which the system should deliver the Intent (in this case, the activity that should be started).
Reference: Starting Another Activity | Android Developers[^]
这篇关于如何修正错误:“不是封闭的类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!