当前位置: 代码迷 >> Android >> 小弟我一运行就报错,大神帮小弟我看看
  详细解决方案

小弟我一运行就报错,大神帮小弟我看看

热度:35   发布时间:2016-05-01 15:02:09.0
我一运行就报错,大神帮我看看
public class yuyue extends Activity{
private Spinner riqi =null;
private Spinner yewu=null;
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.yuyue);
  riqi=(Spinner)findViewById(R.id.riqi);
  yewu=(Spinner)findViewById(R.id.yewu);
  List<String> list =new ArrayList<String>();
  list.add("test1");
  list.add("test2");
  ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,android.R.layout.simple_dropdown_item_1line,list);
// ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this, R.array.planets_array,android.R.layout.simple_dropdown_item_1line);
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  riqi.setAdapter(adapter);
  riqi.setPrompt("日期");
  riqi.setOnItemSelectedListener(new riqiOnSelectedListener());
  Button button1=(Button)findViewById(R.id.yybtn);
  button1.setOnClickListener(new BListener());
  }
  class riqiOnSelectedListener implements OnItemSelectedListener{

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String selected=arg0.getItemAtPosition(arg2).toString();
System.out.println(selected);
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
System.out.println("nothingSelected ");
}
 
  }
  class BListener implements OnClickListener{

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(yuyue.this,xunze.class);
startActivity(intent);
}
 
 
  }
}

我测试了ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,android.R.layout.simple_dropdown_item_1line,list);
这句话有错,但是不知道错在哪里

------解决方案--------------------

ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,android.R.layout.simple_dropdown_item_1line,list);

改为:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, android.R.layout.simple_dropdown_item_1line, list);

或改为:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, list);

另外,建议发最新的yuyue.java全部内容和LogCat出错提示上来看看。
  相关解决方案