Example usage for java.lang IllegalStateException printStackTrace

List of usage examples for java.lang IllegalStateException printStackTrace

Introduction

In this page you can find the example usage for java.lang IllegalStateException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:me.azenet.UHPlugin.UHPluginCommand.java

/**
 * This command starts the game./*  w  ww  . j  a  va 2s.c  om*/
 * 
 * Usage: /uh start [slow [go]]
 * 
 * @param sender
 * @param command
 * @param label
 * @param args
 */
@SuppressWarnings("unused")
private void doStart(CommandSender sender, Command command, String label, String[] args) {

    if (args.length == 1) { // /uh start (standard mode)
        try {
            p.getGameManager().start(sender, false);
        } catch (IllegalStateException e) {
            sender.sendMessage(i.t("start.already"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (args.length == 2 && args[1].equalsIgnoreCase("slow")) { // /uh start slow
        try {
            p.getGameManager().start(sender, true);
        } catch (IllegalStateException e) {
            sender.sendMessage(i.t("start.already"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (args.length == 3 && args[1].equalsIgnoreCase("slow") && args[2].equalsIgnoreCase("go")) { // /uh start slow go
        p.getGameManager().finalizeStartSlow(sender);
    } else {
        sender.sendMessage(i.t("start.syntax"));
    }
}

From source file:edu.cmu.tetrad.search.Lofs2.java

private void optimizeAllRows(TetradMatrix data, final double range, List<List<Integer>> rows,
        List<List<Double>> parameters) {

    for (int i = 0; i < rows.size(); i++) {
        System.out.println("Optimizing row = " + i);

        try {//  ww  w .  ja v  a2s .  c o  m
            optimizeRow(i, data, range, rows, parameters);
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.irccloud.android.fragment.MessageViewFragment.java

private void update_top_unread(int first) {
    if (adapter != null && buffer != null) {
        try {//from   ww  w .ja  v  a2 s .c o  m
            int markerPos = adapter.getLastSeenEIDPosition();
            if (markerPos >= 0 && first > (markerPos + 1) && buffer.unread > 0) {
                if (shouldTrackUnread()) {
                    int highlights = adapter.getUnreadHighlightsAbovePosition(first);
                    int count = (first - markerPos - 1) - highlights;
                    StringBuilder txt = new StringBuilder();
                    if (highlights > 0) {
                        if (highlights == 1)
                            txt.append("mention");
                        else if (highlights > 0)
                            txt.append("mentions");
                        highlightsTopLabel.setText(String.valueOf(highlights));
                        highlightsTopLabel.setVisibility(View.VISIBLE);

                        if (count > 0)
                            txt.append(" and ");
                    } else {
                        highlightsTopLabel.setVisibility(View.GONE);
                    }
                    if (markerPos == 0) {
                        long seconds = (long) Math.ceil((earliest_eid - buffer.last_seen_eid) / 1000000.0);
                        if (seconds < 0) {
                            if (count < 0) {
                                hideView(unreadTopView);
                                return;
                            } else {
                                if (count == 1)
                                    txt.append(count).append(" unread message");
                                else if (count > 0)
                                    txt.append(count).append(" unread messages");
                            }
                        } else {
                            int minutes = (int) Math.ceil(seconds / 60.0);
                            int hours = (int) Math.ceil(seconds / 60.0 / 60.0);
                            int days = (int) Math.ceil(seconds / 60.0 / 60.0 / 24.0);
                            if (hours >= 24) {
                                if (days == 1)
                                    txt.append(days).append(" day of unread messages");
                                else
                                    txt.append(days).append(" days of unread messages");
                            } else if (hours > 0) {
                                if (hours == 1)
                                    txt.append(hours).append(" hour of unread messages");
                                else
                                    txt.append(hours).append(" hours of unread messages");
                            } else if (minutes > 0) {
                                if (minutes == 1)
                                    txt.append(minutes).append(" minute of unread messages");
                                else
                                    txt.append(minutes).append(" minutes of unread messages");
                            } else {
                                if (seconds == 1)
                                    txt.append(seconds).append(" second of unread messages");
                                else
                                    txt.append(seconds).append(" seconds of unread messages");
                            }
                        }
                    } else {
                        if (count == 1)
                            txt.append(count).append(" unread message");
                        else if (count > 0)
                            txt.append(count).append(" unread messages");
                    }
                    unreadTopLabel.setText(txt);
                    showView(unreadTopView);
                } else {
                    hideView(unreadTopView);
                }
            } else {
                if (markerPos > 0) {
                    hideView(unreadTopView);
                    if (adapter.data.size() > 0 && ready) {
                        if (heartbeatTask != null)
                            heartbeatTask.cancel(true);
                        heartbeatTask = new HeartbeatTask();
                        heartbeatTask.execute((Void) null);
                    }
                }
            }
        } catch (IllegalStateException e) {
            //The list view wasn't on screen yet
            e.printStackTrace();
        }
    }
}

From source file:com.mobileobservinglog.support.billing.DonationBillingHandler.java

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity./*  w  ww . j  a v  a2 s  .co  m*/
 * @param sku The sku of the item to purchase.
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link android.app.Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnPurchaseFinishedListener listener,
        String extraData) {
    Log.d("InAppPurchase", "Purchase Flow started -- handler");
    BillingHandlerResult result;
    purchaseListener = listener;
    try {
        checkSetupDone("launchPurchaseFlow");
    } catch (IllegalStateException e) {
        Log.d("InAppPurchase", "Setup was not done -- handler");
        result = new BillingHandlerResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Setup was not finished yet");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
        return;
    }
    flagStartAsync("launchPurchaseFlow");

    try {
        Log.d("InAppPurchase", "Starting the purchase try -- handler");
        Bundle buyIntentBundle = service.getBuyIntent(3, context.getPackageName(), sku, ITEM_TYPE_INAPP,
                extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            Log.d("InAppPurchase", "The response code from the bundle was not OK -- handler");

            //In case we have a managed item that needs to be consumed. Bit of a hack. But works for now
            if (response == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                String packageName = context.getPackageName();
                service.consumePurchase(3, packageName, "inapp:" + packageName + ":" + sku);
                buyIntentBundle = service.getBuyIntent(3, packageName, sku, ITEM_TYPE_INAPP, extraData);
            }
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        this.requestCode = requestCode;
        Log.d("InAppPurchase", "About to start the intent sender for result -- handler");
        if (pendingIntent != null) {
            act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(),
                    Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
            Log.d("InAppPurchase", "Done with the intent sender for result -- handler");
        } else {
            result = new BillingHandlerResult(BILLINGHELPER_SEND_INTENT_FAILED,
                    "Failed to send intent. We had a null pending intent");
            if (purchaseListener != null)
                purchaseListener.onPurchaseFinished(result, null);
        }
    } catch (SendIntentException e) {
        Log.d("InAppPurchase", "Caught a SendIntentException -- handler");
        e.printStackTrace();

        result = new BillingHandlerResult(BILLINGHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    } catch (RemoteException e) {
        Log.d("InAppPurchase", "Caught RemoteException -- handler");
        e.printStackTrace();

        result = new BillingHandlerResult(BILLINGHELPER_REMOTE_EXCEPTION,
                "Remote exception while starting purchase flow");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    }
}

From source file:com.mobileobservinglog.support.billing.DonationBillingHandler.java

/**
 * Handles an activity result that's part of the purchase flow in in-app billing. If you
 * are calling {@link #launchPurchaseFlow}, then you must call this method from your
 * Activity's {@link android.app.Activity@onActivityResult} method. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param requestCode The requestCode as you received it.
 * @param resultCode The resultCode as you received it.
 * @param data The data (Intent) as you received it.
 * @return Returns true if the result was related to a purchase flow and was handled;
 *     false if the result was not related to a purchase, in which case you should
 *     handle it normally.//from   w ww  .  j av a  2s.c  o  m
 */
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("InAppPurchase", "Starting HandleActivityResult -- handler");
    BillingHandlerResult result;
    if (requestCode != this.requestCode)
        return false;

    try {
        checkSetupDone("handleActivityResult");
    } catch (IllegalStateException e) {
        Log.d("InAppPurchase", "Setup was not done -- handler");
        result = new BillingHandlerResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Setup was not finished yet");
    }

    // end of async purchase operation
    flagEndAsync();

    if (data == null) {
        Log.d("InAppPurchase", "Data was null -- handler");
        result = new BillingHandlerResult(BILLINGHELPER_BAD_RESPONSE, "Null data in IAB result");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
        return true;
    }

    int responseCode = getResponseCodeFromIntent(data);
    String purchaseData = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
    String dataSignature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);

    if (resultCode == Activity.RESULT_OK && responseCode == BILLING_RESPONSE_RESULT_OK) {
        Log.d("InAppPurchase", "Activity.Result was OK and Billing response result was ok -- handler");
        if (purchaseData == null || dataSignature == null) {
            Log.d("InAppPurchase", "But we had null data -- handler");
            result = new BillingHandlerResult(BILLINGHELPER_UNKNOWN_ERROR,
                    "IAB returned null purchaseData or dataSignature");
            if (purchaseListener != null)
                purchaseListener.onPurchaseFinished(result, null);
            return true;
        }

        Purchase purchase = null;
        try {
            Log.d("InAppPurchase", "Checking the purchase -- handler");
            purchase = new Purchase(purchaseData, dataSignature);
            String sku = purchase.getSku();

            // Verify signature
            if (!PurchaseSecurity.verifyPurchase(billingKey, purchaseData, dataSignature)) {
                Log.d("InAppPurchase", "Uh Oh, Verification failed on the purchase -- handler");
                result = new BillingHandlerResult(BILLINGHELPER_VERIFICATION_FAILED,
                        "Signature verification failed for sku " + sku);
                if (purchaseListener != null)
                    purchaseListener.onPurchaseFinished(result, purchase);
                return true;
            }
        } catch (JSONException e) {
            Log.d("InAppPurchase", "Caught a JSON exception -- handler");
            e.printStackTrace();
            result = new BillingHandlerResult(BILLINGHELPER_BAD_RESPONSE, "Failed to parse purchase data.");
            if (purchaseListener != null)
                purchaseListener.onPurchaseFinished(result, null);
            return true;
        }

        if (purchaseListener != null) {
            Log.d("InAppPurchase", "Setting the purchase listener to OK -- handler");
            purchaseListener.onPurchaseFinished(new BillingHandlerResult(BILLING_RESPONSE_RESULT_OK, "Success"),
                    purchase);
        }
    } else if (resultCode == Activity.RESULT_OK) {
        // result code was OK, but in-app billing response was not OK.
        if (purchaseListener != null) {
            Log.d("InAppPurchase", "Problem purchasing the item -- handler");
            result = new BillingHandlerResult(responseCode, "Problem purchashing item.");
            purchaseListener.onPurchaseFinished(result, null);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        Log.d("InAppPurchase", "Purchase was canceled -- handler");
        result = new BillingHandlerResult(BILLINGHELPER_USER_CANCELLED, "User canceled.");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    } else {
        Log.d("InAppPurchase", "this was an unknown purchase -- handler");
        result = new BillingHandlerResult(BILLINGHELPER_UNKNOWN_PURCHASE_RESPONSE,
                "Unknown purchase response.");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    }
    return true;
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * Removes all crossfade callbacks on the current
 * Handler object. Also resets the volumes of the
 * MediaPlayer objects to 1.0f./*from   www  . j  a v a2s  .c  o m*/
 */
private void clearCrossfadeCallbacks() {
    if (mHandler == null)
        return;

    mHandler.removeCallbacks(startCrossFadeRunnable);
    mHandler.removeCallbacks(crossFadeRunnable);

    try {
        getMediaPlayer().setVolume(1.0f, 1.0f);
        getMediaPlayer2().setVolume(1.0f, 1.0f);
    } catch (IllegalStateException e) {
        e.printStackTrace();
    }

}

From source file:com.skurro.pricesnapp1.staggeredgridview.StaggeredGridView.java

/**
 * Should be called with mPopulating set to true
 *
 * @param fromPosition Position to start filling from
 * @param overhang     the number of extra pixels to fill beyond the current bottom edge
 * @return the max overhang beyond the end of the view of any added items at the bottom
 *//*from w  w  w.  ja  v  a2 s.c o  m*/
final int fillDown(int fromPosition, int overhang) {

    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int itemMargin = mItemMargin;
    final int colWidth = (getWidth() - paddingLeft - paddingRight - itemMargin * (mColCount - 1)) / mColCount;
    final int gridBottom = getHeight() - getPaddingBottom();
    final int fillTo = gridBottom + overhang;
    int nextCol = getNextColumnDown(fromPosition);
    int position = fromPosition;

    while (nextCol >= 0 && mItemBottoms[nextCol] < fillTo && position < mItemCount) {

        final View child = obtainView(position, null);

        if (child == null)
            continue;

        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp == null) {
            lp = this.generateDefaultLayoutParams();
            child.setLayoutParams(lp);
        }

        if (child.getParent() != this) {
            if (mInLayout) {
                addViewInLayout(child, -1, lp);
            } else {
                addView(child);
            }
        }

        final int span = Math.min(mColCount, lp.span);
        final int widthSize = colWidth * span + itemMargin * (span - 1);
        final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);

        LayoutRecord rec = null;
        if (span > 1) {
            try {
                rec = getNextRecordDown(position, span);
                //                nextCol = rec.column;
                nextCol = 0;
            } catch (IllegalStateException ise) {
                ise.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            rec = mLayoutRecords.get(position);
        }

        boolean invalidateAfter = false;
        if (rec == null) {
            rec = new LayoutRecord();
            mLayoutRecords.put(position, rec);
            rec.column = nextCol;
            rec.span = span;
        } else if (span != rec.span) {
            rec.span = span;
            rec.column = nextCol;
            invalidateAfter = true;
        } else {
            //                nextCol = rec.column;
        }

        if (mHasStableIds) {
            final long id = mAdapter.getItemId(position);
            rec.id = id;
            lp.id = id;
        }

        lp.column = nextCol;

        /**
         * Magic does not exist
         */
        //            child.measure(MeasureSpec.EXACTLY, MeasureSpec.UNSPECIFIED);

        final int heightSpec;
        if (lp.height == LayoutParams.WRAP_CONTENT) {
            heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        } else {
            heightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
        }
        child.measure(widthSpec, heightSpec);

        final int childHeight = child.getMeasuredHeight();
        if (invalidateAfter || (childHeight != rec.height && rec.height > 0)) {
            invalidateLayoutRecordsAfterPosition(position);
        }
        rec.height = childHeight;

        final int startFrom;
        if (span > 1) {
            int lowest = mItemBottoms[nextCol];

            //                final int colEnd = Math.min(mColCount, nextCol + lp.span);
            // Only for span = maxCol
            for (int i = 0; i < mColCount; i++) {
                final int bottom = mItemBottoms[i];
                if (bottom > lowest) {
                    lowest = bottom;
                }
            }
            startFrom = lowest;
        } else {
            startFrom = mItemBottoms[nextCol];
        }

        final int childTop = startFrom + itemMargin;
        final int childBottom = childTop + childHeight;
        final int childLeft;
        if (span > 1) {
            childLeft = paddingLeft;
        } else {
            childLeft = paddingLeft + nextCol * (colWidth + itemMargin);
        }
        final int childRight = childLeft + child.getMeasuredWidth();
        child.layout(childLeft, childTop, childRight, childBottom);

        rec.left = childLeft;
        rec.top = childTop;
        rec.right = childRight;
        rec.bottom = childBottom;
        rec.hasRecRecord = true;

        // add the position to the mapping
        if (!mColMappings.get(nextCol).contains(position)) {

            // check to see if the mapping exists in activity_other_location columns
            // this would happen if list has been updated
            for (ArrayList<Integer> list : mColMappings) {
                if (list.contains(position)) {
                    list.remove((Integer) position);
                }
            }
            mColMappings.get(nextCol).add(position);
        }

        final int colEnd = Math.min(mColCount, nextCol + lp.span);
        for (int i = nextCol; i < colEnd; i++) {
            mItemBottoms[i] = childBottom + rec.getMarginBelow(i - nextCol);
        }

        position++;
        nextCol = getNextColumnDown(position);
    }

    int lowestView = 0;
    for (int i = 0; i < mColCount; i++) {
        if (mItemBottoms[i] > lowestView) {
            lowestView = mItemBottoms[i];
        }
    }

    return lowestView - gridBottom;
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

protected void postProgressMsgList(boolean isInboxTable, long rowId, String msg) {
    try {//from  w w w  .j  a  v a 2 s . c  om
        if (mTabsAdapter != null) {
            MessagesFragment mf = (MessagesFragment) mTabsAdapter
                    .findFragmentByPosition(Tabs.MESSAGE.ordinal());
            if (mf != null) {
                mf.postProgressMsgList(isInboxTable, rowId, msg);
            }
        }
    } catch (IllegalStateException e) {
        // Can not perform this action after onSaveInstanceState...
        e.printStackTrace();
    }
}

From source file:com.tct.mail.compose.ComposeActivity.java

private void doDiscard() {
    final DialogFragment frag = new DiscardConfirmDialogFragment();
    //AM: peng-zhang 2015-02-15 EMAIL BUGFIX_930453 MOD_S
    //frag.show(getFragmentManager(), "discard confirm");
    try {//www.j  a  v  a  2 s. com
        frag.show(getFragmentManager(), "discard confirm");
    } catch (IllegalStateException e) {
        LogUtils.e(LOG_TAG, "FragmentManager checkStateLoss!");
        e.printStackTrace();
    }
    //AM: peng-zhang 2015-02-15 EMAIL BUGFIX_930453 MOD_E
}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public Media createMediaRecorder(final String path, final String mimeType) throws IOException {
    if (getActivity() == null) {
        return null;
    }//from w  w w  .  ja  va 2  s .  com
    if (!checkForPermission(Manifest.permission.RECORD_AUDIO, "This is required to record audio")) {
        return null;
    }
    final AndroidRecorder[] record = new AndroidRecorder[1];
    final IOException[] error = new IOException[1];

    final Object lock = new Object();
    synchronized (lock) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock) {
                    MediaRecorder recorder = new MediaRecorder();
                    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                    if (mimeType.contains("amr")) {
                        recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
                        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                    } else {
                        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
                    }
                    recorder.setOutputFile(removeFilePrefix(path));
                    try {
                        recorder.prepare();
                        record[0] = new AndroidRecorder(recorder);
                    } catch (IllegalStateException ex) {
                        Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        error[0] = ex;
                    } finally {
                        lock.notify();
                    }

                }
            }
        });

        try {
            lock.wait();
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }

        if (error[0] != null) {
            throw error[0];
        }

        return record[0];
    }
}