线程在更新操作时退出未捕获的异常

时间:2017-04-26 09:00:37

标签: java android mysql crash uncaught-exception

我正在创建一个Android应用程序,对本地主机MySQL数据库上的数据执行添加,更新和删除操作。除了更新部分,一切正常。我试图更新数据时会在活动ViewFeedingSched上发生。按下更新按钮时或仅在调用更新功能时,应用程序崩溃。 logcat给出了一条消息:threadid=1: thread exiting with uncaught exception (group=0x41640c80).

更新即可。这是从logcat获得的json

04-26 18:19:32.550 26244-26244/com.aps.thesisit.aps I/TAG: Should be json<br />
                                                           <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
                                                           <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: id in C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php on line <i>10</i></th></tr>
                                                           <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
                                                           <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
                                                           <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>235496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php' bgcolor='#eeeeec'>...\getSelectedFeedSched.php<b>:</b>0</td></tr>
                                                           </table></font>
                                                           <br />
                                                           <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
                                                           <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php on line <i>17</i></th></tr>
                                                           <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
                                                           <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
                                                           <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>235496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php' bgcolor='#eeeeec'>...\getSelectedFeedSched.php<b>:</b>0</td></tr>
                                                           <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.2416</td><td bgcolor='#eeeeec' align='right'>246392</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mysqli-fetch-array' target='_new'>mysqli_fetch_array</a>
                                                           (  )</td><td title='C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php' bgcolor='#eeeeec'>...\getSelectedFeedSched.php<b>:</b>17</td></tr>
                                                           </table></font>
                                                           {"result":[{"schedno":null,"feedtime":null,"feedamt":null}]}
04-26 18:19:32.550 26244-26244/com.aps.thesisit.aps I/TAG: Should be json<br />
                                                           <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
                                                           <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: id in C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php on line <i>10</i></th></tr>
                                                           <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
                                                           <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
                                                           <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>235496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php' bgcolor='#eeeeec'>...\getSelectedFeedSched.php<b>:</b>0</td></tr>
                                                           </table></font>
                                                           <br />
                                                           <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
                                                           <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php on line <i>17</i></th></tr>
                                                           <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
                                                           <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
                                                           <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0019</td><td bgcolor='#eeeeec' align='right'>235496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php' bgcolor='#eeeeec'>...\getSelectedFeedSched.php<b>:</b>0</td></tr>
                                                           <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.2416</td><td bgcolor='#eeeeec' align='right'>246392</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mysqli-fetch-array' target='_new'>mysqli_fetch_array</a>
                                                           (  )</td><td title='C:\wamp64\www\feedingschedHTTP\getSelectedFeedSched.php' bgcolor='#eeeeec'>...\getSelectedFeedSched.php<b>:</b>17</td></tr>
                                                           </table></font>
                                                           {"result":[{"schedno":null,"feedtime":null,"feedamt":null}]}

ViewFeedingSched类

public class ViewFeedingSched extends AppCompatActivity implements View.OnClickListener {


    private EditText editTextFeedAmt;

    private TextView textViewCurrentTimeSet;
    private TextView textViewIDSelected;
    //private TextView textViewCurrentAmtSet;

    private NumberPicker numPickerHr;
    private NumberPicker numPickerMin;

    //private Spinner spinnerFeedAmt;
    //ArrayAdapter<CharSequence> adapter;

    private Button buttonUpdate;
    private Button buttonDelete;

    private String id;
    private String ftime;
    // private String famt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_feeding_sched);

        Intent intent = getIntent();

        id = intent.getStringExtra(Config.SCHED_ID);
        ftime = intent.getStringExtra(Config.FEEDTIME);


        textViewCurrentTimeSet = (TextView) findViewById(R.id.TV_CurrentTimeSet);
        textViewIDSelected = (TextView) findViewById(R.id.TV_PickedSchedID);

        buttonUpdate = (Button) findViewById(R.id.BT_UpdateSched);
        buttonDelete = (Button) findViewById(R.id.BT_DeleteSched);

        buttonUpdate.setOnClickListener(this);
        buttonDelete.setOnClickListener(this);

        textViewIDSelected.setText(id);
        textViewCurrentTimeSet.setText(ftime);

        numPickerHr = (NumberPicker) findViewById(R.id.NP_Hour);
        numPickerHr.setMinValue(0);
        numPickerHr.setMaxValue(23);
        numPickerHr.setWrapSelectorWheel(true);

        numPickerMin = (NumberPicker) findViewById(R.id.NP_Min);
        numPickerMin.setMinValue(0);
        numPickerMin.setMaxValue(59);
        numPickerMin.setWrapSelectorWheel(true);


