Example usage for java.lang NoSuchMethodException printStackTrace

List of usage examples for java.lang NoSuchMethodException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:org.kuali.kra.budget.calculator.QueryList.java

/**
 * sorts the QueryList by the fieldName in ascending or descending order.
 * Note: the field Object should be of Comparable type.
 * @return boolean indicating whether the sort is completed successfully or not.
 * @param ignoreCase use only when comparing strings. as default implementation uses case sensitive comparison.
 * @param fieldName field which is used to sort the bean.
 * @param ascending if true sorting is done in ascending order,
 * else sorting is done in descending order.
 *///from   www  .jav a 2s.  c  o m
@SuppressWarnings("rawtypes")
public boolean sort(String fieldName, boolean ascending, boolean ignoreCase) {
    Object current, next;
    int compareValue = 0;
    Field field = null;
    Method method = null;
    if (this.size() == 0) {
        return false;
    }
    Class dataClass = get(0).getClass();
    String methodName = null;
    try {
        field = dataClass.getDeclaredField(fieldName);
        if (!field.isAccessible()) {
            throw new NoSuchFieldException();
        }
    } catch (NoSuchFieldException noSuchFieldException) {
        //field not available. Use method invokation.
        try {
            methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
            method = dataClass.getMethod(methodName, null);
        } catch (NoSuchMethodException noSuchMethodException) {
            noSuchMethodException.printStackTrace();
            return false;
        }
    }

    for (int index = 0; index < size() - 1; index++) {
        for (int nextIndex = index + 1; nextIndex < size(); nextIndex++) {
            current = get(index);
            next = get(nextIndex);
            //Check if current and next implements Comparable else can't compare.
            //so return without comparing.May be we can have an exception for this purpose.
            try {
                if (field != null && field.isAccessible()) {
                    Comparable thisObj = (Comparable) field.get(current);
                    Comparable otherObj = (Comparable) field.get(next);
                    if (thisObj == null) {
                        compareValue = -1;
                    } else if (otherObj == null) {
                        compareValue = 1;
                    } else {
                        if (thisObj instanceof String && ignoreCase) {
                            compareValue = ((String) thisObj).compareToIgnoreCase((String) otherObj);
                        } else {
                            compareValue = thisObj.compareTo(otherObj);
                        }
                    }
                } else {
                    Comparable thisObj = null;
                    Comparable otherObj = null;
                    if (methodName != null) {
                        Method thisObjMethod = current.getClass().getMethod(methodName, null);
                        Method otherObjMethod = next.getClass().getMethod(methodName, null);
                        thisObj = (Comparable) thisObjMethod.invoke(current, null);
                        otherObj = (Comparable) otherObjMethod.invoke(next, null);
                    } else {
                        thisObj = (Comparable) method.invoke(current, null);
                        otherObj = (Comparable) method.invoke(next, null);
                    }
                    if (thisObj == null) {
                        compareValue = -1;
                    } else if (otherObj == null) {
                        compareValue = 1;
                    } else {
                        if (thisObj instanceof String && ignoreCase) {
                            compareValue = ((String) thisObj).compareToIgnoreCase((String) otherObj);
                        } else {
                            compareValue = thisObj.compareTo(otherObj);
                        }
                    }
                }
            } catch (IllegalAccessException illegalAccessException) {
                LOG.warn(illegalAccessException.getMessage());
                return false;
            } catch (InvocationTargetException invocationTargetException) {
                LOG.warn(invocationTargetException.getMessage(), invocationTargetException);
                return false;
            } catch (SecurityException e) {
                LOG.warn(e.getMessage(), e);
                return false;
            } catch (NoSuchMethodException e) {
                LOG.warn(e.getMessage(), e);
                return false;
            }

            if (ascending && compareValue > 0) {
                E temp = get(index);
                set(index, get(nextIndex));
                set(nextIndex, temp);
            } else if (!ascending && compareValue < 0) {
                E temp = get(index);
                set(index, get(nextIndex));
                set(nextIndex, temp);
            }

        }
    }
    return true;
}

From source file:edu.ku.brc.specify.datamodel.DataModelObjBase.java

/**
 * Sets a value into the current object.
 * @param clazz the class of the data being set
 * @param ref the value/*  ww w . ja va 2 s. c  o m*/
 * @return true on success
 */
