我是Android编程的新手,我正在尝试实现一个微调器,但是我得到了setOnItemSelectedListener,setDropDownViewResource和setAdapter的“无法解析符号”错误。我很难过。我尝试添加更多导入,但他们没有做任何事情。
这是我的代码:
public class MainActivity extends AppCompatActivity implements OnItemSelectedListener {
public final static String EXTRA_MESSAGE = "com.example.FinalProject.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.verb_endings_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
答案 0 :(得分:2)
移动此
Exception in thread "main" java.lang.StackOverflowError
at java.lang.Integer.toString(Integer.java:402)
at TMS.check_move(TMS.java:70)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
at TMS.check_move(TMS.java:79)
at TMS.check_move(TMS.java:95)
.
.
.
.
(GOES ON FOREVER)
在 onCreate 方法中,但是在外面声明微调器,(您希望以后可以使用它...:))
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);