日期:2014-05-20 浏览次数:20805 次
public class TargetStorage{
private static Map<String , Map<String,List<Object>>> recordClassInfo ;
/***
* 将一个类的方法按照seq拆分,并存储在recordClassInfo中
*/
public static <T> Map<String,List<Object>> storageMethodName(Class<T> tClass , String seq){
Class<T> clz = tClass ;
Method[] methods = clz.getDeclaredMethods() ;
Map<String,List<Object>> record = new HashMap<String, List<Object>>();
for(Method method : methods){
String methodName = method.getName();
String[] info_forMethodName = methodName.split(seq);
ArrayList<Object> infoList = new ArrayList<Object>();
for(String infoPiece : info_forMethodName){
infoList.add(infoPiece);
}
record.put(methodName, infoList);//填充record!
}
recordClassInfo.put(tClass.getName()+"__Method", record);//报错的位置
return recordClassInfo.get(tClass.getName()+"__Method") ;
}
}
public class A {
private final static Map<String,List<Object>> checkManager ;//检测管理器,存放程序规定的按键类型
static{
checkManager = TargetStorage.storageMethodName(A.class, "_");
}
public void Ctrl_W(){
}
public void Ctrl_Q(){
}
public static void main(String[] args) {
A a ;
}
}
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
at test.TargetStorage.storageMethodName(TargetStorage.java:27)
at test.A.<clinit>(A.java:9)
private static Map<String , Map<String,List<Object>>> recordClassInfo ;
private static Map<String , Map<String,List<Object>>> recordClassInfo=new HashMap<String , Map<String,List<Object>>>() ;