我在這一行開空指針異常wsresult = restClientInterface.skuska();用於restClientInterface。下面是我的示例:Android @RestService注入通過androidannotations結果到nullPointerException異常
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();
}
是嗎? restClientInterface顯然是空的,你可能想要像初始化它? – njzk2 2013-02-20 11:28:00
你能發佈異常的完整堆棧跟蹤嗎? – 2013-02-21 09:55:59