Lost-Found program problem("error: incompatible types: int cannot be converted to String")

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

May 3, 2018 7:34:44 PM via Website

Well at first I would want to say that I'm preety new to android studios:D.
Anyway this is a problem that I get:image

full program in text file is here:

package com.example.madcoala.zavrsnirad;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
EditText vlasnik, stvar, opis;
//EditText firstname,lastname;
Button insert, show;
TextView result;
RequestQueue requestQueue;
String insertUrl = "----//192.168.1.8:1234/insertIzgubljeno.php";
String showUrl = "----//192.168.1.8:1234/showIzgubljeno.php";

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

    vlasnik = (EditText) findViewById(R.id.editText);
    stvar = (EditText) findViewById(R.id.editText2);
    opis = (EditText) findViewById(R.id.editText3);
    insert = (Button) findViewById(R.id.insert);
    show = (Button) findViewById(R.id.show);
    result = (TextView) findViewById(R.id.textView);
    requestQueue = Volley.newRequestQueue(getApplicationContext());
    show.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
                    showUrl, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONArray lost = response.getJSONArray("lost");
                        int i;
                        for (i = 0; i < lost.length(); i++) {
                            JSONObject izgubljeno = lost.getJSONObject(i);

                            String vlasnik = izgubljeno.getString("vlasnik");
                            String stvar = izgubljeno.getString("stvar");
                            String opis = izgubljeno.getString("opis");
                            result.append(vlasnik + " " + stvar + " " + opis + "\n");
                        }
                        result.append("===\n");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });
            requestQueue.add(jsonObjectRequest);
        }
    });

    insert.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }) {
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> parameters = new HashMap<String, String>();
                    parameters.put("vlasnik", vlasnik.getText().toString());
                    parameters.put("stvar", stvar.getText().toString());
                    parameters.put("opis", opis.getText().toString());
                    return parameters;
                }
            };
            requestQueue.add(request);
        }
    });


}

}

Be the first to answer