2017-02-12 11 views
0

私のアプリケーションをサーバーに接続しようとしましたが、エラーが発生しました。助けてください!エラー:(54、91)エラー:互換性のないタイプ:intを文字列に変換できません。

私はintに文字列から変更しようとしたが、それはdidnの私は、サーバーへのボレーライブラリを使用して私のアプリを接続しようとしているが、私は自分のコードを実行しようとするたびに、私は次のエラー

incompatible types: int cannot be converted to String

を取得助けて!

show.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 

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

            String firstname = students.getString("firstname"); 
            String lastname = students.getString("lastname"); 
            String age = students.getString("age"); 

            result.append(firstname+""+lastname+""+age+""+"\n"); 
           } 
           result.append("==\n"); 

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

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

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

あなたの変換はどこですか? intはその年齢ですか?? –

+0

私はこれをやってみた int age = students.getInt( "age"); しかし、それは助けになりませんでした! –

+1

@AnujGajbhiyeあなたの 'JSON'レスポンスを共有できますか? –

答えて

1

今問題がありました。

JsonObjectRequestの方法が正しくありません。Volleyです。

あなたはこの方法

JsonObjectRequest(String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener)

代わりの

最初の引数は intある

JsonObjectRequest(int method, String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener)

呼んでいます。

あなたint methodはあなたが5つの引数を渡すことによってそれを修正することができString url

に変換されている場所の上部メソッドが呼び出されているので、あなたは、4つの引数を渡していて、すべてがその後、良いことがあります。

+0

私はこの 'int age = students.getInt(" age ");'を実行しようとしましたが、助けにはならなかったという提案で作業することで回避することができます。 –

+0

@AnujGajbhiyeあなたの 'JSON'レスポンスを共有してください。それは混乱をクリアするかもしれない –

+0

これは私のアプリケーションのすべてのコードです..restは、初期化とXMLファイルです。 –

関連する問題