1

该代码已与 arraylist 一起使用。一旦更改为 arraylist 对象类遇到异常问题。

W/dalvikvm(978):threadid=1:线程以未捕获的异常退出(组=0x40a13300)

package com.example.dodolist;
import java.util.Date;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Context;
import android.content.Intent;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
import java.util.ArrayList;


public class Main extends Activity {

Button button;
private ListView mListView;
ArrayList<Task> mArrList;


@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mArrList = new ArrayList<Task>();
    addListenerOnButton();

    Bundle b =  getIntent().getExtras();

    if(b != null)
    {
        mArrList = (ArrayList<Task>) b.getSerializable("mArrList");

        //Initialize the UI components
        mListView = (ListView) findViewById(R.id.listView);
        ArrayAdapter<Task> adapter = new ArrayAdapter<Task>(this, android.R.layout.simple_list_item_1, mArrList);
        mListView.setAdapter(adapter);

    }
}

public void addOverAllTasks(String task) {


    //Initialize the UI components
    mListView = (ListView) findViewById(R.id.listView);
    final Context context = this;

    //Object Class
    //Date currentDate = new Date();
    Task newTask = new Task(task);

    mArrList.add(newTask);

    //refresh the view
    ArrayAdapter<Task> adapter = new ArrayAdapter<Task>(this, android.R.layout.simple_list_item_1, mArrList);
    mListView.setAdapter(adapter);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {


        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Intent intent = new Intent(context, AddTask.class);

            intent.putExtra("mArrList", mArrList);
            intent.putExtra("arrIndex", position);
            startActivity(intent);
        }

    });


}




public void addListenerOnButton() {

    button = (Button) findViewById(R.id.AddTaskBtn);
    button.setOnClickListener(new OnClickListener () {

        @Override
        public void onClick(View v) {


            //store your new task title
            EditText edit_text = (EditText)findViewById(R.id.AddTaskBox);


            Globals g = Globals.getInstance();
            String taskName = edit_text.getText().toString(); // gets the data into string
            g.setData(taskName);

            //Add Tasks into array
            addOverAllTasks(edit_text.getText().toString());

        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}


public void Spinner() {

    Spinner spinner = (Spinner) findViewById(R.id.actionBar);

    //Create an ArrayAdapter using the string array and a default spinner layout

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
 R.array.actionBar_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);
}
}

这是一个例外:

11-05 20:07:16.156: W/dalvikvm(978): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-05 20:07:16.206: E/AndroidRuntime(978): FATAL EXCEPTION: main
11-05 20:07:16.206: E/AndroidRuntime(978): java.lang.RuntimeException: Parcel: unable to marshal value uy
11-05 20:07:16.206: E/AndroidRuntime(978): at android.os.Parcel.writeValue(Parcel.java:1235)
11-05 20:07:16.206: E/AndroidRuntime(978): at android.os.Parcel.writeList(Parcel.java:622)
11-05 20:07:16.206: E/AndroidRuntime(978): at android.os.Parcel.writeValue(Parcel.java:1195)
11-05 20:07:16.206: E/AndroidRuntime(978
4

0 回答 0