mario margo mario margo - 17 days ago 7
Android Question

Error with Volley Bad URL when getting image

I have some error when I tried to load image from server using volley.

This is my log:

E/Volley: [31648] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/103.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/103.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/103.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
E/Volley: [31650] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/106.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/106.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/106.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
E/Volley: [31651] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/106.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/106.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/106.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
E/Volley: [31649] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/103.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/103.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/103.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
E/Volley: [31648] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/0.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/0.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/0.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
E/Volley: [31650] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/107.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/107.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/107.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
E/Volley: [31651] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/0.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/0.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/0.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 
E/Volley: [31651] NetworkDispatcher.run: Unhandled exception java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/107.png
java.lang.RuntimeException: Bad URL kinandayu.com/image_content/uploads/107.png
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:144)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112)
Caused by: java.net.MalformedURLException: Protocol not found: kinandayu.com/image_content/uploads/107.png
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:96)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:112) 


This is my Activity.java:

public class Child_Tab1 extends Activity {

List<GetDataAdapter> GetDataAdapter1;
RecyclerView recyclerView;
RecyclerView.LayoutManager recyclerViewlayaoutManager;
RecyclerView.Adapter recyclerViewadapter;
String GET_JSON_DATA_HTTP_URL = "http://www.kinandayu.com/image_content/getAllImage.php";
String JSON_IMAGE_TITLE_NAME = "id";
String JSON_IMAGE_URL = "image";

JsonArrayRequest jsonArrayRequest;
RequestQueue requestQueue;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.child_tab_1);
GetDataAdapter1 = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.rv1);
recyclerView.setHasFixedSize(true);
recyclerViewlayaoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(recyclerViewlayaoutManager);

JSON_DATA_WEB_CALL();
}

private void JSON_DATA_WEB_CALL() {
jsonArrayRequest = new JsonArrayRequest(GET_JSON_DATA_HTTP_URL, new Response.Listener<JSONArray>() {
@Override
public void onResponse (JSONArray response) {
JSON_PARSE_DATA_AFTER_WEBCALL(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
});
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest);
}

public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {
for (int i = 0; i<array.length(); i++) {
GetDataAdapter GetDataAdapter2 = new GetDataAdapter();
JSONObject json = null;
try {
json = array.getJSONObject(i);

GetDataAdapter2.setImageTitleNamee(json.getString(JSON_IMAGE_TITLE_NAME));
GetDataAdapter2.setImageServerUrl(json.getString(JSON_IMAGE_URL));
} catch (JSONException e) {
e.printStackTrace();
}
GetDataAdapter1.add(GetDataAdapter2);
}
recyclerViewadapter = new RecyclerViewAdapter(GetDataAdapter1, this);
recyclerView.setAdapter(recyclerViewadapter);
}
}


This is my ServerImageParseAdapter.java:

public class ServerImageParseAdapter {
public static ServerImageParseAdapter SIAdapter;
public static Context context1;
public RequestQueue requestQueue1;
public ImageLoader ImageLoader1;
public Cache cache1;
public Network networkOBJ;
LruCache<String, Bitmap> LRUCACHE = new LruCache<String, Bitmap>(30);

private ServerImageParseAdapter(Context context) {
this.context1 = context;
this.requestQueue1 = RQ();
ImageLoader1 = new ImageLoader(requestQueue1, new ImageLoader.ImageCache() {

@Override
public Bitmap getBitmap(String URL) {
return LRUCACHE.get(URL);
}

@Override
public void putBitmap(String url, Bitmap bitmap) {
LRUCACHE.put(url,bitmap);
}
});
}

public ImageLoader getImageLoader() {
return ImageLoader1;
}

public static ServerImageParseAdapter getInstance(Context SynchronizedContext) {
if (SIAdapter == null) {
SIAdapter = new ServerImageParseAdapter(SynchronizedContext);
}
return SIAdapter;
}

public RequestQueue RQ() {
if (requestQueue1 == null) {
cache1 = new DiskBasedCache(context1.getCacheDir());
networkOBJ = new BasicNetwork(new HurlStack());
requestQueue1 = new RequestQueue(cache1, networkOBJ);
requestQueue1.start();
}
return requestQueue1;
}
}


I'm using compile 'com.android.volley:volley:1.0.0'

The problem is the image is not show in my cardview but the name of
image("id")
is show. I've read some question that same with my problem in here but I don't get any solution.

Answer

This is a server-side problem. You need to fix your PHP & JSON to get the correct URL addresses,

{
    "id": "106",
    "image": "kinandayu.com\/image_content\/uploads\/103.png"
}

If you can't do that, then add http:// onto the image URL strings.

String imgURL = json.getString(JSON_IMAGE_URL);
if (!imgURL.startsWith("http://") {
    imgURL = "http://"+imgURL;
}
GetDataAdapter2.setImageServerUrl(imgURL);