java.lang.RuntimeException:无法启动活动{....}:java.lang.NullPointerException

时间:2014-06-29 16:19:56

标签: android

当我尝试输入活动时,我收到此错误并且程序失败:

java.lang.RuntimeException:无法启动活动ComponentInfo {...}:java.lang.NullPointerException

我的活动代码:

private Button addbut;
private ListView List1;
private ListAdapter listadapt;
private ArrayList <ReminderDetails>reminderArrayList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.remindlist);

    List1=(ListView)findViewById(R.id.listView1);
    List1.setOnItemClickListener(this);

    addbut=(Button)findViewById(R.id.Addbutton1);
    addbut.setOnClickListener(this);

    reminderArrayList=new ArrayList<ReminderDetails>();
    listadapt=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,populateList());

    List1.setAdapter(listadapt);
}

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


    public List<String>populateList(){
        List<String>reminderList =new ArrayList<String>();

        AndroidOpenDbHelper openHelperClass = new AndroidOpenDbHelper(this);

        SQLiteDatabase sqliteDatabase=openHelperClass.getReadableDatabase();

        Cursor cursor = sqliteDatabase.query(AndroidOpenDbHelper.TABLE_NAME_REMINDER, null, null, null, null, null, null);
        startManagingCursor(cursor);

        while(cursor.moveToNext()){
            String remindName= cursor.getString(cursor.getColumnIndex(AndroidOpenDbHelper.COLUMN_NAME_REMINDER_NAME));
            String remindDate= cursor.getString(cursor.getColumnIndex(AndroidOpenDbHelper.COLUMN_NAME_REMINDER_DATE));
            String remindTime= cursor.getString(cursor.getColumnIndex(AndroidOpenDbHelper.COLUMN_NAME_REMINDER_TIME));

            ReminderDetails rmDetails = new ReminderDetails();
            rmDetails.setreminderName(remindName);
            rmDetails.setreminderDate(remindDate);
            rmDetails.setreminderTime(remindTime);

            reminderArrayList.add(rmDetails);

            reminderList.add(remindName);
        }

        sqliteDatabase.close();

        return reminderList;
    }


@Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        reminderArrayList=new ArrayList<ReminderDetails>();
        listadapt=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,populateList());
        List1.setAdapter(listadapt);
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        reminderArrayList=new ArrayList<ReminderDetails>();
        listadapt=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,populateList());
        List1.setAdapter(listadapt);
    }

    public void onItemClick(AdapterView<?> i,View j,int k,long m){
        Toast.makeText(getApplicationContext(),"Clicked on :"+k,Toast.LENGTH_SHORT).show();
        Intent updateDeleteReminderIntent=new Intent(this,UpdateDeleteReminderActivity.class);

        ReminderDetails clickedObject= reminderArrayList.get(k);

        Bundle dataBundle= new Bundle();
        dataBundle.putString("ClickedReminderName", clickedObject.getreminderName());
        dataBundle.putString("ClickedReminderDate", clickedObject.getreminderDate());
        dataBundle.putString("ClickedReminderTime", clickedObject.getreminderTime());

        updateDeleteReminderIntent.putExtras(dataBundle);

        startActivity(updateDeleteReminderIntent);
    }

}

日志猫

06-29 16:52:59.534: E/MediaPlayer(16798): Should have subtitle controller already set
06-29 16:53:24.397: D/AndroidRuntime(16798): Shutting down VM
06-29 16:53:24.397: W/dalvikvm(16798): threadid=1: thread exiting with uncaught exception (group=0x416fbd40)
06-29 16:53:24.401: E/AndroidRuntime(16798): FATAL EXCEPTION: main
06-29 16:53:24.401: E/AndroidRuntime(16798): Process: com.example.newproject, PID: 16798
06-29 16:53:24.401: E/AndroidRuntime(16798): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newproject/com.example.newproject.RemindMe}: java.lang.NullPointerException
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.ActivityThread.access$800(ActivityThread.java:139)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.os.Handler.dispatchMessage(Handler.java:102)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.os.Looper.loop(Looper.java:136)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.ActivityThread.main(ActivityThread.java:5102)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at java.lang.reflect.Method.invokeNative(Native Method)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at java.lang.reflect.Method.invoke(Method.java:515)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at dalvik.system.NativeStart.main(Native Method)
06-29 16:53:24.401: E/AndroidRuntime(16798): Caused by: java.lang.NullPointerException
06-29 16:53:24.401: E/AndroidRuntime(16798):    at com.example.newproject.RemindMe.populateList(RemindMe.java:63)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at com.example.newproject.RemindMe.onCreate(RemindMe.java:43)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.Activity.performCreate(Activity.java:5248)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
06-29 16:53:24.401: E/AndroidRuntime(16798):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
06-29 16:53:24.401: E/AndroidRuntime(16798):    ... 11 more
06-29 16:53:25.943: I/Process(16798): Sending signal. PID: 16798 SIG: 9

0 个答案:

没有答案