3

この行で null ポインター例外が発生しています wsresult = restClientInterface.skuska(); restClientInterface 用。これが私のサンプルです:

import org.springframework.http.converter.json.GsonHttpMessageConverter;

import com.googlecode.androidannotations.annotations.rest.Get;
import com.googlecode.androidannotations.annotations.rest.Rest;

@Rest(rootUrl = "http://my_ip_address/webresources", converters = {GsonHttpMessageConverter.class})
public interface RestClient {

    @Get("/persons")
    String skuska();    
}

そして、私はそのフラグメントで使用しています

    @EFragment
public class HomeFragment extends Fragment {

private Button ws;
private TextView wsstring;
private String wsresult;        

        @RestService
        RestClient restClientInterface;

        wsstring = (TextView) view.findViewById(R.id.wsstring);

                ws = (Button) view.findViewById(R.id.ws);
                ws.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        getWSResult();
                        wsstring.setText(wsresult);         
                    }
                });

                return view;
            }

            @Background
            public void getWSResult() {
                 wsresult = restClientInterface.skuska();       
            }
4

1 に答える 1

2

RestClientは、フラグメントの準備ができた直後にAAによって正しく注入される必要があります。生成されたクラスをコピーして貼り付けて、何が起こっているかを確認できますか?

さらに、getWSResult()(バックグラウンドメソッドである)呼び出しを行っており、TextViewでRest呼び出しの結果を設定した直後です。ただし、オブジェクトに設定しようとする前に結果が到着したかどうかはわかりません。

このようなコードで試してみてください:

@EFragment(R.layout.homeFragment)
public class homeFragment extends Fragment {

    @ViewById
    Button ws;

    @ViewById
    TextView wsstring;

    @RestService
    RestClient restClientInterface;

    private String wsresult;

    @Click
    void wsstringClicked() {
        getWSResult();
    }

    @Background
    void getWSResult() {
        wsresult = restClientInterface.skuska();
    }

    @UiThread
    void updateUI() {
        wsstring.setText(wsresult);
    }
}

編集:注釈付きフィールドで削除されprivateました@ViewById

EDIT2:それについて考えているだけです。このフラグメントをアクティビティでどのように使用していますか?どちらかを使用しています@FragmentById@FragmentByTag

于 2013-02-20T13:13:25.117 に答える