samedi 27 février 2016

AlertDialogue Error String resource ID #0x1

I am building an app which after you input some parameter(P1,P2,P3) and click save, will pop an alertdialogue requesting a number, after the user keyin this number, the program will input the information (P1,P2,P3) in a sqlite register table T1. And it will create as many entries as the user define in the alertdialogue in a sqlite T2.

Basically I have the next code:

 switch(item.getItemId()){
        case R.id.Save:

            final String UpdateStudyCode = eStudyCode.getText().toString();
            final String UpdateStudyDescription = eStudyDescription.getText().toString();
            final String UpdateStudyAnalyst = eStudyAnalyst.getText().toString();

            if( l == 0){
            //New Register Study
                if (UpdateStudyCode == ""){
                    Toast.makeText(getApplicationContext(), "Empty Study Code", Toast.LENGTH_SHORT).show();
                }
                else{                       
                    AlertDialog.Builder dialogCreateElements = new AlertDialog.Builder(this);

                    dialogCreateElements.setIcon(android.R.drawable.ic_dialog_alert);
                    dialogCreateElements.setTitle(getResources().getString(R.string.element_create_title));
                    dialogCreateElements.setMessage(getResources().getString(R.string.element_create_messaje));
                    final EditText inputelementstarget = new EditText(this);
                    //dialogCreateElements.setInputType(InputType.TYPE_CLASS_PHONE);
                    //dialogCreateElements.setRawInputType(Configuration.KEYBOARD_12KEY);
                    dialogCreateElements.setView(inputelementstarget);
                    dialogCreateElements.setCancelable(false);
                    dialogCreateElements.setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {   
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // TODO Auto-generated method stub
                            database db = new database (studydetail.this);
                            db.open();
                            //Create Study
                            long studyid;
                            studyid = db.createEntryStudy(UpdateStudyCode,UpdateStudyDescription,UpdateStudyAnalyst);
                            //Create number of specific elements 
                            int element=1;
                            String value = inputelementstarget.getText().toString();
                            int target = Integer.parseInt(value);
                            do
                            {
                                Toast.makeText(getApplicationContext(), element, Toast.LENGTH_SHORT).show();
                                db.createEntryElements(element, studyid);
                                element++;
                            }
                            while (element < target+1);

                            db.close();

                            Toast.makeText(studydetail.this, R.string.element_create_confirmation, Toast.LENGTH_SHORT).show();
                            setResult(RESULT_OK);

                        }
                    });

                  dialogCreateElements.setNegativeButton(android.R.string.no, null);
                  dialogCreateElements.show();

Currently I receive the next error and only the entry in T1 is created FATAL EXCEPTION:

 main
 Process: com.example.standardtime, PID: 1873
 android.content.res.Resources$NotFoundException: String resource ID #0x1
 at android.content.res.Resources.getText(Resources.java:274)
 at android.widget.Toast.makeText(Toast.java:277)
 at com.example.standardtime.studydetail$1.onClick(studydetail.java:121)
 at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:160)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Aucun commentaire:

Enregistrer un commentaire