尝试在下拉列表项上选择名称时,应用程序崩溃

时间:2018-10-05 01:07:21

标签: android

company.class

myDb = new DatabaseHelper(this);
if ((item.equals("Bausing, Ian Lester G.")) || (item.equals("Coronel, Diana O.")) || (item.equals("Del Mundo, Chuckie P.")) || (item.equals("Macaspac, John Chris P.")) || (item.equals("Manalac, Romari C. ")) || (item.equals("Navarro, Joshua Calib O.")) || (item.equals("Vitangcul, Melvin P.")) || (item.equals("Querubin, Geo Isaiah M.")) || (item.equals("Ramos, Adrian Revo P.")))
                {
Cursor res = myDb.getAllData();
                    if (res.getCount() == 0) {

                    showMessage("Error", "Nothing found");
                    return;
                }
                dateArray = new String[1000];
                timeInArray = new String[1000];
                timeOutArray = new String[1000];
                idArray = new Integer[1000];

                StringBuffer buffer = new StringBuffer();

                resState = false;
                indexCount_final = 0;


                while (res.moveToNext()) {
                    buffer.append("           Date : " + res.getString(1) + "\n");
                    buffer.append("      Time In : " + res.getString(2) + "\n");
                    buffer.append("   Time Out : " + res.getString(3) + "\n");
                    buffer.append("   Hours Used : " + res.getString(5) + "\n");
                    buffer.append("Comments : " + res.getString(4) + "\n" + "\n");


                    if (res.getString(6).equals(username)) {

                        if(resState_2 == true)
                        {
                            firstRowIndex = res.getString(0);
                            resState_2 = false;
                            lastIndex_state = false;
                        }

                        idArray[arrayIndex] = Integer.parseInt(res.getString(0));
                        dateArray[arrayIndex] = res.getString(1);
                        timeInArray[arrayIndex] = res.getString(2);
                        timeOutArray[arrayIndex] = res.getString(3);
                        arrayIndex = arrayIndex + 1;

                        resSatte_3 = true;

                    }

                    else if((resSatte_3 == true) && (res.getString(6).equals(username)) == false){
                        if(lastIndex_state == false) {
                            lastRowIndex = String.valueOf(res.getString(0));
                            lastIndex_state = true;

                        }
                        indexCount = ((Integer.parseInt(lastRowIndex))) - Integer.parseInt(firstRowIndex);

                        resState = false;

                        indexCount_final = indexCount_final + indexCount;


                        resSatte_3 = false;

                        resState = true;
                        resState_2 = true;
                    }

                }
                if(lastIndex_state == false)
                {
                    res.moveToLast();
                    lastRowIndex = String.valueOf(res.getString(0));
             //***this part***//
                    indexCount_final = indexCount_final + indexCount;
              //**** to this part ***/
                }
                init_table();
}
}

});

    List<String> categories = new ArrayList<String>();
    categories.add("Name of Trainees");
    categories.add("Manalac, Romari C. ");
    categories.add("Navarro, Joshua Calib O.");
    categories.add("Querubin, Geo Isaiah M.");

    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, categories);


    dataAdapter.setDropDownViewResource(R.layout.spinner_item);


    name_spinner.setAdapter(dataAdapter);

    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}

登录后,然后尝试在下拉列表中选择名称时,应用程序崩溃。我发表了评论,其中我有错误。 我想做的是,在下拉列表中选择名称之后。它将在下拉列表上显示选择名称的记录。目前,我正在使用Firebase。

这是我的initTable

