Example usage for java.lang IllegalArgumentException printStackTrace

List of usage examples for java.lang IllegalArgumentException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:org.cobaltians.cobalt.activities.CobaltActivity.java

public int getResourceIdentifier(String resource) {
    int resId = 0;

    try {//from  w  ww . j  ava 2  s  .  co m
        if (resource == null || resource.length() == 0) {
            throw new IllegalArgumentException();
        }

        String[] resourceSplit = resource.split(":");
        String packageName, resourceName;
        switch (resourceSplit.length) {
        case 1:
            packageName = getPackageName();
            resourceName = resourceSplit[0];
            break;
        case 2:
            packageName = resourceSplit[0].length() != 0 ? resourceSplit[0] : getPackageName();
            resourceName = resourceSplit[1];
            break;
        default:
            throw new IllegalArgumentException();
        }
        resId = getResources().getIdentifier(resourceName, "drawable", packageName);
        if (resId == 0) {
            Log.w(Cobalt.TAG, TAG + "getResourceIdentifier: resource " + resource + " not found.");
        }
    } catch (IllegalArgumentException exception) {
        if (Cobalt.DEBUG) {
            Log.w(Cobalt.TAG, TAG + "getResourceIdentifier: resource " + resource
                    + " format not supported, use resource, :resource or package:resource.");
        }
        exception.printStackTrace();
    }

    return resId;
}

From source file:com.corebase.android.framework.http.client.AsyncHttpClient.java

/**
 * post//www .j ava2s.c  o  m
 * 
 * @param context
 * @param url
 * @param entity
 * @param cacheParams
 * @param contentType
 * @param responseHandler
 * @param requestParam
 */
