Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Katherine Goh
Katherine Goh
3,856 Points

problems with my codes = retrieving datas from mySQL

public class UpdateDeleteData extends AppCompatActivity {

    EditText item_name_et;
    String id, item_name;

    ProgressDialog PD;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_delete_data);

        PD = new ProgressDialog(this);
        PD.setMessage("please wait.....");
        PD.setCancelable(false);

        item_name_et = (EditText) findViewById(R.id.modify_item_et);
        Intent i = getIntent();

        HashMap<String, String> item = (HashMap<String, String>) i
                .getSerializableExtra("item");

        id = item.get(ReadData.ITEM_ID);
        item_name = item.get(ReadData.ITEM_NAME);

        item_name_et.setText(item_name);

    }

    public void update(View view) {
        PD.show();
        item_name = item_name_et.getText().toString();


        Map<String, String> params = new HashMap<String, String>();
        params.put("id", id);
        params.put("item_name",item_name);

        CustomRequest update_request = new CustomRequest(Request.Method.POST, AppConfig.URL_UPDATE_GRP, params, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {

                try{
                    int success = response.getInt("success");

                    if (success == 1) {
                        PD.dismiss();
                        Toast.makeText(getApplicationContext(),
                                "Updated Successfully",
                                Toast.LENGTH_SHORT).show();
                        // redirect to readdata
                        MoveToReadData();

                    } else {
                        PD.dismiss();
                        Toast.makeText(getApplicationContext(),
                                "failed to update", Toast.LENGTH_SHORT)
                                .show();
                    }
                }
                catch (Exception e){
                    PD.dismiss();
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError response) {
                PD.dismiss();
            }
        });


        // Adding request to request queue
        MyApplication.getInstance().addToReqQueue(update_request);
    }


    public void delete(View view) {
        PD.show();


// start of error

        JsonObjectRequest delete_request = new JsonObjectRequest(AppConfig.URL_DELETE_GRP + id,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {

                        try {
                            int success = response.getInt("success");

                            if (success == 1) {
                                PD.dismiss();
                                Toast.makeText(getApplicationContext(),
                                        "Deleted Successfully",
                                        Toast.LENGTH_SHORT).show();
                                // redirect to readdata
                                MoveToReadData();
                            } else {
                                PD.dismiss();
                                Toast.makeText(getApplicationContext(),
                                        "failed to delete", Toast.LENGTH_SHORT)
                                        .show();
                            }

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

                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }); 
//end of error

        // Adding request to request queue
        MyApplication.getInstance().addToReqQueue(delete_request);

    }

    private void MoveToReadData() {
        Intent read_intent = new Intent(UpdateDeleteData.this, ReadData.class)
                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        startActivity(read_intent);

    }
}
aakarshrestha
aakarshrestha
6,509 Points

Whats the error you're getting?

Happy coding!

2 Answers

Katherine Goh
Katherine Goh
3,856 Points

There's 2 error i got from the gradle build:

Error:(129, 62) error: incompatible types: int cannot be converted to String

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

What happened was,, I have an mobile app that I am working with and I wanted to add a new feature of adding, deleting, edit_updating, data through MySQL. i found some sources on-line and tested the program to find it working well. however upon merging with my mobile app, this problem occurred.