Example usage for java.lang NullPointerException printStackTrace

List of usage examples for java.lang NullPointerException printStackTrace

Introduction

In this page you can find the example usage for java.lang NullPointerException 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 String transferXmlToString(Document doc) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {//from ww  w .  j  a v a2  s  .c om
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer t = tf.newTransformer();
        Properties p = t.getOutputProperties();
        p.setProperty(OutputKeys.ENCODING, "UTF-8");
        t.setOutputProperties(p);
        t.transform(new DOMSource(doc), new StreamResult(bos));
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    }
    String xmlStr = "";
    try {
        xmlStr = bos.toString("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return xmlStr;
}

From source file:Main.java

public static void hideIME(Activity context, boolean bHide) {
    if (bHide) {// w ww.  j a v  a  2s  .  c om
        try {
            ((InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(context.getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
        } catch (NullPointerException npe) {
            npe.printStackTrace();
        }
    } else { // show IME
        try {
            ((InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE))
                    .showSoftInput(context.getCurrentFocus(), InputMethodManager.SHOW_IMPLICIT);
        } catch (NullPointerException npe) {
            npe.printStackTrace();
        }
    }
}

From source file:com.optimusinfo.elasticpath.cortex.authentication.newaccount.RegistrationModel.java

/**
 * This method adds a new user/*  w w  w.  j  av a 2 s  .c  om*/
 * 
 * @param urlAddAccountForm
 * @param contentType
 * @param accessToken
 * @param listener
 * @param input
 */
public static void addNewAccount(Context current, String urlAddAccountForm, String accessToken,
        ListenerAddUser listener, JSONObject input) {
    try {
        AsyncTaskAddUser taskAddAccount = new AsyncTaskAddUser(current, urlAddAccountForm, accessToken, input,
                listener);
        taskAddAccount.execute();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String removeUnprintableCharacters(String str) {

    int len = str.length();
    StringBuffer buf = new StringBuffer();
    try {/*w w w .  j  ava2  s .c o m*/
        for (int i = 0; i < len; i++) {
            String rep = "";
            char cp = str.charAt(i);// the code point
            // Replace invisible control characters and unused code points
            switch (Character.getType(cp)) {
            case Character.CONTROL: // \p{Cc}
            case Character.FORMAT: // \p{Cf}
            case Character.PRIVATE_USE: // \p{Co}
            case Character.SURROGATE: // \p{Cs}
            case Character.UNASSIGNED: // \p{Cn}
                buf = buf.append(rep);
                break;
            default:
                char[] chars = Character.toChars(cp);
                buf = buf.append(chars);
                break;
            }
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
        System.err.println("Confused: " + e);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        System.err.println("Confused: " + e);
    } catch (IndexOutOfBoundsException e) {
        e.printStackTrace();
        System.err.println("Confused: " + e);
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Confused: " + e);
    }

    return buf.toString();
}

From source file:Main.java

/**
 * Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory
 * is persistent and available to other applications like gallery.
 *
 * @param type Media type. Can be video or image.
 * @return A file object pointing to the newly created file.
 *///from   w  ww . ja  va  2  s  . co m
public static File getTempOutputMediaFile(Context context, int type) {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.
    if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
        return null;
    }

    @SuppressLint("SimpleDateFormat")
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());

    if (type == MEDIA_TYPE_IMAGE) {
        timeStamp += ".jpg";
    } else if (type == MEDIA_TYPE_VIDEO) {
        timeStamp += ".mp4";
    } else {
        return null;
    }

    try {
        return new File(context.getExternalCacheDir().getAbsolutePath(), timeStamp);
    } catch (NullPointerException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.optimusinfo.elasticpath.cortex.profile.address.AddressModel.java

/**
 * This method adds a Address//  w w  w  .  ja  v a  2  s .c om
 * 
 * @param urlAddToCartForm
 * @param contentType
 * @param accessToken
 * @param listener
 * @param input
 */
public static void addAddress(String urlAddToCartForm, String contentType, String accessToken,
        ListenerAddAddress listener, JSONObject input) {
    try {
        AsyncTaskAddAddress taskAddAddress = new AsyncTaskAddAddress(urlAddToCartForm, urlAddToCartForm,
                accessToken, input, listener);
        taskAddAddress.execute();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:com.optimusinfo.elasticpath.cortex.profile.address.AddressModel.java

public static void getAddressForm(Context current, String addtoCartUrl, String accessToken,
        ListenerGetAddressForm mListner) {
    try {/*from  w ww . j  av  a2 s . c o m*/
        new AsyncTaskGetAddressForm(current, addtoCartUrl, accessToken,
                Constants.RequestHeaders.CONTENT_TYPE_STRING, Constants.RequestHeaders.CONTENT_TYPE,
                Constants.RequestHeaders.AUTHORIZATION_STRING,
                Constants.RequestHeaders.AUTHORIZATION_INITIALIZER, mListner).execute();
    } catch (NullPointerException e) {
        e.printStackTrace();

    }
}

From source file:com.optimusinfo.elasticpath.cortex.profile.address.AddressModel.java

public static void updateAddress(Context current, String url, String token, ListenerUpdateAdddress listener,
        JSONObject input) {/*from w w w  .ja  v  a 2 s . c om*/
    try {
        AsyncTaskUpdateAddress taskUpdate = new AsyncTaskUpdateAddress(current, url, token,
                Constants.RequestHeaders.CONTENT_TYPE_STRING, Constants.RequestHeaders.CONTENT_TYPE,
                Constants.RequestHeaders.AUTHORIZATION_STRING,
                Constants.RequestHeaders.AUTHORIZATION_INITIALIZER, listener, input);
        taskUpdate.execute();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Bitmap createDrawableFromView(Context context, View view) {

    Bitmap bit = null;//from   w  w  w  . j  a  v a 2  s. com
    try {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT));
        view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
        view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
        view.buildDrawingCache();
        bit = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(bit);
        view.draw(canvas);
    } catch (NullPointerException e) {
        Log.e("NullPointerException", e.toString());
        e.printStackTrace();
    }
    return bit;
}

From source file:com.yelinaung.android.utils.NetUtils.java

@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void getStatus(String weburl, String ways) {
    try {//www .  j  av  a 2 s .c o  m
        List<String> httpWays = new ArrayList<String>();
        httpWays.add(ways.toUpperCase());
        httpWays.add(weburl);
        new checkWebStatus().execute(httpWays);
    } catch (NullPointerException ne) {
        ne.printStackTrace();
    }

}