public void postToCache(Context context, String url, HttpEntity entity, CacheParams cacheParams,
        String contentType, AsyncHttpResponseHandler responseHandler, String requestParam) {
    HttpPost httpPost;
    if (null == url || "".equals(url))
        return;
    try {
        httpPost = new HttpPost(url);
    } catch (IllegalArgumentException e) {
        responseHandler.sendFailureMessage(context, e, "uri is invalid");
        e.printStackTrace();
        return;
    }
    setTimeout(socketTimeout);

    try {
        sendRequestPost(httpClient, httpContext, addEntityToRequestBase(httpPost, entity), contentType,
                cacheParams, responseHandler, context, requestParam);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.corebase.android.framework.http.client.AsyncHttpClient.java

public void post(String url, Map<String, String> clientHeaderMap, RequestParams params, String contentType,
        AsyncHttpResponseHandler responseHandler) {
    HttpEntityEnclosingRequestBase request;
    if (null == url || "".equals(url))
        return;/*from  w ww.j  ava 2 s  . c o  m*/
    try {
        request = new HttpPost(url);
    } catch (IllegalArgumentException e) {
        responseHandler.sendFailureMessage(null, e, "uri is invalid");
        e.printStackTrace();
        return;
    }

    if (params != null)
        request.setEntity(paramsToEntity(params));

    if (clientHeaderMap != null && clientHeaderMap.size() > 0) {
        for (String header : clientHeaderMap.keySet()) {
            request.addHeader(header, clientHeaderMap.get(header));
        }
    }
    setTimeout(socketTimeout);
    // if(headers != null) request.setHeaders(headers);

    sendRequest(httpClient, httpContext, request, contentType, null, responseHandler, null);
}

From source file:com.corebase.android.framework.http.client.AsyncHttpClient.java

/**
 * Perform a HTTP GET request and track the Android Context which initiated
 * the request with customized headers/* w  ww .j av a2  s .  c o m*/
 * 
 * @param url
 *            the URL to send the request to.
 * @param headers
 *            set headers only for this request
 * @param params
 *            additional GET parameters to send with the request.
 * @param responseHandler
 *            the response handler instance that should handle the response.
 */
public void get(Context context, String url, Map<String, String> clientHeaderMap, RequestParams params,
        CacheParams cacheParams, AsyncHttpResponseHandler responseHandler) {
    HttpUriRequest request = null;
    if (null == url || "".equals(url))
        return;
    try {
        request = new HttpGet(getUrlWithQueryString(url, params));
    } catch (IllegalArgumentException e) {
        responseHandler.sendFailureMessage(context, e, "uri is invalid");
        e.printStackTrace();
        return;
    }

    if (clientHeaderMap != null && clientHeaderMap.size() > 0) {
        for (String header : clientHeaderMap.keySet()) {
            request.addHeader(header, clientHeaderMap.get(header));
        }
    }

    setTimeout(socketTimeout);
    // if(headers != null) request.setHeaders(headers);

    sendRequest(httpClient, httpContext, request, null, cacheParams, responseHandler, context);
}

From source file:com.corebase.android.framework.http.client.AsyncHttpClient.java

/**
 * Perform a HTTP POST request and track the Android Context which initiated
 * the request. Set headers only for this request
 * /*from   w w w . ja v  a2  s.c om*/
 * @param context
 *            the Android Context which initiated the request.
 * @param url
 *            the URL to send the request to.
 * @param headers
 *            set headers only for this request
 * @param params
 *            additional POST parameters to send with the request.
 * @param contentType
 *            the content type of the payload you are sending, for example
 *            application/json if sending a json payload.
 * @param responseHandler
 *            the response handler instance that should handle the response.
 */
public void post(Context context, String url, Map<String, String> clientHeaderMap, RequestParams params,
        String contentType, AsyncHttpResponseHandler responseHandler) {
    HttpEntityEnclosingRequestBase request;

    if (null == url || "".equals(url))
        return;
    try {
        request = new HttpPost(url);
    } catch (IllegalArgumentException e) {
        responseHandler.sendFailureMessage(context, e, "uri is invalid");
        e.printStackTrace();
        return;
    }
    if (params != null)
        request.setEntity(paramsToEntity(params));

    if (clientHeaderMap != null && clientHeaderMap.size() > 0) {
        for (String header : clientHeaderMap.keySet()) {
            request.addHeader(header, clientHeaderMap.get(header));
        }
    }
    setTimeout(socketTimeout);
    sendRequest(httpClient, httpContext, request, contentType, null, responseHandler, context);
}

From source file:com.dngames.mobilewebcam.PhotoSettings.java

@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    if (key == "cam_refresh") {
        int new_refresh = getEditInt(mContext, prefs, "cam_refresh", 60);
        String msg = "Camera refresh set to " + new_refresh + " seconds!";
        if (MobileWebCam.gIsRunning) {
            if (!mNoToasts && new_refresh != mRefreshDuration) {
                try {
                    Toast.makeText(mContext.getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
                } catch (RuntimeException e) {
                    e.printStackTrace();
                }//from w  w  w.  j  a  va  2 s. c o m
            }
        } else if (new_refresh != mRefreshDuration) {
            MobileWebCam.LogI(msg);
        }
    }

    // get all preferences
    for (Field f : getClass().getFields()) {
        {
            BooleanPref bp = f.getAnnotation(BooleanPref.class);
            if (bp != null) {
                try {
                    f.setBoolean(this, prefs.getBoolean(bp.key(), bp.val()));
                } catch (Exception e) {
                    Log.e("MobileWebCam", "Exception: " + bp.key() + " <- " + bp.val());
                    e.printStackTrace();
                }
            }
        }
        {
            EditIntPref ip = f.getAnnotation(EditIntPref.class);
            if (ip != null) {
                try {
                    int eval = getEditInt(mContext, prefs, ip.key(), ip.val()) * ip.factor();
                    if (ip.max() != Integer.MAX_VALUE)
                        eval = Math.min(eval, ip.max());
                    if (ip.min() != Integer.MIN_VALUE)
                        eval = Math.max(eval, ip.min());
                    f.setInt(this, eval);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        {
            IntPref ip = f.getAnnotation(IntPref.class);
            if (ip != null) {
                try {
                    int eval = prefs.getInt(ip.key(), ip.val()) * ip.factor();
                    if (ip.max() != Integer.MAX_VALUE)
                        eval = Math.min(eval, ip.max());
                    if (ip.min() != Integer.MIN_VALUE)
                        eval = Math.max(eval, ip.min());
                    f.setInt(this, eval);
                } catch (Exception e) {
                    // handle wrong set class
                    e.printStackTrace();
                    Editor edit = prefs.edit();
                    edit.remove(ip.key());
                    edit.putInt(ip.key(), ip.val());
                    edit.commit();
                    try {
                        f.setInt(this, ip.val());
                    } catch (IllegalArgumentException e1) {
                        e1.printStackTrace();
                    } catch (IllegalAccessException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
        {
            EditFloatPref fp = f.getAnnotation(EditFloatPref.class);
            if (fp != null) {
                try {
                    float eval = getEditFloat(mContext, prefs, fp.key(), fp.val());
                    if (fp.max() != Float.MAX_VALUE)
                        eval = Math.min(eval, fp.max());
                    if (fp.min() != Float.MIN_VALUE)
                        eval = Math.max(eval, fp.min());
                    f.setFloat(this, eval);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        {
            StringPref sp = f.getAnnotation(StringPref.class);
            if (sp != null) {
                try {
                    f.set(this, prefs.getString(sp.key(), getDefaultString(mContext, sp)));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    mCustomImageScale = Enum.valueOf(ImageScaleMode.class, prefs.getString("custompicscale", "CROP"));

    mAutoStart = prefs.getBoolean("autostart", false);
    mCameraStartupEnabled = prefs.getBoolean("cam_autostart", true);
    mShutterSound = prefs.getBoolean("shutter", true);
    mDateTimeColor = GetPrefColor(prefs, "datetime_color", "#FFFFFFFF", Color.WHITE);
    mDateTimeShadowColor = GetPrefColor(prefs, "datetime_shadowcolor", "#FF000000", Color.BLACK);
    mDateTimeBackgroundColor = GetPrefColor(prefs, "datetime_backcolor", "#80FF0000",
            Color.argb(0x80, 0xFF, 0x00, 0x00));
    mDateTimeBackgroundLine = prefs.getBoolean("datetime_fillline", true);
    mDateTimeX = prefs.getInt("datetime_x", 98);
    mDateTimeY = prefs.getInt("datetime_y", 98);
    mDateTimeAlign = Paint.Align.valueOf(prefs.getString("datetime_imprintalign", "RIGHT"));

    mDateTimeFontScale = (float) prefs.getInt("datetime_fontsize", 6);

    mTextColor = GetPrefColor(prefs, "text_color", "#FFFFFFFF", Color.WHITE);
    mTextShadowColor = GetPrefColor(prefs, "text_shadowcolor", "#FF000000", Color.BLACK);
    mTextBackgroundColor = GetPrefColor(prefs, "text_backcolor", "#80FF0000",
            Color.argb(0x80, 0xFF, 0x00, 0x00));
    mTextBackgroundLine = prefs.getBoolean("text_fillline", true);
    mTextX = prefs.getInt("text_x", 2);
    mTextY = prefs.getInt("text_y", 2);
    mTextAlign = Paint.Align.valueOf(prefs.getString("text_imprintalign", "LEFT"));
    mTextFontScale = (float) prefs.getInt("infotext_fontsize", 6);
    mTextFontname = prefs.getString("infotext_fonttypeface", "");

    mStatusInfoColor = GetPrefColor(prefs, "statusinfo_color", "#FFFFFFFF", Color.WHITE);
    mStatusInfoShadowColor = GetPrefColor(prefs, "statusinfo_shadowcolor", "#FF000000", Color.BLACK);
    mStatusInfoX = prefs.getInt("statusinfo_x", 2);
    mStatusInfoY = prefs.getInt("statusinfo_y", 98);
    mStatusInfoAlign = Paint.Align.valueOf(prefs.getString("statusinfo_imprintalign", "LEFT"));
    mStatusInfoBackgroundColor = GetPrefColor(prefs, "statusinfo_backcolor", "#00000000", Color.TRANSPARENT);
    mStatusInfoFontScale = (float) prefs.getInt("statusinfo_fontsize", 6);
    mStatusInfoBackgroundLine = prefs.getBoolean("statusinfo_fillline", false);

    mGPSColor = GetPrefColor(prefs, "gps_color", "#FFFFFFFF", Color.WHITE);
    mGPSShadowColor = GetPrefColor(prefs, "gps_shadowcolor", "#FF000000", Color.BLACK);
    mGPSX = prefs.getInt("gps_x", 98);
    mGPSY = prefs.getInt("gps_y", 2);
    mGPSAlign = Paint.Align.valueOf(prefs.getString("gps_imprintalign", "RIGHT"));
    mGPSBackgroundColor = GetPrefColor(prefs, "gps_backcolor", "#00000000", Color.TRANSPARENT);
    mGPSFontScale = (float) prefs.getInt("gps_fontsize", 6);
    mGPSBackgroundLine = prefs.getBoolean("gps_fillline", false);

    mImprintPictureX = prefs.getInt("imprint_picture_x", 0);
    mImprintPictureY = prefs.getInt("imprint_picture_y", 0);

    mNightAutoConfigEnabled = prefs.getBoolean("night_auto_enabled", false);

    mSetNightConfiguration = prefs.getBoolean("cam_nightconfiguration", false);
    // override night camera parameters (read again with postfix)
    getCurrentNightSettings();

    mFilterPicture = false; //***prefs.getBoolean("filter_picture", false);
    mFilterType = getEditInt(mContext, prefs, "filter_sel", 0);

    if (mImprintPicture) {
        if (mImprintPictureURL.length() == 0) {
            // sdcard image
            File path = new File(Environment.getExternalStorageDirectory() + "/MobileWebCam/");
            if (path.exists()) {
                synchronized (gImprintBitmapLock) {
                    if (gImprintBitmap != null)
                        gImprintBitmap.recycle();
                    gImprintBitmap = null;

                    File file = new File(path, "imprint.png");
                    try {
                        FileInputStream in = new FileInputStream(file);
                        gImprintBitmap = BitmapFactory.decodeStream(in);
                        in.close();
                    } catch (IOException e) {
                        Toast.makeText(mContext, "Error: unable to read imprint bitmap " + file.getName() + "!",
                                Toast.LENGTH_SHORT).show();
                        gImprintBitmap = null;
                    } catch (OutOfMemoryError e) {
                        Toast.makeText(mContext, "Error: imprint bitmap " + file.getName() + " too large!",
                                Toast.LENGTH_LONG).show();
                        gImprintBitmap = null;
                    }
                }
            }
        } else {
            DownloadImprintBitmap();
        }

        synchronized (gImprintBitmapLock) {
            if (gImprintBitmap == null) {
                // last resort: resource default
                try {
                    gImprintBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.imprint);
                } catch (OutOfMemoryError e) {
                    Toast.makeText(mContext, "Error: default imprint bitmap too large!", Toast.LENGTH_LONG)
                            .show();
                    gImprintBitmap = null;
                }
            }
        }
    }

    mNoToasts = prefs.getBoolean("no_messages", false);
    mFullWakeLock = prefs.getBoolean("full_wakelock", true);

    switch (getEditInt(mContext, prefs, "camera_mode", 1)) {
    case 0:
        mMode = Mode.MANUAL;
        break;
    case 2:
        mMode = Mode.HIDDEN;
        break;
    case 3:
        mMode = Mode.BACKGROUND;
        break;
    case 1:
    default:
        mMode = Mode.NORMAL;
        break;
    }
}

From source file:com.hortonworks.historian.nifi.reporter.HistorianDeanReporter.java

private String renameHDFSObject(String oldPathString, String newPathString) {
    Path oldPath = new Path(oldPathString);
    Path newPath = new Path(newPathString);
    try {/*from www  .j a va 2 s  . co m*/
        fs.rename(oldPath, newPath);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return newPathString.toString();
}

From source file:org.cobaltians.cobalt.activities.CobaltActivity.java

public void setBarContent(JSONObject content) {
    Toolbar topBar = (Toolbar) findViewById(getTopBarId());
    ActionBar actionBar = getSupportActionBar();
    BottomBar bottomBar = (BottomBar) findViewById(getBottomBarId());
    int colorInt = CobaltFontManager.DEFAULT_COLOR;
    boolean applyColor = false;

    try {/*from  w  w w .  j av a2s.  c o m*/
        String backgroundColor = content.optString(Cobalt.kBarsBackgroundColor, null);
        // TODO: apply on overflow popup
        if (backgroundColor != null) {
            int backgroundColorInt = Cobalt.parseColor(backgroundColor);
            if (actionBar != null)
                actionBar.setBackgroundDrawable(new ColorDrawable(backgroundColorInt));
            bottomBar.setBackgroundColor(backgroundColorInt);
        }
    } catch (IllegalArgumentException exception) {
        if (Cobalt.DEBUG) {
            Log.w(Cobalt.TAG, TAG
                    + " - setBarContent: backgroundColor format not supported, use (#)RGB or (#)RRGGBB(AA).");
        }
        exception.printStackTrace();
    }

    try {
        String color = content.optString(Cobalt.kBarsColor, null);
        if (color != null) {
            colorInt = Cobalt.parseColor(color);
            applyColor = true;
            topBar.setTitleTextColor(colorInt);

            Drawable overflowIconDrawable = topBar.getOverflowIcon();
            // should never be null but sometimes....
            if (overflowIconDrawable != null) {
                overflowIconDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP);
            }

            Drawable navigationIconDrawable = topBar.getNavigationIcon();
            // should never be null but sometimes....
            if (navigationIconDrawable != null) {
                navigationIconDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP);
            }
        }
    } catch (IllegalArgumentException exception) {
        if (Cobalt.DEBUG) {
            Log.w(Cobalt.TAG, TAG + " - setupBars: color format not supported, use (#)RGB or (#)RRGGBB(AA).");
        }
        exception.printStackTrace();
    }

    String logo = content.optString(Cobalt.kBarsIcon, null);
    if (logo != null && !logo.equals("")) {
        Drawable logoDrawable = null;

        int logoResId = getResourceIdentifier(logo);
        if (logoResId != 0) {
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    logoDrawable = getResources().getDrawable(logoResId, null);
                } else {
                    logoDrawable = getResources().getDrawable(logoResId);
                }

                if (applyColor && logoDrawable != null) {
                    logoDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP);
                }
            } catch (Resources.NotFoundException exception) {
                Log.w(Cobalt.TAG, TAG + " - setupBars: " + logo + " resource not found.");
                exception.printStackTrace();
            }
        } else {
            logoDrawable = CobaltFontManager.getCobaltFontDrawable(getApplicationContext(), logo, colorInt);
        }
        topBar.setLogo(logoDrawable);
        if (actionBar != null)
            actionBar.setDisplayShowHomeEnabled(true);
    } else {
        if (actionBar != null)
            actionBar.setDisplayShowHomeEnabled(false);
    }

    if (content.has(Cobalt.kBarsNavigationIcon)) {
        try {
            JSONObject navigationIcon = content.getJSONObject(Cobalt.kBarsNavigationIcon);
            if (navigationIcon == null)
                navigationIcon = new JSONObject();
            boolean enabled = navigationIcon.optBoolean(Cobalt.kNavigationIconEnabled, true);
            if (actionBar != null)
                actionBar.setDisplayHomeAsUpEnabled(enabled);
            Drawable navigationIconDrawable = null;

            String icon = navigationIcon.optString(Cobalt.kNavigationIconIcon);
            if (icon != null) {
                int iconResId = getResourceIdentifier(icon);
                if (iconResId != 0) {
                    try {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            navigationIconDrawable = getResources().getDrawable(iconResId, null);
                        } else {
                            navigationIconDrawable = getResources().getDrawable(iconResId);
                        }
                        if (applyColor && navigationIconDrawable != null) {
                            navigationIconDrawable.setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP);
                        }
                    } catch (Resources.NotFoundException exception) {
                        Log.w(Cobalt.TAG, TAG + " - setupBars: " + icon + " resource not found.");
                        exception.printStackTrace();
                    }
                } else {
                    navigationIconDrawable = CobaltFontManager.getCobaltFontDrawable(getApplicationContext(),
                            icon, colorInt);
                }
                topBar.setNavigationIcon(navigationIconDrawable);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    if (content.has(Cobalt.kBarsTitle) && actionBar != null) {
        try {
            String title = content.getString(Cobalt.kBarsTitle);
            if (title != null) {
                actionBar.setTitle(title);
            } else {
                actionBar.setDisplayShowTitleEnabled(false);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

/**
 * fetch ??  ? rrdDb? ?.//from   w  w w .j a  va2 s .  c om
 * @param device
 * @param databaseName
 * @param fetchData
 */
public void restoreTetradRrdDb(String rrdPath, FetchData fetchData) throws Exception {
    RrdDb rrdDb = null;

    try {
        // RrdDb ?
        rrdDb = new RrdDb(rrdPath);

        int columnCount = fetchData.getColumnCount();
        int rowCount = fetchData.getRowCount();
        long[] timestamps = fetchData.getTimestamps();
        String[] keys = fetchData.getDsNames();
        double[][] values = fetchData.getValues();
        Sample sample = null;
        for (int row = 0; row < rowCount; row++) {
            try {
                long t = timestamps[row];
                sample = rrdDb.createSample(t);
                for (int dsIndex = 0; dsIndex < columnCount; dsIndex++) {
                    if (rrdDb.containsDs((String) keys[dsIndex])) {
                        sample.setValue(keys[dsIndex], values[dsIndex][row]);
                    }
                }
                sample.update();
            } catch (IllegalArgumentException e) {
                // rrdDb? lastupdate time  ?? ??  , IllegalArgumentException ?.
                // rrdDb? lastupdate time  ?? ??   ?   , exception    ?.
                e.printStackTrace();
            }
        }
        rrdDb.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        try {
            if (rrdDb != null)
                rrdDb.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}