public void init_table() {
        TableLayout stk = (TableLayout) findViewById(R.id.table_main);
        TableRow tbrow0 = new TableRow(this);
    TextView tv1 = new TextView(this);
    tv1.setText(" Date ");
    tv1.setTextColor(Color.BLACK);
    tv1.setTextAppearance(this, android.R.style.TextAppearance_DeviceDefault_Medium);
    tbrow0.addView(tv1);
    TextView tv2 = new TextView(this);
    tv2.setText(" Time In ");
    tv2.setTextColor(Color.BLACK);
    tv2.setTextAppearance(this, android.R.style.TextAppearance_DeviceDefault_Medium);
    tbrow0.addView(tv2);
    TextView tv3 = new TextView(this);
    tv3.setText(" Time Out ");
    tv3.setTextColor(Color.BLACK);
    tv3.setTextAppearance(this, android.R.style.TextAppearance_DeviceDefault_Medium);
    tbrow0.addView(tv3);
    stk.addView(tbrow0);


    for (int i = 0; i < (indexCount_final); i++) {
        TableRow tbrow = new TableRow(this);
        TextView t2v = new TextView(this);
        t2v.setText(dateArray[i]);
        t2v.setTextColor(Color.BLACK);
        t2v.setGravity(Gravity.CENTER);
        tbrow.addView(t2v);
        TextView t3v = new TextView(this);
        t3v.setText(timeInArray[i]);
        t3v.setTextColor(Color.BLACK);
        t3v.setGravity(Gravity.CENTER);
        tbrow.addView(t3v);
        TextView t4v = new TextView(this);
        t4v.setText(timeOutArray[i]);
        t4v.setTextColor(Color.BLACK);
        t4v.setGravity(Gravity.CENTER);
        tbrow.addView(t4v);


        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        Button btnEdit = new Button(this);
        btnEdit.setText("Button " + i);
        btnEdit.setId(i + 1);
        final int id_ = btnEdit.getId();
        btnEdit.setText("Edit");

        btnEdit.setTextColor(Color.BLACK);
        tbrow.addView(btnEdit);

        btnEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "ID Clicked is " + String.valueOf(id_), Toast.LENGTH_SHORT).show();

                Cursor res = myDb.getAllData();
                if (res.getCount() == 0) {
                    // show message
                    showMessage("Error", "Nothing found");
                    return;
                }

                while (res.moveToNext()) {

                    if (res.getString(0).equals(String.valueOf(id_))) {

                        date_selected = res.getString(1);
                        timeIn_selected = res.getString(2);
                        timeOut_selected = res.getString(3);
                        hours_rend_selected = res.getString(4);
                        comment_selected = res.getString(5);
                        name_selected = res.getString(6);
                    }

                }
                LayoutInflater li = LayoutInflater.from(context);
                View promptsView = li.inflate(R.layout.prompts_company, null);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        context);

                alertDialogBuilder.setView(promptsView);

                final EditText userInput = (EditText) promptsView
                        .findViewById(R.id.editTextDialogUserInput);


                txtTimeIn = (TextView) promptsView.findViewById(R.id.txtTimeIn);
                txtTimeOut = (TextView) promptsView.findViewById(R.id.txtTimeOut);

                txtTimeIn.setText(timeIn_selected);
                txtTimeOut.setText(timeOut_selected);

                btnIn = (Button) promptsView.findViewById(R.id.btnTimeIn_company);
                btnOut = (Button) promptsView.findViewById(R.id.btnTimeOut_company);

                timePicker_company = (TimePicker) promptsView.findViewById(R.id.timePicker_company);

                alertDialogBuilder
                        .setCancelable(false)
                        .setPositiveButton("OK",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
myDb.updateData(String.valueOf(id_), date_selected, timeIn_selected, timeOut_selected, hours_rend_selected, comment_selected, name_selected);
                                            init_table();
                                        }
                                    })
                            .setNegativeButton("Cancel",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface 

dialog, int id) {
                                            dialog.cancel();
                                    }
                                });

                AlertDialog alertDialog = alertDialogBuilder.create();

                alertDialog.show();


            }
        });
        stk.addView(tbrow);
    }

}

“ indexCount_final = indexCount_final + indexCount;”存在问题 在下拉列表中选择名称后,应用程序崩溃了

1 个答案:

答案 0 :(得分:0)

如果您发布崩溃日志,可能会为查找崩溃原因提供很大帮助。 以我的猜测,我认为您应该关闭游标res。 如果不关闭游标,StrictMode会调用崩溃以防止泄漏。