2016-05-25 6 views
0

Retrofitの使用を開始したばかりですが、疑問があります。私は私のアプリケーションをデバッグすることができないいくつかのエラーを避けることはできません。あなたを気にして、すみません。RetrofitからJSON Result(WCFのもの)にアクセスできない

これはコードの一部で、おそらく知っておく必要があります。

あなたのすべてがわかるように、Graddleインタフェース(休憩用)、POJOクラス、および活動(I(クラスと最初のものの一覧である親クラスを持ちます) のonCreateで改造を呼び出して、私は

--Graddle-- 
compile 'com.squareup.retrofit2:retrofit:2.0.2' 
compile 'com.google.code.gson:gson:2.5' 
compile 'com.squareup.retrofit2:converter-gson:2.0.0' 

--Pojo-- 
public class pisoAlquiler { 
private int codigo; 
private String fotos; 
} 

public class pisosAlquiler { 
List<pisoAlquiler> pisoAlquilerList; 
} 

--Interface-- 
public interface RestApi { 
@GET("/Service1.svc?wsdl") 
Call<pisosAlquiler> devolverPisosA(); 
} 

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

    Retrofit retrofit = new Retrofit.Builder() 
      .baseUrl("http://localhost:52896") 
      .addConverterFactory(GsonConverterFactory.create()) 
      .build(); 

    // prepare call in Retrofit 2.0 
    RestApi restApi = retrofit.create(RestApi.class); 

    Call<pisosAlquiler> call = restApi.devolverPisosA(); 
    //asynchronous call 
    call.enqueue(this); 
} 

@Override 
public void onResponse(Call<pisoAlquiler> call, Response<pisoAlquiler> response) { 
    setProgressBarIndeterminateVisibility(false); 
    // Create a LinearLayout element 
    LinearLayout ll = new LinearLayout(this); 
    ll.setOrientation(LinearLayout.VERTICAL); 

    pisosAlquiler prueba = (pisosAlquiler) response.body().pisoAlquilerList; 
} 

- 私はproblably来て、2つのエラーを取得) onResponse にデータを回復同じ問題からonCreate

call.enqueue(this); 

この返すエラー、私は(pisoAlquilerのリストが含まれています)の代わりにpisosAlquilerのpisoAlquilerクラスに、エラー消えるを使用する場合のコールでは、適用することはできないと言って。

onResponse

pisosAlquiler prueba = (pisosAlquiler) response.body().pisoAlquilerList; 

pisoAlquilerListシンボルを解決することはできません戻ります。私はpisoAlquilerの属性を呼び出すことができますが、pisosAlquilerが持っている唯一の属性ではないようです...

すべてのアイデア?

ありがとうございます。

+1

変更 'pisosAlquiler prueba =(pisosAlquiler)response.body()。pisoAlquilerList';これは 'pisosAlquiler prueba =(pisosAlquiler)response.body();'です。あなたのPOJOによると、pisoAlquilerListはプライベートなので、 '.pisoAlquilerList'呼び出しにアクセスできないかもしれないことにも注意してください。 – ishmaelMakitla

+2

'call.enqueue(this);'を呼び出すとき 'Callback を実装しているあなたの現在のクラス(' this')か、 'Callback 'を実装していますか? – ishmaelMakitla

+1

私の働く答えを見ることができます: [1]:http://stackoverflow.com/questions/37098347/how-to-use-gson-2-0-on-onresponse-from-retrofit-2-0/ 37099604#37099604 [2]:http://stackoverflow.com/questions/36771946/error-when-using-retrofit/36773538#36773538 –

答えて

0

まあ、

DebbugモードとWCFで - 私(のVisual Studioによる)とAndroid Studioが同じネットワーク内に立体配置のwasn'tた問題。次の以下のローカルネットワーク内のAndroid Studioで作業するためのVisual Studioを構成するための

、:

のWeb.Config貴様の場所からリスニング用に設定する必要があります。オープン

<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 

プロジェクトフォルダに割り当てられたのapplicationHost.config - >設定::サービスや行動のタグの間に、次のいずれかを変更し :

<site name="Proyect" id="2"> 
      <application path="/" applicationPool="Clr4IntegratedAppPool"> 
       <virtualDirectory path="/" physicalPath="c:\ProjectFolder\Proyect /> 
      </application> 
      <bindings> 
       <binding protocol="http" bindingInformation="*:52896:localhost" /> 
      </bindings> 
     </site> 

について:

<site name="Proyect" id="2"> 
      <application path="/" applicationPool="Clr4IntegratedAppPool"> 
       <virtualDirectory path="/" physicalPath="c:\ProjectFolder\Proyect" /> 
      </application> 
      <bindings> 
       <binding protocol="http" bindingInformation="*:52896:localhost" /> 
       <binding protocol="http" bindingInformation="*:52896:*" /> 
      </bindings> 
     </site> 

これで内部要求を聞くことができます。

そのポートのWindowsファイアウォールを開きます。

関連する問題