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:de.tap.easy_xkcd.Activities.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    try {//from w w  w. java2  s.  co m
        mNavView.getMenu().findItem(getCurrentFragment()).setChecked(true);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:org.micromanager.plugins.magellan.imagedisplay.DisplayOverlayer.java

/**
 * Draw an initial version of the overlay that can be calculated quickly
 * subsequent calls will draw more detailed surface overlay renderings
 *
 * @return/* w w  w .  ja va2 s  .c  om*/
 */
private Callable<Overlay> createBaseOverlay() {
    return new Callable<Overlay>() {

        @Override
        public Overlay call() throws InterruptedException {
            try {
                //determine appropriate overlay
                int mode = display_.getMode();
                if (mode == DisplayPlus.EXPLORE) {
                    Overlay overlay = createBackgroundOverlay();
                    if (display_.getExploreEndTile() != null) {
                        //draw explore tiles waiting to be confirmed with a click
                        highlightTilesOnOverlay(overlay,
                                Math.min(display_.getExploreEndTile().y, display_.getExploreStartTile().y),
                                Math.max(display_.getExploreEndTile().y, display_.getExploreStartTile().y),
                                Math.min(display_.getExploreEndTile().x, display_.getExploreStartTile().x),
                                Math.max(display_.getExploreEndTile().x, display_.getExploreStartTile().x),
                                TRANSPARENT_MAGENTA);
                    } else if (display_.getMouseDragStartPointLeft() != null) {
                        //highlight multiple tiles when mouse dragging    
                        Point mouseLoc = display_.getCurrentMouseLocation();
                        Point dragStart = display_.getMouseDragStartPointLeft();
                        Point p2Tiles = zoomableStack_.getTileIndicesFromDisplayedPixel(mouseLoc.x, mouseLoc.y),
                                p1Tiles = zoomableStack_.getTileIndicesFromDisplayedPixel(dragStart.x,
                                        dragStart.y);
                        highlightTilesOnOverlay(overlay, Math.min(p1Tiles.y, p2Tiles.y),
                                Math.max(p1Tiles.y, p2Tiles.y), Math.min(p1Tiles.x, p2Tiles.x),
                                Math.max(p1Tiles.x, p2Tiles.x), TRANSPARENT_BLUE);
                    } else if (display_.getCurrentMouseLocation() != null) {
                        //draw single highlighted tile under mouse
                        Point coords = zoomableStack_.getTileIndicesFromDisplayedPixel(
                                display_.getCurrentMouseLocation().x, display_.getCurrentMouseLocation().y);
                        highlightTilesOnOverlay(overlay, coords.y, coords.y, coords.x, coords.x,
                                TRANSPARENT_BLUE); //highligth single tile

                    }
                    try {
                        if (acq_ instanceof ExploreAcquisition) {
                            //always draw tiles waiting to be acquired
                            LinkedBlockingQueue<ExploreAcquisition.ExploreTileWaitingToAcquire> tiles = ((ExploreAcquisition) acq_)
                                    .getTilesWaitingToAcquireAtSlice(display_.getVisibleSliceIndex()
                                            + ((ExploreAcquisition) acq_).getMinSliceIndex());
                            if (tiles != null) {
                                for (ExploreAcquisition.ExploreTileWaitingToAcquire t : tiles) {
                                    highlightTilesOnOverlay(overlay, t.row, t.row, t.col, t.col,
                                            TRANSPARENT_GREEN);
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    return overlay;
                } else if (mode == DisplayPlus.NEWGRID) {
                    return newGridOverlay();
                } else if (mode == DisplayPlus.NONE) {
                    return createBackgroundOverlay();
                } else if (mode == DisplayPlus.SURFACE) {
                    //Do only fast version of surface overlay rendering, which don't require 
                    //any progress in the interpolation
                    Overlay overlay = createBackgroundOverlay();
                    addInterpPoints(display_.getCurrentSurface(), overlay);
                    return overlay;
                } else {
                    Log.log("Unkonwn display mode", true);
                    throw new RuntimeException();
                }
            } catch (NullPointerException npe) {
                Log.log("Null pointer exception while creating overlay. written to stack ", false);
                npe.printStackTrace();
                return null;
            }
        }
    };
}

From source file:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java

private void exportBounds() {
    int rows = tableWindowSize.getRowCount();
    double coverage;
    int wsize;//  w  w  w . j a v a 2 s.  com
    File fExport;
    Writer wr;
    double[] bounds;
    for (int i = 0; i < rows; i++) {
        try {
            wsize = (Integer) tableWindowSize.getValueAt(i, 0);
            coverage = (Double) tableWindowSize.getValueAt(i, 1);
            bounds = trace.getDynamicBound(coverage, wsize);

            fExport = new File(trace.getName() + "_w" + wsize + "_c" + coverage);
            wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fExport)));
            wr.write("# window size: " + wsize + "\r\n" + "# coverage: " + coverage + "\r\n");
            for (int j = 0; j < bounds.length; j++) {
                wr.write(bounds[j] + "\r\n");
            }

            wr.close();

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

From source file:com.radicaldynamic.groupinform.services.InformOnlineService.java

private void connect(boolean forceOnline) {
    mConnecting = true;/*from   ww  w  .  j av  a  2s. c  o  m*/

    // Make sure that the user has not specifically requested that we be offline
    if (Collect.getInstance().getInformOnlineState().isOfflineModeEnabled() && forceOnline == false) {
        if (Collect.Log.INFO)
            Log.i(Collect.LOGTAG, t + "offline mode enabled; not auto-connecting");

        /* 
         * This is not a complete initialization (in the sense that we attempted connection) but we need 
         * to pretend that it is so that the UI can move forward to whatever state is most suitable.
         */
        mInitialized = true;
        mConnecting = false;

        return;
    }

    if (Collect.Log.INFO)
        Log.i(Collect.LOGTAG, t + "pinging " + Collect.getInstance().getInformOnlineState().getServerUrl());

    // Try to ping the service to see if it is "up" (and determine whether we are registered)
    String pingUrl = Collect.getInstance().getInformOnlineState().getServerUrl() + "/ping";
    String getResult = HttpUtils.getUrlData(pingUrl);
    JSONObject ping;

    try {
        ping = (JSONObject) new JSONTokener(getResult).nextValue();

        String result = ping.optString(InformOnlineState.RESULT, InformOnlineState.ERROR);

        // Online and registered (checked in)
        if (result.equals(InformOnlineState.OK)) {
            if (Collect.Log.INFO)
                Log.i(Collect.LOGTAG, t + "ping successful (we are connected and checked in)");
            mServicePingSuccessful = mSignedIn = true;
        } else if (result.equals(InformOnlineState.FAILURE)) {
            if (Collect.Log.WARN)
                Log.w(Collect.LOGTAG, t + "ping successful but not signed in (will attempt checkin)");
            mServicePingSuccessful = true;

            if (Collect.getInstance().getInformOnlineState().hasRegistration() && checkin()) {
                if (Collect.Log.INFO)
                    Log.i(Collect.LOGTAG, t + "checkin successful (we are connected)");

                // Fetch regardless of the fact that we're not yet marked as being signed in
                AccountDeviceList.fetchDeviceList(true);
                AccountFolderList.fetchFolderList(true);

                mSignedIn = true;
            } else {
                if (Collect.Log.WARN)
                    Log.w(Collect.LOGTAG, t + "checkin failed (registration invalid)");
                mSignedIn = false;
            }
        } else {
            // Assume offline
            if (Collect.Log.WARN)
                Log.w(Collect.LOGTAG, t + "ping failed (we are offline)");
            mSignedIn = false;
        }
    } catch (NullPointerException e) {
        // This usually indicates a communication error and will send us into an offline state
        if (Collect.Log.ERROR)
            Log.e(Collect.LOGTAG, t + "ping error while communicating with service (we are offline)");
        e.printStackTrace();
        mServicePingSuccessful = mSignedIn = false;
    } catch (JSONException e) {
        // Parse errors (malformed result) send us into an offline state
        if (Collect.Log.ERROR)
            Log.e(Collect.LOGTAG, t + "ping error while parsing getResult " + getResult + " (we are offline)");
        e.printStackTrace();
        mServicePingSuccessful = mSignedIn = false;
    } finally {
        // Load regardless of whether we are signed in
        AccountDeviceList.loadDeviceList();
        AccountFolderList.loadFolderList();

        // Unblock
        mInitialized = true;
        mConnecting = false;
    }
}

From source file:org.seadva.archive.impl.cloud.SdaArchiveStore.java

public List<File> recurseDirectory(final File directory) {
    List<File> files = new ArrayList<File>();
    if (directory != null && directory.isDirectory()) {
        try {// w  w  w .jav a  2 s  .  c  o  m
            File[] filesList = directory.listFiles();
            if (filesList != null) {
                for (File file : filesList) {

                    if (file.isDirectory()) {
                        files.addAll(recurseDirectory(file));
                    } else {
                        files.add(file);
                    }
                }
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    return files;
}

From source file:com.p2p.misc.DeviceUtility.java

public Boolean isRoaming() {
    try {//from   www. jav  a 2  s  . c om
        if (CheckNetConnectivity(mactivity)) {

            ConnectivityManager cm = (ConnectivityManager) mactivity
                    .getSystemService(Context.CONNECTIVITY_SERVICE);

            if (cm.getActiveNetworkInfo().isRoaming())
                return true;
            else
                return false;
        } else
            return false;
    } catch (NullPointerException e) {
        e.printStackTrace();
        return false;
    }

}

From source file:com.hygenics.parser.getDAOTemplate.java

/**
 * Return the column names/*from w ww .  ja  va2  s.c  om*/
 * 
 * @return
 */
public ArrayList<String> getColumns(String table) {
    String[] split = table.split("\\.");
    String sql = null;

    if (split.length == 2) {
        sql = "SELECT column_name FROM information_schema.columns WHERE table_name='" + split[1].trim()
                + "' AND table_schema='" + split[0].trim() + "'";
    } else {
        // get rid of obscure sql error
        try {
            throw new NullPointerException("Table must be provided in schema.table format!");
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    return this.jdbcTemplateObject.query(sql, getArrayResultSetExtractor("column_name"));
}

From source file:org.ut.biolab.medsavant.server.db.variants.annotation.BatchVariantAnnotator.java

/**
 * Perform the prepared batch annotation in parallel
 *
 * @throws IOException//from   w w w .  j  a  va2s  .  c  o m
 * @throws SQLException
 */
public void performBatchAnnotationInParallel()
        throws IOException, SQLException, SessionExpiredException, IllegalArgumentException {

    org.ut.biolab.medsavant.server.serverapi.LogManager.getInstance().addServerLog(sid,
            LogManagerAdapter.LogType.INFO, "Annotation of " + inputTDFFile.getAbsolutePath() + " was started. "
                    + annotations.length + " annotation(s) will be performed.");

    LOG.info("Annotation of " + inputTDFFile.getAbsolutePath() + " was started. " + annotations.length
            + " annotation(s) will be performed.");
    //EmailLogger.logByEmail("Annotation started", "Annotation of " + inputTDFFile.getAbsolutePath() + " was started. " + annotations.length + " annotation(s) will be performed.");

    CSVReader recordReader = null;
    CSVWriter recordWriter = null;
    AnnotationCursor[] cursors = null;
    try {
        // no annotations to perform, copy input to output
        if (annotations.length == 0) {
            jobProgress.setMessage("No annotations to perform, processing intermediate files");
            MedSavantIOController.requestIO(new IOJob("Copy File") {
                @Override
                protected void doIO() throws IOException {
                    IOUtils.copyFile(inputTDFFile, outputTDFFile);
                }
            });

            return;
        }

        // otherwise, perform annotations
        jobProgress.setMessage("Performing " + annotations.length + " annotations");
        LOG.info("Performing " + annotations.length + " annotations");

        // the number of columns in the input file
        int numFieldsInInputFile = getNumFieldsInTDF(inputTDFFile);
        if (numFieldsInInputFile == 0) {
            org.ut.biolab.medsavant.server.serverapi.LogManager.getInstance().addServerLog(sid,
                    LogManagerAdapter.LogType.ERROR,
                    "Error parsing input file " + inputTDFFile.getAbsolutePath() + " . Is it tab delimited?");
            throw new IOException("Error parsing input file. Is it tab delimited?");
        }

        // the number of fields that will be in the output file
        int numFieldsInOutputFile = numFieldsInInputFile;

        // create cursors for all annotations
        cursors = new AnnotationCursor[annotations.length];
        for (int i = 0; i < annotations.length; i++) {
            AnnotationCursor ac = new AnnotationCursor(sid, annotations[i]);
            numFieldsInOutputFile += ac.getNumNonDefaultFields();
            cursors[i] = ac;
        }

        final int numlines[] = new int[1];

        MedSavantIOController.requestIO(new IOJob("Line counter") {
            @Override
            protected void doIO() throws IOException {
                jobProgress.setMessage("Counting number of variants to annotate");
                //LOG.info("DEBUG: Inside doIO of LineCounter, working with TDF File "+inputTDFFile+"\n");
                int numLines = 0;
                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(new FileReader(inputTDFFile));
                    while (reader.readLine() != null) {
                        numLines++;
                    }
                } finally {
                    if (reader != null) {
                        reader.close();
                    }
                }
                numlines[0] = numLines;
                //LOG.info("DEBUG: Read "+numLines+" from "+inputTDFFile);
            }
        });

        // open the input and output files
        recordReader = new CSVReader(new FileReader(inputTDFFile),
                VariantManagerUtils.FIELD_DELIMITER.charAt(0), CSVWriter.DEFAULT_QUOTE_CHARACTER, '\\');
        //recordWriter = new CSVWriter(new FileWriter(outputTDFFile), VariantManagerUtils.FIELD_DELIMITER.charAt(0), CSVWriter.DEFAULT_QUOTE_CHARACTER, '\\', "\r\n");
        recordWriter = new CSVWriter(new FileWriter(outputTDFFile),
                VariantManagerUtils.FIELD_DELIMITER.charAt(0), CSVWriter.DEFAULT_QUOTE_CHARACTER, "\r\n");

        //LOG.info("Reading from " + inputTDFFile.getAbsolutePath());
        //LOG.info("Writing to " + outputTDFFile.getAbsolutePath());
        // read the input, line by line
        String[] inputLine;

        MedSavantIOController.requestIO(new VariantAnnotatorIOJob(cursors, recordReader, recordWriter,
                numlines[0], numFieldsInOutputFile));

        org.ut.biolab.medsavant.server.serverapi.LogManager.getInstance().addServerLog(sid,
                LogManagerAdapter.LogType.INFO, "Annotation of " + inputTDFFile.getAbsolutePath()
                        + " completed. " + annotations.length + " annotations were performed.");

        // report success
        LOG.info("Annotation of " + inputTDFFile.getAbsolutePath() + " completed. " + annotations.length
                + " annotations were performed.");
        //EmailLogger.logByEmail("Annotation completed", "Annotation of " + inputTDFFile.getAbsolutePath() + " completed. " + annotations.length + " annotations were performed.");
    } catch (InterruptedException ie) {

        org.ut.biolab.medsavant.server.serverapi.LogManager.getInstance().addServerLog(sid,
                LogManagerAdapter.LogType.ERROR, "Error performing annotation(s). " + ie.getLocalizedMessage());

        LOG.error("performBatchAnnotationInParallell interrupted: " + ie);
    } finally {
        // clean up
        try {
            /*
            if (cursors != null) {
                    
            for (AnnotationCursor c : cursors) {
                c.cleanup();
            }
            }*/
            if (recordReader != null) {
                recordReader.close();
            }
            if (recordWriter != null) {
                recordWriter.close();
            }
            inputTDFFile.delete(); //no longer need input TDF file.
        } catch (NullPointerException nex) {
            LOG.error("Caught nullpointerexception ");
            nex.printStackTrace();
        }
    }
}

From source file:com.p2p.misc.DeviceUtility.java

public String availableConnectivity() {
    ConnectivityManager conMan = (ConnectivityManager) mactivity.getSystemService(Context.CONNECTIVITY_SERVICE);

    String nwrType = "";

    // wifi// ww w  .ja v a 2s .c o m
    State wifi = conMan.getNetworkInfo(1).getState();

    // mobile
    State mobile = null;
    try {
        mobile = conMan.getNetworkInfo(0).getState();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

    if (mobile != null && mobile == State.CONNECTED || mobile == State.CONNECTING) {
        nwrType = "GSM";

    } else if (wifi == State.CONNECTED || wifi == State.CONNECTING) {
        nwrType = "Wi-Fi";
    }

    return nwrType;
}

From source file:org.mewx.wenku8.fragment.NavigationDrawerFragment.java

/**
 * This function clear all the effects on button, and it needs API Level 16.
 * So if the device is between 4.0-4.1, it will appear no effects.
 *
 * Notice:// ww w.  j ava2 s. c  o  m
 * Once the enum MainActivity.FRAGMENT_LIST changes, this function show be edited.
 */
private void clearAllButtonColor() {
    // sdk ver is too low
    if (Build.VERSION.SDK_INT < 16) {
        try {
            // Clear icon color
            ImageButton imageButton;
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_rklist);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_latest);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_fav);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_config);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));

            // Clear icon color effects
            TextView textView;
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_rklist);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_latest);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_fav);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_config);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));
        } catch (NullPointerException e) {
            Toast.makeText(mainActivity, "NullPointerException in clearAllButtonColor(); sdk16-",
                    Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    } else {
        try {
            // Clear the background effects on "main buttons"
            TableRow tableRow;
            tableRow = (TableRow) mainActivity.findViewById(R.id.main_menu_rklist);
            tableRow.setBackground(getResources().getDrawable(R.drawable.btn_menu_item));
            tableRow = (TableRow) mainActivity.findViewById(R.id.main_menu_latest);
            tableRow.setBackground(getResources().getDrawable(R.drawable.btn_menu_item));
            tableRow = (TableRow) mainActivity.findViewById(R.id.main_menu_fav);
            tableRow.setBackground(getResources().getDrawable(R.drawable.btn_menu_item));
            tableRow = (TableRow) mainActivity.findViewById(R.id.main_menu_config);
            tableRow.setBackground(getResources().getDrawable(R.drawable.btn_menu_item));

            // Clear icon color effects
            TextView textView;
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_rklist);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_latest);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_fav);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));
            textView = (TextView) mainActivity.findViewById(R.id.main_menu_text_config);
            textView.setTextColor(getResources().getColor(R.color.menu_text_color));

            // Clear icon color
            ImageButton imageButton;
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_rklist);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_latest);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_fav);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));
            imageButton = (ImageButton) mainActivity.findViewById(R.id.main_menu_ic_config);
            imageButton.setColorFilter(getResources().getColor(R.color.menu_text_color));

            // Clear the dark and light switcher button effect
            //            textView = (TextView) mainActivity.findViewById(R.id.main_menu_dark_mode_switcher);
            //            textView.setTextColor(getResources().getColor(R.color.main_menu_color_text));
            //            textView.setBackground(getResources().getDrawable(R.drawable.btn_menu_item));

        } catch (NullPointerException e) {
            Toast.makeText(mainActivity, "NullPointerException in clearAllButtonColor();", Toast.LENGTH_SHORT)
                    .show();
            e.printStackTrace();
        }
    }
}