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.mili.core.graphics.GraphicsUtilTest.java

@Test
@Ignore//from w w w .  j a  va 2 s  .  co  m
public void test_Image_scaleImage_Image_int_int() {
    // negativ
    try {
        GraphicsUtil.scaleImage(null, 0, 0);
        fail("here was null given, but method works !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    try {
        Image i = GraphicsUtil.readImage(new File(this.dir, "test.jpg"));
        GraphicsUtil.scaleImage(i, -1, 10);
        fail("here was < 0 given, but method works !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
    try {
        Image i = GraphicsUtil.readImage(new File(this.dir, "test.jpg"));
        GraphicsUtil.scaleImage(i, 10, -1);
        fail("here was < 0 given, but method works !");
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
    // positiv keine skalierung
    try {
        Image i = GraphicsUtil.readImage(new File(this.dir, "test.jpg"));
        int x = i.getWidth(null);
        int y = i.getHeight(null);
        i = GraphicsUtil.scaleImage(i, 0, 0);
        assertEquals(x, i.getWidth(null));
        assertEquals(y, i.getHeight(null));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // positiv skalierung
    try {
        Image i = GraphicsUtil.readImage(new File(this.dir, "test_big.jpg"));
        Image p = GraphicsUtil.readImage(new File(this.dir, "block.jpg"));
        double fx = GraphicsUtil.getRelationFactor(i.getWidth(null), i.getHeight(null), p);
        p = GraphicsUtil.scaleImage(p, (int) fx, (int) fx);
        i = GraphicsUtil.pointCenterImage(i, p, 50, 50);
        i = GraphicsUtil.scaleImage(i, 150, 150);
        GraphicsUtil.writeImage(new File(this.dir, "test_scaled.jpg"), i);
        assertEquals(150, i.getWidth(null));
        assertEquals(150, i.getHeight(null));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static void refreshNotification(Context context, boolean noTimeline) {
    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    //int[] unreadCounts = new int[] {4, 1, 2}; // for testing
    int[] unreadCounts = getUnreads(context);

    int timeline = unreadCounts[0];
    int realTimelineCount = timeline;

    // if they don't want that type of notification, simply set it to zero
    if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) {
        unreadCounts[0] = 0;//  ww w. j a  v a2 s. c o m
    }
    if (!settings.mentionsNot) {
        unreadCounts[1] = 0;
    }
    if (!settings.dmsNot) {
        unreadCounts[2] = 0;
    }

    if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) {

    } else {
        Intent markRead = new Intent(context, MarkReadService.class);
        PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

        String shortText = getShortText(unreadCounts, context, currentAccount);
        String longText = getLongText(unreadCounts, context, currentAccount);
        // [0] is the full title and [1] is the screenname
        String[] title = getTitle(unreadCounts, context, currentAccount);
        boolean useExpanded = useExp(context);
        boolean addButton = addBtn(unreadCounts);

        if (title == null) {
            return;
        }

        Intent resultIntent;

        if (unreadCounts[1] != 0 && unreadCounts[0] == 0) {
            // it is a mention notification (could also have a direct message)
            resultIntent = new Intent(context, RedirectToMentions.class);
        } else {
            resultIntent = new Intent(context, MaterialMainActivity.class);
        }

        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

        NotificationCompat.Builder mBuilder;

        Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

        mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0])
                .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1]))
                .setContentIntent(resultPendingIntent).setAutoCancel(true)
                .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
                .setPriority(NotificationCompat.PRIORITY_HIGH);

        if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) {
            // inbox style notification for mentions
            mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) {
            // inbox style notification for direct messages
            mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else {
            // big text style for an unread count on timeline, mentions, and direct messages
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)));
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title[0], shortText);
        }

        // Light Flow notification
        sendToLightFlow(context, title[0], shortText);

        int homeTweets = unreadCounts[0];
        int mentionsTweets = unreadCounts[1];
        int dmTweets = unreadCounts[2];

        int newC = 0;

        if (homeTweets > 0) {
            newC++;
        }
        if (mentionsTweets > 0) {
            newC++;
        }
        if (dmTweets > 0) {
            newC++;
        }

        if (settings.notifications && newC > 0) {

            if (settings.vibrate) {
                mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
            }

            if (settings.sound) {
                try {
                    mBuilder.setSound(Uri.parse(settings.ringtone));
                } catch (Exception e) {
                    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                }
            }

            if (settings.led)
                mBuilder.setLights(0xFFFFFF, 1000, 1000);

            // Get an instance of the NotificationManager service
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

            if (addButton) { // the reply and read button should be shown

                Log.v("username_for_noti", title[1]);
                sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit();
                MentionsDataSource data = MentionsDataSource.getInstance(context);
                long id = data.getLastIds(currentAccount)[0];
                PendingIntent replyPending = PendingIntent.getActivity(context, 0, null, 0);
                sharedPrefs.edit().putLong("from_notification_long", id).commit();
                sharedPrefs.edit()
                        .putString("from_notification_text",
                                "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings))
                        .commit();

                // Create the remote input
                RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                        .setLabel("@" + title[1] + " ").build();

                // Create the notification action
                NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
                        replyPending).addRemoteInput(remoteInput).build();

                NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read),
                        readPending);

                mBuilder.addAction(replyAction);
                mBuilder.addAction(action.build());
            }

            // Build the notification and issues it with notification manager.
            notificationManager.notify(1, mBuilder.build());

            // if we want to wake the screen on a new message
            if (settings.wakeScreen) {
                PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                        | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
                wakeLock.acquire(5000);
            }
        }

        // if there are unread tweets on the timeline, check them for favorite users
        if (settings.favoriteUserNotifications && realTimelineCount > 0) {
            favUsersNotification(currentAccount, context);
        }
    }

    try {

        ContentValues cv = new ContentValues();

        cv.put("tag", "com.daiv.android.twitter/com.daiv.android.twitter.ui.MainActivity");

        // add the direct messages and mentions
        cv.put("count", unreadCounts[1] + unreadCounts[2]);

        context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);

    } catch (IllegalArgumentException ex) {

        /* Fine, TeslaUnread is not installed. */

    } catch (Exception ex) {

        /* Some other error, possibly because the format
           of the ContentValues are incorrect.
                
        Log but do not crash over this. */

        ex.printStackTrace();

    }
}

