void 是此变量的无效类型 [英] void is an invalid type for this variable
本文介绍了void 是此变量的无效类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误:
void 是变量 onRadioButtonClicked 的无效类型
void is an invalid type for the variable onRadioButtonClicked
但是开发者网站说void是必须的!那么问题出在哪里呢?xml 的编码是正确的.. 问题一定出在这里:
But the developer site says that void is a must! So where is the problem? The coding of the xml's is correc.. The problem must lie somewhere here:
package com.example.kernel.version;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
public class MainPage extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
setContentView(R.layout.activity_main_page);
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radio_pirates:
if (checked)
// Pirates are the best
break;
case R.id.radio_ninjas:
if (checked)
// Ninjas rule
break;
}
}
推荐答案
您的 onRadioButtonClicked
包含在您的 onCreate
方法中—使它们成为独立的方法.在:
Your onRadioButtonClicked
is contained within your onCreate
method—make them separate methods. Add a closing brace }
after:
setContentView(R.layout.activity_main_page);
这篇关于void 是此变量的无效类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文