Example usage for java.lang NoSuchFieldException printStackTrace

List of usage examples for java.lang NoSuchFieldException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:szjy.advtech.BuildInfo.java

/**
 * Get field from Class//from   w ww.j a  va 2  s . co  m
 * @param c
 * @param fieldName
  * @return
  */
private static Field getClassField(Class c, String fieldName) {
    Field field = null;

    try {
        field = c.getField(fieldName);
    } catch (NoSuchFieldException nsfe) {
        nsfe.printStackTrace();
    }

    return field;
}

From source file:com.jiubai.taskmoment.widget.MyLinearLayoutManager.java

private static void makeInsetsDirty(RecyclerView.LayoutParams p) {
    if (!canMakeInsetsDirty) {
        return;/*w w w .java  2  s. co m*/
    }

    if (insetsDirtyField == null) {
        try {
            insetsDirtyField = RecyclerView.LayoutParams.class.getDeclaredField("mInsetsDirty");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        insetsDirtyField.setAccessible(true);
    }
    try {
        insetsDirtyField.set(p, true);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

}

From source file:net.dv8tion.jda.utils.DebugUtil.java

public static JSONObject fromJDA(JDA iJDA, boolean includeUsers, boolean includeGuilds,
        boolean includeGuildUsers, boolean includeChannels, boolean includePrivateChannels) {
    JDAImpl jda = (JDAImpl) iJDA;//  w ww. j a v a 2s .c o  m
    JSONObject obj = new JSONObject();
    obj.put("self_info", fromUser(jda.getSelfInfo()))
            .put("proxy",
                    jda.getGlobalProxy() == null ? JSONObject.NULL
                            : new JSONObject().put("host", jda.getGlobalProxy().getHostName()).put("port",
                                    jda.getGlobalProxy().getPort()))
            .put("response_total", jda.getResponseTotal()).put("audio_enabled", jda.isAudioEnabled())
            .put("auto_reconnect", jda.isAutoReconnect());

    JSONArray array = new JSONArray();
    for (Object listener : jda.getRegisteredListeners())
        array.put(listener.getClass().getCanonicalName());
    obj.put("event_listeners", array);

    try {
        Field f = EntityBuilder.class.getDeclaredField("cachedJdaGuildJsons");
        f.setAccessible(true);
        HashMap<String, JSONObject> cachedJsons = ((HashMap<JDA, HashMap<String, JSONObject>>) f.get(null))
                .get(jda);

        array = new JSONArray();
        for (String guildId : cachedJsons.keySet())
            array.put(guildId);
        obj.put("second_pass_json_guild_ids", array);

        f = EntityBuilder.class.getDeclaredField("cachedJdaGuildCallbacks");
        f.setAccessible(true);
        HashMap<String, Consumer<Guild>> cachedCallbacks = ((HashMap<JDA, HashMap<String, Consumer<Guild>>>) f
                .get(null)).get(jda);

        array = new JSONArray();
        for (String guildId : cachedCallbacks.keySet())
            array.put(guildId);
        obj.put("second_pass_callback_guild_ids", array);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    if (includeGuilds) {
        array = new JSONArray();
        for (Guild guild : jda.getGuilds())
            array.put(fromGuild(guild, includeGuildUsers, includeChannels, true, true));
        obj.put("guilds", array);
    }

    if (includePrivateChannels) {
        array = new JSONArray();
        for (PrivateChannel chan : jda.getPrivateChannels())
            array.put(fromPrivateChannel(chan, false));
        obj.put("private_channels", array);

        array = new JSONArray();
        for (Map.Entry<String, String> entry : jda.getOffline_pms().entrySet()) {
            array.put(new JSONObject().put("id", entry.getValue()).put("user_id", entry.getKey()));
        }
        obj.put("offline_private_channels", array);
    }

    if (includeUsers) {
        array = new JSONArray();
        for (User user : jda.getUsers())
            array.put(fromUser(user));
        obj.put("users", array);
    }

    return obj;
}

From source file:com.aw.support.reflection.MethodInvoker.java

public static Field getAttribute(Object target, String fielName) {
    Class cls = target.getClass();
    Field field = null;//w ww.j a va 2 s. c  o  m
    try {
        field = cls.getField(fielName);
    } catch (NoSuchFieldException e) {
        field = null;
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    return field;
}

From source file:de.beyondjava.angularFaces.core.ELTools.java

private static Field getField(String p_expression) {
    synchronized (fields) {
        if (fields.containsKey(p_expression)) {
            return fields.get(p_expression);
        }//  w  w  w  . ja  v a 2 s  .c o m
    }

    if (p_expression.startsWith("#{") && p_expression.endsWith("}")) {
        int delimiterPos = p_expression.lastIndexOf('.');
        if (delimiterPos < 0) {
            LOGGER.log(Level.WARNING, "There's no field to access: #{" + p_expression + "}");
            return null;
        }
        String beanExp = p_expression.substring(0, delimiterPos) + "}";
        String fieldName = p_expression.substring(delimiterPos + 1, p_expression.length() - 1);
        Object container = evalAsObject(beanExp);
        if (null == container) {
            LOGGER.severe("Can't read the bean '" + beanExp
                    + "'. Thus JSR 303 annotations can't be read, let alone used by the AngularDart client.");
            return null;
        }

        Class<? extends Object> c = container.getClass();
        while (c != null) {
            Field declaredField;
            try {
                declaredField = c.getDeclaredField(fieldName);
                synchronized (fields) {
                    fields.put(p_expression, declaredField);
                }
                return declaredField;
            } catch (NoSuchFieldException e) {
                // let\"s try with the super class
                c = c.getSuperclass();
            } catch (SecurityException e) {
                LOGGER.log(Level.SEVERE, "Unable to access a field", e);
                e.printStackTrace();
                return null;
            }
        }
    }
    return null;
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

private static void refreshView(View view, ExtraRefreshable extraRefreshable) {
    if (view == null)
        return;//from w  ww.ja  va  2  s.  co 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) {
            try {
                if (sRecyclerBin == null) {
                    sRecyclerBin = AbsListView.class.getDeclaredField("mRecycler");
                    sRecyclerBin.setAccessible(true);
                }
                if (sListViewClearMethod == null) {
                    sListViewClearMethod = Class.forName("android.widget.AbsListView$RecycleBin")
                            .getDeclaredMethod("clear");
                    sListViewClearMethod.setAccessible(true);
                }
                sListViewClearMethod.invoke(sRecyclerBin.get(view));
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            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 (sRecycler == null) {
                    sRecycler = RecyclerView.class.getDeclaredField("mRecycler");
                    sRecycler.setAccessible(true);
                }
                if (sRecycleViewClearMethod == null) {
                    sRecycleViewClearMethod = Class.forName("android.support.v7.widget.RecyclerView$Recycler")
                            .getDeclaredMethod("clear");
                    sRecycleViewClearMethod.setAccessible(true);
                }
                sRecycleViewClearMethod.invoke(sRecycler.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);
            }
        }
    }
}

From source file:com.plusub.lib.annotate.JsonParserUtils.java

/**
 * ?JSONobjEntity//from   w w w .  ja  va 2s .  co  m
 * <p>Title: initEntityParser
 * <p>Description: 
 * @param className ?
 * @param jsonString JSON
 * @param isParserList ?className?@JsonParserClass
 * @throws Exception
 */
public static Object initEntityParser(Class className, String jsonString, boolean isParserList)
        throws Exception {
    JSONObject jo = new JSONObject(jsonString);
    Object obj = getInstance(className.getName());

    JsonParserClass jsonClass = obj.getClass().getAnnotation(JsonParserClass.class);
    String rootKey = "";
    boolean isHasPage = false;
    String pageKey = "";
    if (jsonClass != null) {
        rootKey = jsonClass.parserRoot();
        isHasPage = jsonClass.isHasPage();
        pageKey = jsonClass.pageFieldStr();
    }
    Object result = null;

    if (!isParserList) {
        if (isEmpty(rootKey)) {
            result = parserField(obj, jo);
        } else {
            JSONObject json = JSONUtils.getJSONObject(jo, rootKey, null);
            if (json != null) {
                result = parserField(obj, json);
            }
        }
    } else {
        Object pageObj = null;
        //?page
        if (isHasPage) {
            Field field;
            try {
                field = obj.getClass().getDeclaredField(pageKey);
                JsonParserField jsonField = field.getAnnotation(JsonParserField.class);
                String key = jsonField.praserKey();
                if (isEmpty(key)) {
                    key = field.getName();
                }
                JSONObject pageJO = JSONUtils.getJSONObject(jo, key, null);
                if (pageJO != null) {
                    pageObj = getPageInfo(pageJO, field);
                    setFieldValue(obj, field, pageObj);
                }
            } catch (NoSuchFieldException e) {
                // TODO Auto-generated catch block
                if (showLog) {
                    Logger.e("JsonParserUtils", "Field" + pageKey);
                    e.printStackTrace();
                }
            }
        }

        //?
        JSONArray ja = JSONUtils.getJSONArray(jo, rootKey, null);
        if (ja != null && ja.length() > 0) {
            int size = ja.length();
            Object[] data = new Object[size];
            //?
            for (int index = 0; index < size; index++) {
                Object oj = parserField(getInstance(className.getName()), ja.getJSONObject(index));

                //page?
                if (isHasPage && pageObj != null) {
                    try {
                        setFieldValue(oj, oj.getClass().getDeclaredField(pageKey), pageObj);
                    } catch (NoSuchFieldException e) {
                        // TODO Auto-generated catch block
                        if (showLog) {
                            e.printStackTrace();
                        }
                    }
                }

                data[index] = oj;
            }
            result = Arrays.asList(data);
        } else {
            if (showLog) {
                Logger.i(TAG, "JSONArray is Empty " + rootKey);
            }
        }
    }

    return result;
}

From source file:com.genentech.chemistry.tool.sdfAggregator.SDFAggregator.java

/**
 * Generates help string of all aggregator functions
 *
 *///from   w w w  .j a  v a  2s  .  c o m
private static String getAggregationFunctionDescriptions() {
    StringBuilder sb = new StringBuilder(2000);
    String desc = "";

    for (String funcName : functionArr) {
        try {
            desc = (String) Class.forName(PACKAGEName + "." + funcName).getField("DESCRIPTION").get(null);
        } catch (NoSuchFieldException e) {
            System.err.println(e.getMessage());
            System.err.printf("Aggregation function %s does not implement DESCRIPION", funcName);
            exitWithHelp(options);
        } catch (IllegalAccessException e) {
            System.err.println(e.getMessage());
            System.err.println("Function does not exist: " + funcName);
            exitWithHelp(options);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.err.println(e.getMessage());
            System.err.println("Function does not exist: " + funcName);
            exitWithHelp(options);
        }

        sb.append(desc);
    }
    return sb.toString();
}

From source file:br.com.cybereagle.androidtestlibrary.shadow.ShadowAsyncTaskLoader.java

private void updateLastLoadCompleteTimeField() {
    try {//w w  w .ja  v  a 2s .c  o  m
        Field mLastLoadCompleteTimeField = AsyncTaskLoader.class.getDeclaredField("mLastLoadCompleteTimeField");
        if (!mLastLoadCompleteTimeField.isAccessible()) {
            mLastLoadCompleteTimeField.setAccessible(true);
        }
        mLastLoadCompleteTimeField.set(asyncTaskLoader, SystemClock.uptimeMillis());

    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.grottworkshop.gwsspringindicator.ScrollerViewPager.java

public void fixScrollSpeed() {
    try {//  w  w w.j  a va2 s . co m
        fixScrollSpeed(duration);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
}