List of usage examples for java.lang.reflect InvocationTargetException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void recreate(Activity activity) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { recreateHC(activity);/*from ww w . j a v a 2 s. c o m*/ } else { try { recreateGB(activity); } catch (InvocationTargetException e) { e.getTargetException().printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.ReconfigurationPacket.java
private static BasicReconfigurationPacket<?> getReconfigurationPacket(JSONObject json, Map<ReconfigurationPacket.PacketType, Class<?>> typeMap, Stringifiable<?> unstringer, boolean forcePrintException) throws JSONException { BasicReconfigurationPacket<?> rcPacket = null; ReconfigurationPacket.PacketType rcType = null; String canonicalClassName = null; try {// w ww . ja v a2s. c o m long t = System.nanoTime(); if ((rcType = ReconfigurationPacket.PacketType.intToType.get(JSONPacket.getPacketType(json))) != null && (canonicalClassName = getPacketTypeCanonicalClassName(rcType)) != null) { rcPacket = (BasicReconfigurationPacket<?>) (Class.forName(canonicalClassName) .getConstructor(JSONObject.class, Stringifiable.class).newInstance(json, unstringer)); } DelayProfiler.updateDelayNano("rc_reflection", t); } catch (NoSuchMethodException nsme) { nsme.printStackTrace(); } catch (InvocationTargetException ite) { ite.printStackTrace(); } catch (IllegalAccessException iae) { iae.printStackTrace(); } catch (ClassNotFoundException cnfe) { Reconfigurator.getLogger().info("Class " + canonicalClassName + " not found"); cnfe.printStackTrace(); } catch (InstantiationException ie) { ie.printStackTrace(); } finally { if (forcePrintException && ReconfigurationPacket.PacketType.intToType.get(JSONPacket.getPacketType(json)) == null) { (new RuntimeException("No reconfiguration packet type found in: " + json)).printStackTrace(); } } return rcPacket; }
From source file:io.github.wysohn.triggerreactor.tools.ReflectionUtil.java
public static Object constructNew(Class<?> clazz, Object[] args) throws NoSuchMethodException, InstantiationException, IllegalArgumentException, IllegalAccessException { if (args.length < 1) { return clazz.newInstance(); } else {/*from w w w.java2 s . co m*/ Class<?>[] paramTypes = new Class[args.length]; for (int i = 0; i < args.length; i++) { paramTypes[i] = args[i].getClass(); } Constructor<?> con = clazz.getConstructor(paramTypes); try { return con.newInstance(args); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; } }
From source file:msi.gama.gui.swt.WorkspaceModelsManager.java
static private IProject createOrUpdateProject(final String name) { final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IProject[] projectHandle = new IProject[] { null }; WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override//from ww w. ja v a 2 s. com protected void execute(final IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating or updating " + name, 2000); IProject project = ws.getRoot().getProject(name); // IProjectDescription desc = null; if (!project.exists()) { // desc = project.getDescription(); // } else { IProjectDescription desc = ws.newProjectDescription(name); project.create(desc, new SubProgressMonitor(monitor, 1000)); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000)); projectHandle[0] = project; setValuesProjectDescription(project, false); } }; try { op.run(null); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return projectHandle[0]; }
From source file:org.openbaton.cli.util.PrintFormat.java
private static String showObject(List<Object> object) throws IllegalAccessException, InvocationTargetException { String result = ""; String firstLine = ""; String secondLine = ""; String[] rowProperty = new String[5000]; String[] rowValue = new String[5000]; int rowCount = 0; String fieldName = ""; String fieldCheck = ""; Field[] fieldBase = object.get(0).getClass().getDeclaredFields(); Field[] fieldSuper = object.get(0).getClass().getSuperclass().getDeclaredFields(); Field[] field = ArrayUtils.addAll(fieldBase, fieldSuper); rowProperty[rowCount] = "| PROPERTY"; rowValue[rowCount] = "| VALUE"; rowCount++;/* w ww . ja v a2 s. c om*/ for (int i = 0; i < field.length; i++) { Method[] methodBase = object.get(0).getClass().getDeclaredMethods(); Method[] methodSuper = object.get(0).getClass().getSuperclass().getDeclaredMethods(); Method[] methods = ArrayUtils.addAll(methodBase, methodSuper); for (int z = 0; z < methods.length; z++) { if (methods[z].getName().equalsIgnoreCase("get" + field[i].getName())) { Object lvlDown = methods[z].invoke(object.get(0)); if (lvlDown != null) try { if (lvlDown instanceof Set || lvlDown instanceof List || lvlDown instanceof Iterable) { Set<Object> objectHash = new HashSet<Object>(); if (methods[z].getName().contains("security") || methods[z].getName().contains("Source") || methods[z].getName().contains("Target")) { objectHash.add(lvlDown); } else { objectHash = (Set<Object>) lvlDown; } for (Object obj : objectHash) { Field[] fieldBase2 = obj.getClass().getDeclaredFields(); Field[] fieldSuper2 = obj.getClass().getSuperclass().getDeclaredFields(); Field[] field2 = ArrayUtils.addAll(fieldBase2, fieldSuper2); String name = ""; String id = ""; for (Field aField2 : field2) { Method[] methodBase2 = obj.getClass().getDeclaredMethods(); Method[] methodSuper2 = obj.getClass().getSuperclass().getDeclaredMethods(); Method[] methods2 = ArrayUtils.addAll(methodBase2, methodSuper2); for (Method aMethods2 : methods2) { if (aMethods2.getName().equalsIgnoreCase("get" + aField2.getName())) { Object lvlDown2 = aMethods2.invoke(obj); if (lvlDown2 != null) try { if (!(lvlDown2 instanceof Set) && !(lvlDown2 instanceof List) && !(lvlDown2 instanceof Iterable)) { if (aMethods2.getName().equalsIgnoreCase("getId")) { id = aMethods2.invoke(obj).toString(); fieldName = field[i].getName(); if (!fieldCheck.equalsIgnoreCase(fieldName)) { rowProperty[rowCount] = "| " + field[i].getName().toUpperCase(); rowValue[rowCount] = "|"; rowCount++; rowProperty[rowCount] = "|"; rowValue[rowCount] = "|"; rowCount++; fieldCheck = fieldName; } } if (aMethods2.getName().equalsIgnoreCase("getName")) { name = aMethods2.invoke(obj).toString(); } } } catch (InvocationTargetException e) { e.printStackTrace(); } } } } if (id.length() > 0 || name.length() > 0) { rowCount--; rowProperty[rowCount] = "|"; if (name.length() > 0) { rowValue[rowCount] = "| id: " + id + " - name: " + name; } else if (id.length() > 0) { rowValue[rowCount] = "| id: " + id; } rowCount++; rowProperty[rowCount] = "|"; rowValue[rowCount] = "|"; rowCount++; } } } else { if (lvlDown instanceof String || lvlDown instanceof Integer || lvlDown instanceof Enum) { rowProperty[rowCount] = "| " + field[i].getName(); rowValue[rowCount] = "| " + lvlDown.toString(); rowCount++; rowProperty[rowCount] = "|"; rowValue[rowCount] = "|"; rowCount++; } } } catch (InvocationTargetException e) { e.printStackTrace(); } } } } addRow("\n"); firstLine = buildLine(rowProperty); secondLine = buildLine(rowValue); addRow(firstLine, secondLine, "+"); for (int c = 0; c < rowCount; c++) { addRow(rowProperty[c], rowValue[c], "|"); if (c == 0) { addRow(firstLine, secondLine, "+"); } } //end addRow(firstLine, secondLine, "+"); result = printer(); return result; }
From source file:Main.java
@SuppressWarnings("unused") public static void unregisterMediaButtonEventReceiverCompat(AudioManager audioManager, ComponentName receiver) { if (sMethodUnregisterMediaButtonEventReceiver == null) return;// www . ja v a 2 s. c o m try { sMethodUnregisterMediaButtonEventReceiver.invoke(audioManager, receiver); } catch (InvocationTargetException e) { // Unpack original exception when possible Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else { // Unexpected checked exception; wrap and re-throw throw new RuntimeException(e); } } catch (IllegalAccessException e) { Log.e(TAG, "IllegalAccessException invoking unregisterMediaButtonEventReceiver."); e.printStackTrace(); } }
From source file:msi.gama.application.workspace.WorkspaceModelsManager.java
static public IProject createOrUpdateProject(final String name) { final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IProject[] projectHandle = new IProject[] { null }; final WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override/*from www .j a va 2 s . c om*/ protected void execute(final IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating or updating " + name, 2000); final IProject project = ws.getRoot().getProject(name); // IProjectDescription desc = null; if (!project.exists()) { // desc = project.getDescription(); // } else { final IProjectDescription desc = ws.newProjectDescription(name); project.create(desc, new SubProgressMonitor(monitor, 1000)); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000)); projectHandle[0] = project; setValuesProjectDescription(project, false, false, null); } }; try { op.run(null); } catch (final InvocationTargetException e) { e.printStackTrace(); } catch (final InterruptedException e) { e.printStackTrace(); } return projectHandle[0]; }
From source file:edu.umass.cs.reconfiguration.AbstractReconfiguratorDB.java
protected static Object autoInvokeMethod(Object target, BasicReconfigurationPacket<?> rcPacket, boolean recovery, Stringifiable<?> unstringer) { try {// ww w. ja v a2 s . c om return target.getClass() .getMethod( ReconfigurationPacket.HANDLER_METHOD_PREFIX + ReconfigurationPacket.getPacketTypeClassName(rcPacket.getType()), ReconfigurationPacket.getPacketTypeClass(rcPacket.getType()), boolean.class) .invoke(target, rcPacket, recovery); } catch (NoSuchMethodException nsme) { nsme.printStackTrace(); } catch (InvocationTargetException ite) { ite.printStackTrace(); } catch (IllegalAccessException iae) { iae.printStackTrace(); } return null; }
From source file:net.tbnr.util.json.JSONChatMessage.java
public void sendToPlayer(Player player) { PacketContainer chat = new PacketContainer(PacketType.Play.Server.CHAT); chat.getChatComponents().write(0, WrappedChatComponent.fromJson(chatObject.toJSONString())); try {//from w w w. ja v a 2 s .c o m ProtocolLibrary.getProtocolManager().sendServerPacket(player, chat); } catch (InvocationTargetException e) { e.printStackTrace(); } }
From source file:org.fs.ghanaian.json.JsonArrayCallback.java
/** * * @param array/* w ww . ja v a 2 s. com*/ * @return */ public T marshall(JSONArray array) { try { Method method = clazz.getMethod("fromJsonArray", JSONArray.class); return (T) method.invoke(null, array); } catch (NoSuchMethodException ne) { ne.printStackTrace(); } catch (IllegalAccessException iea) { iea.printStackTrace(); } catch (InvocationTargetException ite) { ite.printStackTrace(); } return null; }