小编fre*_*red的帖子

Java反射:代码在调试器中运行良好,但在"正常"运行模式下运行不正常

我正在尝试从方法数组中调用静态方法.这在调试器中工作得很好,但在正常运行模式下不行.这是为什么?

以下代码注释中的更多描述..

编辑以便于再现只需在调试器与普通模式下运行此类:

public class Stackoverflowquestion {

public static class Backautomat {
    private String aktuellBackendeBrotsorte = "Butterbrot";
    //Test für Statische Methoden: Brauche ich dazu auch eine Instanz für Invoke? 
    public static String getBezeichnung(){
        return "Bezeichnung: Bester-Backautomat-Ever";
    }
    //Test für Methoden ohne Parameterliste
    public boolean backautomat_starten(){
        return true;
    }
}

public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    //Get all methods of class
    Method[] backaudomadMethoden = Backautomat.class.getMethods();
    //Get first Method of class -> I know this one is static …
Run Code Online (Sandbox Code Playgroud)

java reflection methods static nullpointerexception

3
推荐指数
1
解决办法
463
查看次数

标签 统计

java ×1

methods ×1

nullpointerexception ×1

reflection ×1

static ×1