        getSchedule();
    }


    private void getSchedule(){
        class GetSchedule extends AsyncTask<Void,Void,String>{
            ProgressDialog loading;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewFeedingSched.this,"Fetching...","Wait...",false,false);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                showSchedule(s);
            }

            @Override
            protected String doInBackground(Void... params) {
                RequestHandler rh = new RequestHandler();
                String s = rh.sendGetRequestParam(Config.URL_GET_SCHED,id);
                return s;
            }
        }
        GetSchedule ge = new GetSchedule();
        ge.execute();
    }

    private void showSchedule(String json){
        try {
            JSONObject jsonObject = new JSONObject(json);
            JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
            JSONObject c = result.getJSONObject(0);
            String feedtime = c.getString(Config.TAG_FEEDTIME);

            textViewCurrentTimeSet.setText(feedtime);

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private void updateSchedule(){

        final String feedamt = editTextFeedAmt.getText().toString().trim();
        final String NP_FeedTime_HR = String.valueOf(numPickerHr.getValue()).trim();
        final String NP_FeedTime_MIN = String.valueOf(numPickerMin.getValue()).trim();

        class UpdateSchedule extends AsyncTask<Void,Void,String>{
            ProgressDialog loading;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewFeedingSched.this,"Updating...","Wait...",false,false);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                Toast.makeText(ViewFeedingSched.this,s,Toast.LENGTH_LONG).show();
            }

            @Override
            protected String doInBackground(Void... params) {
                HashMap<String,String> hashMap = new HashMap<>();
                hashMap.put(Config.KEY_SCHED_ID,id);
                hashMap.put(Config.KEY_FEED_TIME,NP_FeedTime_HR+":"+NP_FeedTime_MIN+":00");
                hashMap.put(Config.KEY_FEED_AMT,feedamt);

                RequestHandler rh = new RequestHandler();

                String s = rh.sendPostRequest(Config.URL_UPDATE_SCHED,hashMap);

                return s;
            }
        }

        UpdateSchedule ue = new UpdateSchedule();
        ue.execute();
    }

    private void deleteSchedule(){
        class DeleteSchedule extends AsyncTask<Void,Void,String> {
            ProgressDialog loading;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewFeedingSched.this, "Updating...", "Wait...", false, false);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                Toast.makeText(ViewFeedingSched.this, s, Toast.LENGTH_LONG).show();
            }

            @Override
            protected String doInBackground(Void... params) {
                RequestHandler rh = new RequestHandler();
                String s = rh.sendGetRequestParam(Config.URL_DELETE_SCHED, id);
                return s;
            }
        }

        DeleteSchedule de = new DeleteSchedule();
        de.execute();
    }

    private void confirmDeleteSchedule(){
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage("Are you sure you want to delete this schedule?");

        alertDialogBuilder.setPositiveButton("Yes",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        deleteSchedule();
                        startActivity(new Intent(ViewFeedingSched.this,FeedingScheduleList.class));
                    }
                });

        alertDialogBuilder.setNegativeButton("No",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {

                    }
                });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }


    @Override
    public void onClick(View v) {
        if(v == buttonUpdate){
            updateSchedule();
        }

        if(v == buttonDelete){
            confirmDeleteSchedule();
        }
    }
}

在参加观看活动时的LOGCAT消息

04-26 16:57:00.490 31406-31406/com.aps.thesisit.aps E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
04-26 16:57:00.490 31406-31406/com.aps.thesisit.aps W/dalvikvm: VFY: unable to resolve instanceof 153 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
04-26 16:57:00.600 31406-31961/com.aps.thesisit.aps I/System.out: [socket][0] connection /192.168.254.103:8080;LocalPort=50670(0)
04-26 16:57:00.600 31406-31961/com.aps.thesisit.aps I/System.out: [CDS]connect[/192.168.254.103:8080]
04-26 16:57:00.620 31406-31961/com.aps.thesisit.aps I/System.out: [CDS]port[50670]
04-26 16:57:00.620 31406-31961/com.aps.thesisit.aps I/System.out: [socket][/192.168.254.101:50670] connected
04-26 16:57:00.620 31406-31961/com.aps.thesisit.aps I/System.out: [CDS]rx timeout:0
04-26 16:57:00.670 31406-31961/com.aps.thesisit.aps I/System.out: [CDS]rx timeout:100
04-26 16:57:00.670 31406-31961/com.aps.thesisit.aps I/System.out: [CDS]rx timeout:0
04-26 16:57:03.630 31406-31406/com.aps.thesisit.aps I/dalvikvm-heap: Grow heap (frag case) to 9.523MB for 2362992-byte allocation
04-26 16:57:03.740 31406-32092/com.aps.thesisit.aps I/System.out: [CDS]rx timeout:0
04-26 16:57:04.190 31406-32092/com.aps.thesisit.aps I/System.out: [CDS]rx timeout:100
04-26 16:57:04.190 31406-32092/com.aps.thesisit.aps I/System.out: [CDS]rx timeout:0
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:159)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:172)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at com.aps.thesisit.aps.ViewFeedingSched.showSchedule(ViewFeedingSched.java:117)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at com.aps.thesisit.aps.ViewFeedingSched.access$000(ViewFeedingSched.java:28)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at com.aps.thesisit.aps.ViewFeedingSched$1GetSchedule.onPostExecute(ViewFeedingSched.java:101)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at com.aps.thesisit.aps.ViewFeedingSched$1GetSchedule.onPostExecute(ViewFeedingSched.java:89)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at android.os.AsyncTask.finish(AsyncTask.java:632)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at android.os.AsyncTask.access$600(AsyncTask.java:177)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at android.os.Looper.loop(Looper.java:136)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5291)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-26 16:57:04.210 31406-31406/com.aps.thesisit.aps W/System.err:     at dalvik.system.NativeStart.main(Native Method)

按下更新按钮后的LOGCAT消息

04-26 16:58:14.790 31406-31406/com.aps.thesisit.aps W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41640c80)

0 个答案:

没有答案