- 浏览: 1971871 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (509)
- JavaEE (122)
- Oracle数据库 (29)
- JavaScript (37)
- SAP (5)
- MySql数据库 (7)
- JavaSE (4)
- Ajax (1)
- jQuery (13)
- SSH框架 (36)
- Web Service (10)
- JSF框架 (2)
- JBPM (0)
- ireport报表 (2)
- ibatis (5)
- Hibernate (31)
- JSP (11)
- Tomcat 服务器 (20)
- Other (19)
- JavaWeb (4)
- Maven (11)
- OSWorkFlow (10)
- HTML (13)
- Exception汇总 (7)
- SVN (2)
- 笑话 (1)
- JSTL (1)
- WebSphere Message Broker (13)
- ANT命令 (3)
- Liunx (12)
- Struts2 (26)
- Eclipse (6)
- DOS (3)
- Flex (11)
- WebSphere (1)
- 开发常用工具 (3)
- Junit (2)
- EJB (4)
- Struts1.2 (2)
- Jboss (1)
- Android (2)
- Java框架源码解析 (1)
- Spring (4)
- MyBatis (6)
- SpringMVC (4)
- Jetty (2)
- 数据库表设计 (1)
- SSO (4)
最新评论
-
贝塔ZQ:
也可以试试PageOffice插件,觉得更简单点
Jxl操作Excel设置背景、字体颜色、对齐方式、列的宽度 -
jia1208:
...
Could not publish server configuration for Tomcat v6.0 Server at localhost. -
u011274527:
赞
java.io.EOFException java.io.ObjectInputStream$PeekInputStream.readFully 错误 -
旭旭小牛啦:
怎么没哟了,继续赛
jQuery 选择器 -
wzw3919:
100行会报空指针
Java 解压缩zip文件
在使用反射执行一个方法时常遇到object is not an instance of declaring class的异常,如下代码:view plaincopy to clipboardprint? import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Date; import cn.rdt.famework.frame.config.FrameConstant; public class PrimaryKeyUtils { // public synchronized String getPrimaryKey() { String pk = ""; StringBuffer primaryKey = new StringBuffer(new SimpleDateFormat( "yyMMddHHmmssSSS").format(new Date())); int tpk = FrameConstant.PRIMARY_KEY; if (tpk < 9999) { tpk++; } else { tpk = 1000; } FrameConstant.PRIMARY_KEY = tpk; pk = primaryKey.append(String.valueOf(tpk)).toString(); primaryKey = null; return pk; } public String GetPrimaryKey(String mothed){ String primaryKey = ""; try { Class c = PrimaryKeyUtils.class; Method m = c.getMethod(mothed,new Class[]{}); // Object obj=c.newInstance(); m.invoke(mothed,null); primaryKey = String.valueOf(m.invoke(c.newInstance() ,new Object[]{})); } catch (Exception e) { e.printStackTrace(); } return primaryKey; } public static void main(String[] args) { PrimaryKeyUtils primaryKey = new PrimaryKeyUtils(); System.out.println(primaryKey.GetPrimaryKey("getPrimaryKey")); } } import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Date; import cn.rdt.famework.frame.config.FrameConstant; public class PrimaryKeyUtils { // public synchronized String getPrimaryKey() { String pk = ""; StringBuffer primaryKey = new StringBuffer(new SimpleDateFormat( "yyMMddHHmmssSSS").format(new Date())); int tpk = FrameConstant.PRIMARY_KEY; if (tpk < 9999) { tpk++; } else { tpk = 1000; } FrameConstant.PRIMARY_KEY = tpk; pk = primaryKey.append(String.valueOf(tpk)).toString(); primaryKey = null; return pk; } public String GetPrimaryKey(String mothed){ String primaryKey = ""; try { Class c = PrimaryKeyUtils.class; Method m = c.getMethod(mothed,new Class[]{}); // Object obj=c.newInstance(); m.invoke(mothed,null); primaryKey = String.valueOf(m.invoke(c.newInstance() ,new Object[]{})); } catch (Exception e) { e.printStackTrace(); } return primaryKey; } public static void main(String[] args) { PrimaryKeyUtils primaryKey = new PrimaryKeyUtils(); System.out.println(primaryKey.GetPrimaryKey("getPrimaryKey")); } } 第34行会报object is not an instance of declaring class错 对象不是声明类的一个实例。解决办法如下: 第一种:反射执行的方法 getPrimaryKey() 改成静态的 第二种:在执行方法前先实例化类。m.invoke(mothed,null)改为m.invoke(c.newInstance(),null)或者m.invoke(new PrimaryKeyUtils(),null) 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yeson6/archive/2011/01/14/6138963.aspx
发表评论
-
解决Java服务器端插入数据到Mysql中乱码问题--简单几步轻松解决乱码问题
2015-11-13 17:52 2388当写入数据到mysql数据库中发生乱码时.请检查以下几个地 ... -
设计模式之-代理模式-Proxy
2015-04-28 21:24 838使用代理模式之前需要知道代理模式能做什么? 能有哪些好处以及 ... -
构建高并发、服务化、低耦合企业级脚骨:springmvc+mybatis+restfull+webservice+bootstrap html5
2015-04-14 01:17 85SpringMVC + Mybatis + SpringS ... -
教您搭建大型互联网企业架构:springmvc+mybatis+restful+webservice+quartz+bootstrap
2015-04-13 21:54 99SpringMVC + Mybatis + SpringS ... -
大型互联网服务集成平台:springmvc+mybatis+restful+webservice+quartz+bootstrap html5
2015-04-13 21:49 81SpringMVC + Mybatis + SpringSe ... -
大型互联网服务集成平台:springmvc+mybatis+restfull+JMS+webservice+bootstrap
2015-04-12 23:36 22SpringMVC + Mybatis + SpringS ... -
大型互联网服务集成平台:springmvc+mybatis+restfull+JMS+webservice+bootstrap
2015-04-12 23:33 83SpringMVC + Mybatis + SpringS ... -
Maven构建大型互联网架构springmvc+mybatis+Restfull+Webservice+Bootstrap
2015-04-12 23:28 71SpringMVC + Mybatis + SpringS ... -
maven构建高大上开源架构:springmvc+mybatis+rest+bootstrap html5
2015-04-12 23:25 23SpringMVC + Mybatis + SpringS ... -
手机App后台架构:Springmvc+SpringSecurity+mybatis+Rest+Quartz+Bootstrap Html5( Maven构建)
2015-04-09 01:39 76APP后台架构Maven构建,模拟大型互联网架构,支持高并发 ... -
maven构建springmvc+mybatis+rest+webservice+bootstrap html5(cms开源项目)
2015-04-09 01:21 85SpringMVC + Mybatis + SpringS ... -
Java正则表达式
2014-11-26 21:03 1193Java正则表达式: package pack.ja ... -
Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCache
2014-11-10 20:03 6187错误信息: [org.springframework.be ... -
Collections工具类中的frequency方法统计单词出现的次数
2013-11-05 21:30 2771最近发现了一个Collections中有一个很好用的方法: ... -
Java 压缩Excel文件生成.zip文件
2013-05-08 22:22 7911首先创建文件目录,然后生成Excel文件到创建的目录下, ... -
Java 解压缩zip文件
2013-05-08 13:14 8287不借助于其他的第三方 ... -
Jxl操作Excel设置背景、字体颜色、对齐方式、列的宽度
2013-04-06 22:26 57498最近项目中需要用到导出Excel文件,以下是我写了一个通过j ... -
java获取字节的长度.
2012-05-17 22:00 6696我们经常要获取中文,数字,或者英文字符所占字节的长度,下面就列 ... -
StringBuffer-reverse()字符反转功能
2012-05-17 21:42 7057在书上看到一个这样的例子, 采用最简便的方式把一串字符串反转过 ... -
java 打开IE
2012-05-23 22:14 1261Runtime.getRuntime().exec(" ...
相关推荐
大数据方面很不错的资料,分享给大家,在今后大数据、云的发展趋势下,希望大家有所收获
一个ant的简单的教程,很适合基础的入门
To use the class inside the jsp page we need to create an object of the class by using the new operator. At last use the instance of the class to access the methods of the java file. Setting Colors ...
For example, if your header file uses the File class in ways that do not require access to the declaration of the File class, your header file can just forward declare class File; instead of having ...
Fixed a bug when sending email to more than two address (the separator is still ‘,‘).9/3/981.6.0- Sometimes the filenames of an attachment contain invalid chars making very dificult to open a ...
Building an Object Model with the Class Designer 778 Summary 783 36 Sampling Design Patterns in C# 784 Overview of Design Patterns 784 The Iterator Pattern 785 Implementing the Proxy ...
1.2 An architectural overview of OSGi 9 The OSGi framework 9 ■ Putting it all together 12 1.3 “Hello, world!” examples 12 Module layer example 12 ■ Lifecycle layer example 14 ■ Service layer ...
Fetching a Row as an Object 10.3. Zend_Db_Profiler 10.3.1. Introduction 10.3.2. Using the Profiler 10.3.3. Advanced Profiler Usage 10.3.3.1. Filter by query elapsed time 10.3.3.2. Filter by ...
Instantiation using an instance factory method ........................................... 30 4.4. Dependencies ...........................................................................................
Instantiation using an instance factory method ........................................... 30 4.4. Dependencies ...........................................................................................
Table of Contents Section 1 Introduction to SystemVerilog ...................................................................................................... 1 Section 2 Literal Values................
Sun 官方 J2ee 5.0 教程 The Java EE 5Tutorial For Sun Java System Application Server 9.1 Contents Preface ..................................................................................................