我使用000webhost.com
来托管我的文件,我可以通过网络浏览器访问它们,是否有任何我应该知道的webhost设置,以使我的文件可用于我的Android应用程序。
我无法通过android访问json文件甚至图像文件夹,当改造的onFailure()
方法被执行时,printStackTrace
方法说:
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: java.net.UnknownHostException: Unable to resolve host "http": No address associated with hostname
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:457)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at java.net.InetAddress.getAllByName(InetAddress.java:215)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.Dns$1.lookup(Dns.java:39)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:174)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:289)
04-05 16:41:49.342 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:240)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.RealCall.access$100(RealCall.java:30)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at java.lang.Thread.run(Thread.java:818)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at libcore.io.Posix.android_getaddrinfo(Native Method)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:438)
04-05 16:41:49.343 23509-23509/com.hanselandpetal.catalog W/System.err: ... 20 more
这是我正在使用的http地址:
public static final String ENDPOINT =
"http://services.hanselandpetal.com";
public static final String ENDPOINT2 =
"http://ajay_pyaraka.site88.net";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ENDPOINT2)
.addConverterFactory(GsonConverterFactory.create())
.build();
FlowersAPI service = retrofit.create(FlowersAPI.class);
Call<List<Flower>> call = service.getFeed2();
call.enqueue(new Callback<List<Flower>>() {
@Override
public void onResponse(Call<List<Flower>> call, Response<List<Flower>> response) {
if (response.isSuccessful()) {
flowerList = response.body();
updateDisplay();
}
}
@Override
public void onFailure(Call<List<Flower>> call, Throwable t) {
Toast.makeText(MainActivity.this, "Failure", Toast.LENGTH_SHORT).show();
t.printStackTrace();
}
});
我能够从第一个END ENDPOINT获得,但不能使用第二个ENDPOINT2