0

Im получает ClassCastException в этой строке. .putStringArrayListExtra ("list", (ArrayList) listItems)); Я пытаюсь отправить содержимое ListView в другое действие.Почему ClassCastException?

Я не могу сказать, почему. Может кто-нибудь помочь.

private double overallTotalproduct; 
public static TextView resultTextView; 

ArrayList<String> listItems=new ArrayList<String>(); 
ArrayAdapter<String> adapter; 

private Button whateverButton; 
    TextView inputPrice; 
    RelativeLayout lay1; 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.menuview); 

    adapter=new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, 
      listItems); 
      setListAdapter(adapter); 

whateverButton = (Button)findViewById(R.id.whateverButton); 
inputPrice= (TextView)findViewById(R.id.inputPrice); 
lay1= (RelativeLayout)findViewById(R.id.lay1); 


//Total Box 
final TextView textViewtotalproduct = (TextView) findViewById(R.id.inputPrice); 

final TextView textView1 = (TextView) findViewById(R.id.m1aa); 
final String stringm1aa = textView1.getText().toString(); 
final double intm1aa = Double.parseDouble(stringm1aa); 
final TextView textView1a = (TextView) findViewById(R.id.m1a); 
final String stringm1a = textView1a.getText().toString(); 

    lay1.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     listItems.add("$"+intm1aa +"-"+ stringm1a); 
     adapter.notifyDataSetChanged(); 
     resultTextView.setText(stringm1a); 
     overallTotalproduct = intm1aa + overallTotalproduct; 
     textViewtotalproduct.setText(String.valueOf(overallTotalproduct)); 
    } 
}); 

    public void onwhateverPress(View v) { 
    Intent whateverIntent = new Intent(this, WhateverActivity.class); 

if (whateverResult.iswhateveranicewhatever()) { 

final TextView daplane =(TextView)findViewById(R.id.date); 
String watch = daplane.getText().toString(); 



startActivity(new Intent(MenuView1Activity.this,RecordCheckActivity.class) 
.putExtra("date",(CharSequence)watch) 

//THIS IS THE LINE IM GETTING THE ERROR ON 
.putStringArrayListExtra("list", (ArrayList<String>) listItems)); 
finish(); 

И вторая активность

Intent id11 = getIntent(); 
if (id11.getCharSequenceExtra("list") != null) { 
final TextView setmsg = (TextView)findViewById(R.id.saleNotes); 
setmsg.setText(id11.getCharSequenceExtra("list"));    

} 
+0

Возможно, полезно для вашего случая: http://stackoverflow.com/q/4030115/513413 – Hesam

+0

Вы также должны опубликовать макет. Возможно, вы плохо извлекаете некоторые из своих виджетов. – Daniel

+0

Если я удалю одну проблему, все будет работать отлично. – SmulianJulian

ответ

2

У вас уже есть:

ArrayList<String> listItems=new ArrayList<String>(); 

Тогда почему ты кастинг ListItems в ArrayList здесь ???:

.putStringArrayListExtra("list", (ArrayList<String>) listItems)); 

Просто выполните следующие действия:

.putStringArrayListExtra("list", listItems)); 
+0

Это ответ. Спасибо, вы знаете, как получить намерение в другой деятельности setText не работает – SmulianJulian

Смежные вопросы