我跟進這個link一個例子引用我的錯誤:OkHttp:非靜態方法不能從靜態內容
Non-static method 'newCall(com.squareup.okhttp.Request) cannot be referenced from a static content
在此行中Call call = OkHttpClient.newCall(request);
這是代碼
public class MainActivity extends Activity {
public OkHttpClient client = new OkHttpClient();
String requestUrl = " http://iheartquotes.com/api/v1/random?format=json";
Request request = new Request.Builder().url(requestUrl).build();
TextView text1;
public static final MediaType JSON =
MediaType.parse("application/json; charset=utf-8");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (TextView) findViewById(R.id.messageText);
}
call = OkHttpClient.newCall(request);
}
是什麼原因?
這樣調用'client.newCall(request);' –