From source file:fm.krui.kruifm.StreamService.java

/**
 * Builds and returns a configured, unprepared MediaPlayer and attach an error handler.
 *///from   w  w  w  . j  a v  a 2  s .  com
public MediaPlayer buildAudioPlayer() {

    // Build MediaPlayer
    mp = new MediaPlayer();

    try {
        mp.reset();
        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mp.setDataSource(streamUrl);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Caught IllegalArgumentException: ");
        e.printStackTrace();
    } catch (IllegalStateException e) {
        Log.e(TAG, "Caught IllegalStateException: ");
        e.printStackTrace();
    } catch (SecurityException e) {
        Log.e(TAG, "Caught SecurityException: ");
        e.printStackTrace();
    } catch (IOException e) {
        Log.e(TAG, "Caught IOException: ");
        e.printStackTrace();
    }

    // Attach error handler to instance.
    /*mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            
    @Override
    public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
            
        // If there is an error in playback, stop and inform the user.
        mp = buildAudioPlayer();
        // FIXME: This should be a status bar message! Update this when that is fully implemented
        Toast.makeText(getApplicationContext(), "Failed to load the stream. Please check your internet connection and try again.", Toast.LENGTH_LONG).show();
        Log.e(TAG, "Error in playback. onError is being called.");
            
        return true;
    }
            
    });*/
    return mp;
}

From source file:com.comphenix.protocol.events.PacketContainerTest.java

