当前位置: 代码迷 >> Android >> 请帮看上上面的Hello World如何也报错啊
  详细解决方案

请帮看上上面的Hello World如何也报错啊

热度:57   发布时间:2016-05-01 15:07:52.0
请帮看下下面的Hello World怎么也报错啊?
Java code
package com.example.lucky;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.*;import android.view.*;import android.widget.AdapterView.*;import android.widget.ArrayAdapter;import android.widget.AdapterView.OnItemSelectedListener;public class MainActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Spinner sp1 = (Spinner) findViewById(R.id.spinner1);        final String[] chooseStr = { "A", "B", "C" };        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,                android.R.layout.simple_spinner_item, chooseStr);        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);        sp1.setPrompt("请选择:");        sp1.setAdapter(adapter);        sp1.setOnItemSelectedListener(new OnItemSelectedListener() {            @Override[color=#FF0000]//这里报错:Description    Resource    Path    Location    TypeThe method onItemSelected(AdapterView<?>, View, int, long) of type new AdapterView.OnItemSelectedListener(){} must override a superclass method    MainActivity.java    /Lucky/src/com/example/lucky    line 33    Java Problem[/color]            public void onItemSelected(AdapterView<?> arg0, View arg1,                    int arg2, long arg3) {                System.out.println("Hello, world");            }            @Override            public void onNothingSelected(AdapterView<?> arg0) {                //            }         });    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        getMenuInflater().inflate(R.menu.activity_main, menu);        return true;    }}


------解决方案--------------------
貌似是Compiler compliance level的问题,5.0不支持override,需要改成6.0

修改路径是,在myeclipse下:Windows--Preferences--Java--Compiler,在右边的Compiler compliance level 修改版本为 6.0,就可以了
------解决方案--------------------
删掉项目,重新导入就可以了。
  相关解决方案