Example usage for java.net MalformedURLException printStackTrace

List of usage examples for java.net MalformedURLException printStackTrace

Introduction

In this page you can find the example usage for java.net MalformedURLException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static Bitmap loadImageFromUrl(String url) {
    URL m;//from w  w  w .  j  a v  a2s . co m
    InputStream i = null;
    try {
        m = new URL(url);
        i = (InputStream) m.getContent();
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return BitmapFactory.decodeStream(i);
}

From source file:Main.java

public static boolean isUrl(String imageUrl) {
    try {/*from   w w  w  .  jav  a2 s.  co  m*/
        new URL(imageUrl);
        return true;
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static Bitmap loadImageFromNet(String url) {
    URL m;//from  w ww.  ja  va 2s. c  o  m
    InputStream i = null;
    try {
        m = new URL(url);
        i = (InputStream) m.getContent();
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return BitmapFactory.decodeStream(i);
}

From source file:Main.java

public static Drawable loadImageFromUrl(String url) {
    URL m;/*  w w  w. j a v a2 s.  co  m*/
    InputStream i = null;
    try {
        m = new URL(url);
        i = (InputStream) m.getContent();
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Drawable d = Drawable.createFromStream(i, "src");
    return d;
}

From source file:Main.java

public static String getHost(String urlString) {
    URL url;//www.ja  v a2  s.c o m
    try {
        url = new URL(urlString);
        return url.getHost();
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static Bitmap getBitmapFromRemote(String address) {
    Bitmap bitmap = null;//  w ww . java  2 s  .  c om
    try {
        URL url = new URL(address);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoInput(true);
        conn.connect();
        InputStream is = conn.getInputStream();
        bitmap = BitmapFactory.decodeStream(is);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static Drawable ImageOperations(Context ctx, String url, String saveFilename) {
    try {//from w w  w . ja v  a 2 s . c  om
        InputStream is = (InputStream) fetch(url);
        Drawable d = Drawable.createFromStream(is, "src/assets/gfx");
        return d;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static ImageView getImageViewFromUrl(String imageUrl, Activity activity, int viewId) {

    try {/*from ww w . j av a  2s. c o m*/
        ImageView i = (ImageView) activity.findViewById(viewId);
        Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(imageUrl).getContent());
        i.setImageBitmap(bitmap);
        return i;
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;

}

From source file:Main.java

public static URL getString(URL str) {
    String ssString = str.toString();
    String[] aaStrings = ssString.split("/");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < aaStrings.length; i++) {
        if (i == 4) {
            aaStrings[i] = "180";
        }/*from  w ww.  ja  va 2  s  .c om*/
        sb.append(aaStrings[i] + "/");
    }
    sb.deleteCharAt(sb.length() - 1);
    URL url = null;
    try {
        url = new URL(sb.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return url;
}

From source file:Util.java

/**
 * Finds this computer's global IP address
 * /* w ww  .  ja va 2 s  .  com*/
 * @return The global IP address, or null if a problem occurred
 */
public static Inet4Address getGlobalAddress() {
    try {
        URLConnection uc = new URL("http://www.whatismyip.org/").openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        return (Inet4Address) InetAddress.getByName(br.readLine());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;

}