public static boolean setDataMember(final FormDataObjIFace dataObject, final String fieldName,
        final FormDataObjIFace ref) {
    String methodName = "";
    try {
        methodName = "set" + StringUtils.capitalize(fieldName);
        //System.out.println(dataObject.getClass().getSimpleName()+"."+methodName+"("+clazz.getSimpleName()+")");
        Method method = dataObject.getClass().getMethod(methodName, ref.getDataClass());
        if (method != null) {
            method.invoke(dataObject, ref);
            return true;
        }

    } catch (java.lang.NoSuchMethodException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex);
        log.error("Couldn't find method [" + methodName + "] on Class ["
                + dataObject.getDataClass().getSimpleName() + "] for arg[" + ref.getDataClass() + "]");
        log.error("For Class " + dataObject.getClass().getSimpleName());
        for (Method m : dataObject.getClass().getMethods()) {
            String mName = m.getName();
            if (mName.startsWith("set")) {
                log.error(mName + " " + mName.equals(methodName));
            }
        }
        ex.printStackTrace();

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex);
        ex.printStackTrace();

    }
    return false;
}

From source file:com.dtolabs.rundeck.ExpandRunServer.java

private void execute(final String[] args, final File configDir, final File baseDir, final File serverDir,
        final Properties configuration) throws IOException {
    //set some system properties used by the RunServer class
    System.setProperty("server.http.port", configuration.getProperty("server.http.port"));
    System.setProperty(RUNDECK_SERVER_CONFIG_DIR, configDir.getAbsolutePath());
    System.setProperty("rundeck.server.serverDir", serverDir.getAbsolutePath());
    System.setProperty("rundeck.config.location",
            new File(configDir, configuration.getProperty("rundeck.config.name")).getAbsolutePath());
    if (useJaas) {
        System.setProperty("java.security.auth.login.config",
                new File(configDir, configuration.getProperty("loginmodule.conf.name")).getAbsolutePath());
        System.setProperty(PROP_LOGINMODULE_NAME, configuration.getProperty(PROP_LOGINMODULE_NAME));
    }/* w ww  . j av  a2 s.c o m*/

    //configure commandline arguments
    final ArrayList<String> execargs = new ArrayList<String>();
    execargs.add(baseDir.getAbsolutePath());
    if (args.length > 1) {
        execargs.addAll(Arrays.asList(Arrays.copyOfRange(args.clone(), 1, args.length)));
    }

    //execute the RunServer.main method
    int result = 500;
    try {
        invokeMain(runClassName, execargs.toArray(new String[execargs.size()]), new File(serverdir, "lib"));
        result = 0;//success
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    DEBUG("Finished, exit code: " + result);
    System.exit(result);
}

From source file:org.durka.hallmonitor.CoreStateManager.java

public void registerCoreService(CoreService mService) {
    mCoreService = mService;/*www.ja  v a2s.c o m*/
    try {
        startCoreServiceAsUser = ((ContextWrapper) mCoreService).getClass().getMethod("startServiceAsUser",
                Intent.class, UserHandle.class);
        Log.d(LOG_TAG, "CoreService registred");
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}

From source file:com.spark.percent.PercentLayoutHelper.java

private void supportMinOrMaxDimesion(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
    try {/*from w  w  w .  ja  v a2  s .  co  m*/
        Class<?> clazz = view.getClass();
        invokeMethod("setMaxWidth", widthHint, heightHint, view, clazz, info.maxWidthPercent);
        invokeMethod("setMaxHeight", widthHint, heightHint, view, clazz, info.maxHeightPercent);
        invokeMethod("setMinWidth", widthHint, heightHint, view, clazz, info.minWidthPercent);
        invokeMethod("setMinHeight", widthHint, heightHint, view, clazz, info.minHeightPercent);

    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

}

From source file:android.percent.support.PercentLayoutHelper.java

private void supportMinOrMaxDimesion(int widthHint, int heightHint, View view, PercentLayoutInfo info) {
    try {//from   w  w  w .  j  a v  a2 s.c o  m
        Class clazz = view.getClass();
        invokeMethod("setMaxWidth", widthHint, heightHint, view, clazz, info.maxWidthPercent);
        invokeMethod("setMaxHeight", widthHint, heightHint, view, clazz, info.maxHeightPercent);
        invokeMethod("setMinWidth", widthHint, heightHint, view, clazz, info.minWidthPercent);
        invokeMethod("setMinHeight", widthHint, heightHint, view, clazz, info.minHeightPercent);

    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

}

From source file:com.lewa.crazychapter11.MainActivity.java

public static void checkMethod() {
    try {/*from   w  w  w . j a  v a  2  s  .co m*/
        Method function = null;
        Class mainActivity = Class.forName("com.lewa.crazychapter11.MainActivity");
        function = mainActivity.getMethod("methodForCheck", String.class);
        String temp_str = "guoguo come here";
        Log.i("algerhecheck", "function ====== " + function.invoke(null, temp_str));

    } catch (NoSuchMethodException e) {
        Log.i("algerhecheck", "NoSuchMethodException ====== ");
    } catch (ClassNotFoundException e) {
        Log.i("algerhecheck", "ClassNotFoundException ########### ");
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    //*/   ////getExternalFilesDirs
    try {
        Class<?> ContextCompat = Class.forName("android.support.v4.content.ContextCompat");
        Method checkSelfPermission = ContextCompat.getMethod("checkSelfPermission", Context.class,
                String.class);
        Log.d("algerheReflect", "checkSelfPermission=" + checkSelfPermission);
    } catch (Exception e) {
        Log.i("algerheReflect", "NoSuchMethodException ====== 111111");
    }

    try {
        Class<?> ContextCompat = Class.forName("android.support.v4.content.ContextCompat");
        Method getExternalFilesDirs = ContextCompat.getMethod("getExternalFilesDirs", Context.class,
                String.class);
        Log.d("algerheReflect", "getExternalFilesDirs=" + getExternalFilesDirs);
    } catch (Exception e) {
        Log.i("algerheReflect", "NoSuchMethodException ====== 222222");
    }

    //*/         

    // TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); 
    //       String imei1 = tm.getDeviceId(0);
    //       String imei2 = tm.getDeviceId(1);

    //       String imsi1 = "";
    //       String imsi2 = "";

    //    try {
    //           Class telephonyManager = Class.forName("android.telephony.TelephonyManager");
    //           Method getSubscriberId;
    //           if (Build.VERSION.SDK_INT == 21) {
    //               getSubscriberId = telephonyManager.getMethod("getSubscriberId", new Class[]{long.class});
    //               imsi1 = (String) getSubscriberId.invoke(tm, new Object[]{SubscriptionManager.getSubId(0)[0]});
    //               imsi2 = (String) getSubscriberId.invoke(tm, new Object[]{SubscriptionManager.getSubId(1)[0]});
    //           } else {
    //               getSubscriberId = telephonyManager.getMethod("getSubscriberId", new Class[]{int.class});
    //               int subId1 = (int)SubscriptionManager.getSubId(0)[0];
    //               int subId2 = (int)SubscriptionManager.getSubId(1)[0];
    //               imsi1 = (String) getSubscriberId.invoke(tm, new Object[]{subId1});
    //               imsi2 = (String) getSubscriberId.invoke(tm, new Object[]{subId2});
    //           }

    //           Log.i("algerhecheck","imsi1="+imsi1+"\n imsi2="+imsi2);
    // } catch (ClassNotFoundException e) {
    //     e.printStackTrace();
    // } catch (NoSuchMethodException e) {
    //     e.printStackTrace();
    // } catch (InvocationTargetException e) {
    //     e.printStackTrace();
    // } catch (IllegalAccessException e) {
    //     e.printStackTrace();
    // }
}

From source file:io.github.meness.easyintro.EasyIntroCarouselFragment.java

private void setViewPagerToPageIndicator() {
    try {/*  w  ww  . j  a v a  2s. c om*/
        View view = mIndicatorsContainer.findViewById(R.id.pageIndicator);
        // invoke indicator `setViewPager(ViewPager)` method
        view.getClass().getMethod("setViewPager", ViewPager.class).invoke(view, mPager);
    } catch (NoSuchMethodException e) {
        Log.e(EasyIntro.TAG, getString(R.string.exception_no_such_method_set_view_pager));
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        Log.e(EasyIntro.TAG, getString(R.string.exception_invocation_target_set_view_pager));
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        Log.e(EasyIntro.TAG, getString(R.string.exception_illegal_access_set_view_pager));
        e.printStackTrace();
    }
}

From source file:com.gome.haoyuangong.views.SwipeRefreshLayout.java

private void removeViewTapCallback(View v) {
    try {/*from   w w w .  j  a  v a2  s  .  c o m*/
        Method m = View.class.getDeclaredMethod("removeTapCallback");
        m.setAccessible(true);
        m.invoke(v);
        System.out.println(m);
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 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();
    }
}

From source file:com.aliyun.odps.mapred.conf.JobConf.java

/**
 * label//from   w  w w. jav  a 2  s  .co m
 *
 * @param schema
 *     
 * @param label
 *     
 */
@Deprecated
public void setOutputSchema(Column[] schema, String label) {
    try {
        onDeprecated(JobConf.class.getMethod("setOutputSchema", Column[].class, String.class));
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
}