@Test
public void testDeepClone() {
    // Try constructing all the packets
    for (PacketType type : PacketType.values()) {
        if (BLACKLISTED.contains(type) || type.isDeprecated()) {
            continue;
        }//from   w  ww.  j  av  a 2s .  co m

        // Whether or not this packet has been registered
        boolean registered = type.isSupported();

        try {
            PacketContainer constructed = new PacketContainer(type);

            if (!registered) {
                fail("Expected IllegalArgumentException(Packet " + type + " not registered");
            }

            // Initialize default values
            constructed.getModifier().writeDefaults();

            // Make sure watchable collections can be cloned
            if (type == PacketType.Play.Server.ENTITY_METADATA) {
                constructed.getWatchableCollectionModifier().write(0, Util.asList(
                        new WrappedWatchableObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)),
                                (byte) 1),
                        new WrappedWatchableObject(new WrappedDataWatcherObject(0, Registry.get(String.class)),
                                "String"),
                        new WrappedWatchableObject(new WrappedDataWatcherObject(0, Registry.get(Float.class)),
                                1.0F)));
            }

            // Clone the packet
            PacketContainer cloned = constructed.deepClone();

            // Make sure they're equivalent
            StructureModifier<Object> firstMod = constructed.getModifier(), secondMod = cloned.getModifier();
            assertEquals(firstMod.size(), secondMod.size());

            if (PacketType.Status.Server.SERVER_INFO.equals(type)) {
                assertArrayEquals(SerializationUtils.serialize(constructed),
                        SerializationUtils.serialize(cloned));
            } else {
                // Make sure all the fields are equivalent
                for (int i = 0; i < firstMod.size(); i++) {
                    if (firstMod.getField(i).getType().isArray())
                        assertArrayEquals(getArray(firstMod.read(i)), getArray(secondMod.read(i)));
                    else
                        testEquality(firstMod.read(i), secondMod.read(i));
                }
            }
        } catch (IllegalArgumentException e) {
            if (!registered) {
                e.printStackTrace();
            } else {
                // Something is very wrong
                throw e;
            }
        } catch (RuntimeException e) {
            throw new RuntimeException("Failed to serialize packet " + type, e);
        }
    }
}

From source file:net.cloudpath.xpressconnect.screens.GetCredentials.java

public WifiConfigurationProxy getExistingConfig(int paramInt) {
    List localList = ((WifiManager) getSystemService("wifi")).getConfiguredNetworks();
    for (int i = 0; i < localList.size(); i++)
        if (((WifiConfiguration) localList.get(i)).networkId == paramInt)
            try {
                WifiConfigurationProxy localWifiConfigurationProxy = new WifiConfigurationProxy(
                        (WifiConfiguration) localList.get(i), this.mLogger);
                return localWifiConfigurationProxy;
            } catch (IllegalArgumentException localIllegalArgumentException) {
                Util.log(this.mLogger, "IllegalArgumentException in getExistingConfig()!");
                localIllegalArgumentException.printStackTrace();
                return null;
            } catch (NoSuchFieldException localNoSuchFieldException) {
                Util.log(this.mLogger, "NoSuchFieldException in getExistingConfig()!");
                localNoSuchFieldException.printStackTrace();
                return null;
            } catch (ClassNotFoundException localClassNotFoundException) {
                Util.log(this.mLogger, "ClassNotFoundException in getExistingConfig()!");
                localClassNotFoundException.printStackTrace();
                return null;
            } catch (IllegalAccessException localIllegalAccessException) {
                Util.log(this.mLogger, "IllegalAccessException in getExistingConfig()!");
                localIllegalAccessException.printStackTrace();
                return null;
            }// www .  j a  v a 2 s .  c  o  m
    return null;
}

From source file:com.medsphere.fileman.FMRecord.java

