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 void saveOrUpdate(String nodeName, String value) {
    try {//from   w  ww.j a  v a 2  s.c  o m
        updateNode(nodeName, value);
    } catch (NullPointerException e) {
        insertNode(nodeName, value);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dimasdanz.kendalipintu.util.CommonUtilities.java

public static void generateNotification(Context context, String message, String time, String info) {
    try {/*  w  ww.  java  2s  . c  o m*/
        NotificationManager manager;
        int notificationID = 73;

        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.ic_stat_notification);

        Notification.Builder builder = new Notification.Builder(context);
        Intent resultIntent = new Intent(context, LogActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        stackBuilder.addParentStack(LogActivity.class);
        stackBuilder.addNextIntent(resultIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        Spannable sb = new SpannableString(message + " " + time + "-" + info);
        sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, message.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        builder.setAutoCancel(true);
        builder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);
        builder.setContentTitle(context.getString(R.string.notification_title));
        builder.setContentText(sb);
        builder.setTicker(context.getString(R.string.notification_ticker));
        builder.setNumber(++msgCounter);
        builder.setSmallIcon(R.drawable.ic_stat_notification);
        builder.setLargeIcon(largeIcon);
        builder.setContentIntent(resultPendingIntent);

        if (msgCounter > 1) {
            Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
            if (msgCounter > 6) {
                name[0] = new SpannableString("...");
                name[1] = name[2];
                name[2] = name[3];
                name[3] = name[4];
                name[4] = name[5];
                name[5] = sb;
            } else {
                name[msgCounter - 1] = sb;
            }

            inboxStyle.setBigContentTitle(context.getString(R.string.notification_title));
            inboxStyle.setSummaryText(
                    msgCounter + " " + context.getString(R.string.notification_title) + " Baru");

            for (int i = name.length; i > 0; i--) {
                inboxStyle.addLine(name[i - 1]);
            }

            builder.setStyle(inboxStyle);
            builder.setContentText(msgCounter + " " + context.getString(R.string.notification_title) + " Baru");
        } else {
            name[0] = sb;
        }
        manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(notificationID, builder.build());
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

}

From source file:edu.illinois.whereru.HTTPRequest.java

public static JSONObject makeHttpRequest(String urlString, String method, List<NameValuePair> params) {

    JSONObject jsonObject = null;//from w w w.ja  v a 2s.  co  m

    try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpResponse httpResponse;

        if (method.equals("POST")) {
            // init post
            HttpPost httpPost = new HttpPost(urlString);
            // set the resource to send
            httpPost.setEntity(new UrlEncodedFormEntity(params));
            // send the request, retrieve response
            httpResponse = httpClient.execute(httpPost);

        } else {
            // GET method
            // formulate url
            String paramString = URLEncodedUtils.format(params, "utf-8");
            urlString += "?" + paramString;
            // init GET
            HttpGet httpGet = new HttpGet(urlString);
            // send the request, retrieve response
            httpResponse = httpClient.execute(httpGet);

        }

        // retrieve content from the response
        HttpEntity httpEntity = httpResponse.getEntity();
        InputStream is = httpEntity.getContent();

        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }

        is.close();
        jsonObject = new JSONObject(sb.toString());
    } catch (NullPointerException e) {

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return jsonObject;
}

From source file:net.idlesoft.android.apps.github.utils.GravatarCache.java

private static String getGravatarIdFromGithub(final String name) {
    final GitHubAPI gapi = new GitHubAPI();
    try {//from w w w  .ja  v  a2s.c o  m
        return new JSONObject(gapi.user.info(name).resp).getJSONObject("user").getString("gravatar_id");
    } catch (final NullPointerException e) {
        return "";
    } catch (final JSONException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:com.fabula.android.timeline.sync.ServerDownloader.java

/**
 * Method that fetches JSON-data from a URL
 * //w w  w.ja va  2s. c o  m
 * @param url Address to service that provide JSON
 * @return data as {@link InputStream}
 */
public static InputStream getJSONData(String url) {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "TimelineAndroid");
    InputStream data = null;
    try {
        HttpHost targetHost = new HttpHost(Constants.GOOGLE_APP_ENGINE_URL, 80, "http");
        HttpGet httpGet = new HttpGet(url);
        // Make sure the server knows what kind of a response we will accept
        httpGet.addHeader("Accept", "application/json");
        // Also be sure to tell the server what kind of content we are sending
        httpGet.addHeader("Content-Type", "application/json");

        HttpResponse response = httpClient.execute(targetHost, httpGet);
        data = null;
        try {
            data = response.getEntity().getContent();
        } catch (NullPointerException e) {
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return data;
}

From source file:com.bjorsond.android.timeline.sync.ServerDownloader.java

/**
 * Method that fetches JSON-data from a URL
 * /*from  ww  w.j a v  a 2 s  . c o m*/
 * @param url Address to service that provide JSON
 * @return data as {@link InputStream}
 */
public static InputStream getJSONData(String url) {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "TimelineAndroid");
    InputStream data = null;
    try {
        HttpHost targetHost = new HttpHost(Constants.GOOGLE_APP_ENGINE_URL, 80, "http");
        HttpGet httpGet = new HttpGet(url);
        // Make sure the server knows what kind of a response we will accept
        httpGet.addHeader("Accept", "application/json");
        // Also be sure to tell the server what kind of content we are sending
        httpGet.addHeader("Content-Type", "application/json");

        HttpResponse response = httpClient.execute(targetHost, httpGet);
        data = null;
        try {
            data = response.getEntity().getContent();
        } catch (NullPointerException e) {
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return data;
}

From source file:sonicScream.utilities.ScriptParser.java

private static void parseLine(String line) throws NullPointerException {
    //System.out.println(line); //Enable this to write out scripts as they're parsed. Warning: Causes massive slowdown
    if (StringUtils.isBlank(line)) {
        return;/*from  w  w  w .  j a  va2  s.  co m*/
    }
    //Need this if we want braces commented out too
    if (line.trim().startsWith("//")) {
        try {
            TreeItem<String> newNode = new TreeItem<>(StringUtils.normalizeSpace(line));
            _currentNode = newNode;
            if (_currentNode != null) {
                _currentParent.getChildren().add(newNode);
            }
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        }
    } else if (line.contains("{")) {
        _currentParent = _currentNode;
    } else if (line.contains("}")) {
        _currentParent = _currentParent.getParent();
        if (_currentParent == null) {
            _currentParent = _rootItem;
        }
    } else {
        try {
            TreeItem<String> newNode = new TreeItem<>(StringUtils.normalizeSpace(line));
            _currentNode = newNode;
            if (_currentNode != null) {
                _currentParent.getChildren().add(newNode);
            }
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.oic.connection.Connections.java

public static void mapBroadCastMessage(JSONObject json, int mapid) {
    synchronized (userConnections) {
        try {// w w w .j ava  2s.co m
            for (int i = 0; i < userConnections.size(); i++) {

                WebSocketListener webSocket = userConnections.get(i);
                OicCharacter c = webSocket.getCharacter();
                Session session = webSocket.getSession();
                try {
                    if (c.getMap().getMapId() == mapid) {
                        if (session.isOpen()) {
                            session.getRemote().sendString(json.toJSONString());
                        } else {
                            session.close();
                            userConnections.remove(webSocket);
                        }
                    }
                } catch (NullPointerException e) {
                    session.close();
                    userConnections.remove(webSocket);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.streaming.sweetplayer.utils.Utils.java

/**
 * Send information to Google Analytics/*w ww . ja  v a 2 s . co m*/
 */
public static void gaSendEvent(Context context, String action, String textTracked) {
    try {
        GoogleAnalytics appInstance = GoogleAnalytics.getInstance(context);
        Tracker tracker = appInstance.getTracker(context.getString(R.string.ga_trackingId));

        try {
            if (tracker != null) {
                tracker.sendEvent(Config.GOOGLE_ANALYTICS_ACTION, action, textTracked, null);
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.streaming.sweetplayer.utils.Utils.java

public static void gaSendView(Context context, String view) {
    try {//from  ww w.  j av a2s . c  om
        GoogleAnalytics appInstance = GoogleAnalytics.getInstance(context);
        Tracker tracker = appInstance.getTracker(context.getString(R.string.ga_trackingId));

        if (tracker != null && view != null) {
            try {
                tracker.sendView(view);
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}