List of usage examples for java.lang NoSuchMethodException printStackTrace
public void printStackTrace()
From source file:request.processing.ServletLoader.java
public static void loadServlet(String servletDir) { try {//from w ww . java 2 s . c om JarFile jarFile = new JarFile(servletDir); Enumeration<JarEntry> e = jarFile.entries(); URL[] urls = { new URL("jar:file:" + servletDir + "!/") }; URLClassLoader cl = URLClassLoader.newInstance(urls); while (e.hasMoreElements()) { try { JarEntry je = (JarEntry) e.nextElement(); if (je.isDirectory() || !je.getName().endsWith(".class")) { continue; } String className = je.getName().substring(0, je.getName().length() - 6); className = className.replace('/', '.'); Class c = cl.loadClass(className); if (Servlet.class.isAssignableFrom(c)) { Constructor<Servlet> constructor = c.getConstructor(); Servlet i = constructor.newInstance(); namesToServlets.put(c.getSimpleName(), i); } else { continue; } } catch (ClassNotFoundException cnfe) { System.err.println("Class not found"); cnfe.printStackTrace(); } catch (NoSuchMethodException e1) { System.err.println("No such method"); e1.printStackTrace(); } catch (SecurityException e1) { System.err.println("Security Exception"); e1.printStackTrace(); } catch (InstantiationException e1) { System.err.println("Instantiation Exception"); e1.printStackTrace(); } catch (IllegalAccessException e1) { System.err.println("IllegalAccessException"); e1.printStackTrace(); } catch (IllegalArgumentException e1) { System.err.println("IllegalArgumentException"); e1.printStackTrace(); } catch (InvocationTargetException e1) { System.err.println("InvocationTargetException"); e1.printStackTrace(); } } jarFile.close(); } catch (IOException e) { System.err.println("Not a jarFile, no biggie. Moving on."); } }
From source file:info.aamulumi.sharedshopping.APIConnection.java
/** * Send a GET request and create a list with returned JSON datas. * The JSONObject returned by server must have : * - success : int - 1 if request is successful * - data : JSONArray - contains datas which will be parsed * * @param url - url to access * @param parseMethod - name of the method used to parse an object in data * @param urlParameters - parameters send in URL * @param bodyParameters - parameters send in body (encoded) * @return the list of parsed elements/*from w ww . j ava2 s. c o m*/ */ private static <T> ArrayList<T> getItems(String url, String parseMethod, HashMap<String, String> urlParameters, HashMap<String, String> bodyParameters) { ArrayList<T> list = new ArrayList<>(); // Get parseMethod Class<?>[] cArg = new Class[1]; cArg[0] = JSONObject.class; Method parse; try { parse = APIConnection.class.getMethod(parseMethod, cArg); } catch (NoSuchMethodException e1) { e1.printStackTrace(); return null; } // Do the request JSONObject json = makeHttpRequest(url, GET, urlParameters, bodyParameters); if (json == null) return null; try { int success = json.getInt("success"); // Parse if successful if (success == 1) { JSONArray data = json.getJSONArray("data"); for (int i = 0; i < data.length(); i++) { @SuppressWarnings("unchecked") T tmp = (T) parse.invoke(APIConnection.class, data.getJSONObject(i)); list.add(tmp); } } } catch (Exception e) { e.printStackTrace(); return null; } return list; }
From source file:org.zywx.wbpalmstar.plugin.uexiconlist.utils.IconListUtils.java
/** * ???//from w w w.j a v a2 s . c om * * @param className * ?? * @param methodName * ?? * @param parmTypeList * ? * @return */ public static Method getReflectionMethod(String className, String methodName, Class<?>[] parmTypeList) { Method mMethod = null; try { Class<?> mClass = Class.forName(className); try { /** ?methodName, parmList?public?public */ mMethod = mClass.getDeclaredMethod(methodName, parmTypeList); mMethod.setAccessible(true); } catch (NoSuchMethodException e) { e.printStackTrace(); } } catch (ClassNotFoundException e) { e.printStackTrace(); } return mMethod; }
From source file:org.jbpm.bpel.graph.exe.MockIntegrationService.java
private static String getIdString(Object objectWithId) { Class classWithId = objectWithId.getClass(); // get the class name excluding the package String className = ClassUtils.getShortClassName(classWithId); // obtain the identifier getter method according to jBPM conventions String idString = "0"; try {//w w w . j av a2 s. c om Method idGetter = classWithId.getMethod("getId", null); idGetter.setAccessible(true); Long idWrapper = (Long) idGetter.invoke(objectWithId, null); long id = idWrapper.longValue(); if (id != 0L) { idString = Long.toHexString(id); } else { // object is transient, fall back to hash code idString = Integer.toHexString(objectWithId.hashCode()); } } catch (NoSuchMethodException e) { // no id getter, fall back to hash code idString = Integer.toHexString(objectWithId.hashCode()); } catch (IllegalAccessException e) { // we made the getter accessible, should not happen e.printStackTrace(); } catch (InvocationTargetException e) { // strange a getter throws a checked exception e.printStackTrace(); } return className + idString; }
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 {//ww w. j a va 2s . com 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:edu.umass.cs.reconfiguration.reconfigurationpackets.ReconfigurationPacket.java
public static void assertPacketTypeChecks(ReconfigurationPacket.PacketType type, String packetName, Class<?> target, String handlerMethodPrefix) { String errMsg = "Method " + handlerMethodPrefix + packetName + " does not exist in " + target.getSimpleName();/*w w w . j ava 2 s. c o m*/ try { // System.out.println(type + " : " + packetName + " : " + // handlerMethodPrefix+packetName); if (packetName != null) assert (target.getMethod(handlerMethodPrefix + packetName, getPacketTypeClass(type), ProtocolTask[].class) != null) : errMsg; } catch (NoSuchMethodException nsme) { System.err.println(errMsg); nsme.printStackTrace(); } }
From source file:me.piebridge.android.preference.PreferenceFragment.java
public static void callVoidMethod(Object receiver, String methodName, Class<?>[] parameterTypes, Object[] args) {/*from w w w . j ava 2 s. com*/ try { Method method = receiver.getClass().getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); method.invoke(receiver, args); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } }
From source file:me.piebridge.android.preference.PreferenceFragment.java
@SuppressWarnings("unchecked") public static <T> T callConstructor(Class<T> returnType, Class<?>[] parameterTypes, Object[] args) { try {//from w ww . ja v a 2s . c o m Constructor<?> constructor = returnType.getDeclaredConstructor(parameterTypes); constructor.setAccessible(true); return (T) constructor.newInstance(args); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (java.lang.InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; }
From source file:me.piebridge.android.preference.PreferenceFragment.java
@SuppressWarnings("unchecked") public static <T> T callReturnMethod(Object receiver, String methodName, Class<T> returnType, Class<?>[] parameterTypes, Object[] args) { try {/*from w w w. j a v a2s . c o m*/ Method method = receiver.getClass().getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return (T) method.invoke(receiver, args); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } if (Boolean.class.equals(returnType)) { return (T) Boolean.FALSE; } return null; }
From source file:com.demo.wondersdaili.mvp.utils.ThemeUtils.java
private static void refreshView(View view, ExtraRefreshable extraRefreshable) { if (view == null) return;//w w w. j a v a 2 s . c o m view.destroyDrawingCache(); if (view instanceof Tintable) { ((Tintable) view).tint(); if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable); } } } else { if (extraRefreshable != null) { extraRefreshable.refreshSpecificView(view); } if (view instanceof AbsListView) { ListAdapter adapter = ((AbsListView) view).getAdapter(); while (adapter instanceof WrapperListAdapter) { adapter = ((WrapperListAdapter) adapter).getWrappedAdapter(); } if (adapter instanceof BaseAdapter) { ((BaseAdapter) adapter).notifyDataSetChanged(); } } if (view instanceof RecyclerView) { try { if (mRecycler == null) { mRecycler = RecyclerView.class.getDeclaredField("mRecycler"); mRecycler.setAccessible(true); } if (mClearMethod == null) { mClearMethod = Class.forName("android.support.v7.widget.RecyclerView$Recycler") .getDeclaredMethod("clear"); mClearMethod.setAccessible(true); } mClearMethod.invoke(mRecycler.get(view)); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } ((RecyclerView) view).getRecycledViewPool().clear(); ((RecyclerView) view).invalidateItemDecorations(); } if (view instanceof ViewGroup) { for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable); } } } }