public Object getObject(String fieldName) {
    Map<String, AnnotatedElement> domainFields = getDomainJavaFields();
    if (domainFields != null) {
        String numericFieldName = getNumericFieldName(fieldName);
        if (numericFieldName != null) {
            AnnotatedElement ele = domainFields.get(numericFieldName);
            setAccessible(ele, true);//from w  w w. ja v  a  2s  .c om
            if (ele instanceof Field) {
                Field classField = (Field) ele;
                if (classField != null) {
                    try {
                        Object retVal = classField.get(this);
                        if (retVal != null) {
                            return retVal;
                        }
                    } catch (IllegalArgumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            } else if (ele instanceof Method) {
                Method classMember = (Method) ele;
                if (classMember != null) {
                    try {
                        Object retVal = classMember.invoke(this);
                        if (retVal != null) {
                            return retVal;
                        }
                    } catch (IllegalArgumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

            }
        }
    }
    // Couldn't get from domain fields.
    if (values == null) {
        return null;
    }
    return values.get(fieldName);
}

From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java

public Object getMetaPacket(Object watcher) {
    Class<?> DataWatcher = Util.getCraftClass("DataWatcher");

    Class<?> PacketPlayOutEntityMetadata = Util.getCraftClass("PacketPlayOutEntityMetadata");

    Object packet = null;/*from  w w w  . j  a  v a2  s. c  o m*/
    try {
        packet = PacketPlayOutEntityMetadata
                .getConstructor(new Class[] { Integer.TYPE, DataWatcher, Boolean.TYPE })
                .newInstance(new Object[] { Integer.valueOf(this.id), watcher, Boolean.valueOf(true) });
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    return packet;
}

From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java

public Object getTeleportPacket(Location loc) {
    Class<?> PacketPlayOutEntityTeleport = Util.getCraftClass("PacketPlayOutEntityTeleport");

    Object packet = null;//from   w w w.j a v a 2 s . c o m
    try {
        packet = PacketPlayOutEntityTeleport
                .getConstructor(new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Byte.TYPE,
                        Byte.TYPE, Boolean.TYPE })
                .newInstance(new Object[] { Integer.valueOf(this.id), Integer.valueOf(loc.getBlockX() * 32),
                        Integer.valueOf(loc.getBlockY() * 32), Integer.valueOf(loc.getBlockZ() * 32),
                        Byte.valueOf((byte) ((int) loc.getYaw() * 256 / 360)),
                        Byte.valueOf((byte) ((int) loc.getPitch() * 256 / 360)), Boolean.valueOf(false) });
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    return packet;
}

From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java

public Object getWatcher() {
    Class<?> Entity = Util.getCraftClass("Entity");
    Class<?> DataWatcher = Util.getCraftClass("DataWatcher");

    Object watcher = null;//from  w w  w  .j a  v  a 2s . c  o m
    try {
        watcher = DataWatcher.getConstructor(new Class[] { Entity }).newInstance(new Object[] { this.dragon });
        Method a = Util.getMethod(DataWatcher, "a", new Class[] { Integer.TYPE, Object.class });

        a.invoke(watcher,
                new Object[] { Integer.valueOf(0), Byte.valueOf(isVisible() ? (byte) 0 : (byte) 32) });
        a.invoke(watcher, new Object[] { Integer.valueOf(6), Float.valueOf(this.health) });
        a.invoke(watcher, new Object[] { Integer.valueOf(7), Integer.valueOf(0) });
        a.invoke(watcher, new Object[] { Integer.valueOf(8), Byte.valueOf((byte) 0) });
        a.invoke(watcher, new Object[] { Integer.valueOf(10), this.name });
        a.invoke(watcher, new Object[] { Integer.valueOf(11), Byte.valueOf((byte) 1) });
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    return watcher;
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

protected boolean isScrollOver(float distanceX) {
    try {//from  ww  w  .j  a  v  a 2 s  . c om
        if (mDisplayMatrix != null) {
            float m_x = getValue(mDisplayMatrix, Matrix.MTRANS_X); //?
            float width = getWidth() - m_x;
            //width  ?+? 
            //mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X)  ?
            //width == mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X) ???? == 0??                        
            if ((m_x == 0 && distanceX <= 0) //
                    || (width == mBitmap.getWidth() //??
                            * getValue(mDisplayMatrix, Matrix.MSCALE_X) && distanceX >= 0)) {
                System.out.println("ScrollOver");
                return true;
            }
        }
    } catch (IllegalArgumentException e) {
        Log.v("Vincent", "isScrollOver");
        e.printStackTrace();
    }

    return false;
}