Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 活动未启动,空指针异常_Android - Fatal编程技术网

Android 活动未启动,空指针异常

Android 活动未启动,空指针异常,android,Android,当我尝试调用活动时,我的应用程序崩溃。它也使用数据库,但问题可能不存在。它在使用setText方法的行上显示错误。有人能提出一些解决办法吗。提前谢谢 这是我的密码 public class EventsShower extends BaseActivity{ private DBHelper dbHelper; private SQLiteDatabase db; private Cursor cursor; private int[] colors =

当我尝试调用活动时,我的应用程序崩溃。它也使用数据库,但问题可能不存在。它在使用setText方法的行上显示错误。有人能提出一些解决办法吗。提前谢谢

这是我的密码

    public class EventsShower extends BaseActivity{

    private DBHelper dbHelper;
    private SQLiteDatabase db;
    private Cursor cursor;
    private int[] colors = new int[2];
    private String eventS, dateS, timeS, done;

//    @Override
//    protected void onDestroy() {
//        db.close();
//        dbHelper.close();
//        cursor.close();
//        super.onDestroy();
//    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.events_shower);

        colors[0] = Color.parseColor("#DF5D5D");
        colors[1] = Color.parseColor("#5077C9");


        LinearLayout linearLayout = (LinearLayout)findViewById(R.id.linLayout);
        LayoutInflater inflater = getLayoutInflater();

//        TextView tvEvent = (TextView)findViewById(R.id.tvEvent);
//        TextView tvDate = (TextView)findViewById(R.id.tvDate);
//        TextView tvTime = (TextView)findViewById(R.id.tvTime);


        dbHelper = new DBHelper(this);
        db = dbHelper.getWritableDatabase();

        String[] columns = new String[]{DBHelper.DATE, DBHelper.TIME, DBHelper.EVENT, DBHelper.DONE};
        cursor = db.query(DBHelper.TABLE_NAME, columns, null, null, null, null, null);

        cursor.moveToFirst();
        do{
            View item = inflater.inflate(R.layout.item, linearLayout, false);
//            eventS = cursor.getString(cursor.getColumnIndex(DBHelper.EVENT));
//            dateS = cursor.getString(cursor.getColumnIndex(DBHelper.DATE));
//            timeS = cursor.getString(cursor.getColumnIndex(DBHelper.TIME));
            Log.i("myLogs", eventS + "--" + dateS + "--" + timeS);
            TextView tvEvent = (TextView)findViewById(R.id.tvEvent);
            tvEvent.setText(cursor.getString(cursor.getColumnIndex(DBHelper.EVENT)));
            TextView tvDate = (TextView)findViewById(R.id.tvDate);
            tvDate.setText(cursor.getString(cursor.getColumnIndex(DBHelper.DATE)));
            TextView tvTime = (TextView)findViewById(R.id.tvTime);
            tvTime.setText(cursor.getString(cursor.getColumnIndex(DBHelper.TIME)));

            if(cursor.getString(cursor.getColumnIndex(DBHelper.DONE)).equals("1")) {
                done = "Done";
            }else {
                done = "Pending";
            }

            if(cursor.getString(cursor.getColumnIndex(DBHelper.DONE)).equals("1")) {
                item.setBackgroundColor(colors[0]);
            } else {
                item.setBackgroundColor(colors[1]);
            }
            linearLayout.addView(item);
            if(cursor.isLast()) {
//                eventS = cursor.getString(cursor.getColumnIndex(DBHelper.EVENT));
//                dateS = cursor.getString(cursor.getColumnIndex(DBHelper.DATE));
//                timeS = cursor.getString(cursor.getColumnIndex(DBHelper.TIME));

                tvEvent.setText(cursor.getString(cursor.getColumnIndex(DBHelper.EVENT)));

                tvDate.setText(cursor.getString(cursor.getColumnIndex(DBHelper.DATE)));

                tvTime.setText(cursor.getString(cursor.getColumnIndex(DBHelper.TIME)));
                if(cursor.getString(cursor.getColumnIndex(DBHelper.DONE)).equals("1")) {
                    done = "Done";
                }else {
                    done = "Pending";
                }


                if(cursor.getString(cursor.getColumnIndex(DBHelper.DONE)).equals("1")) {
                    item.setBackgroundColor(colors[0]);
                } else {
                    item.setBackgroundColor(colors[1]);
                }
                linearLayout.addView(item);
                cursor.close();
            }
            cursor.moveToNext();
        }while(cursor.moveToNext());


    }

}
还有我的日志

12-05 09:46:08.386    2449-2449/com.example.kg2152.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kg2152.example/com.example.kg2152.example.EventsShower}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.example.kg2152.example.EventsShower.onCreate(EventsShower.java:60)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
可能R.id.tvEvent和其他视图属于R.layout.item,因此,您应该使用item检索其中的对象。例如

    View item = inflater.inflate(R.layout.item, linearLayout, false);
    TextView tvEvent = (TextView)item.findViewById(R.id.tvEvent);
可能R.id.tvEvent和其他视图属于R.layout.item,因此,您应该使用item检索其中的对象。例如

    View item = inflater.inflate(R.layout.item, linearLayout, false);
    TextView tvEvent = (TextView)item.findViewById(R.id.tvEvent);

事件显示的60行上有什么?@Suvitruf tvEvent.setTextcursor.getStringcursor.getColumnIndexDBHelper.EVENT;事件显示的60行上有什么?@Suvitruf tvEvent.setTextcursor.getStringcursor.getColumnIndexDBHelper.EVENT;