- 浏览: 1988960 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (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 2413当写入数据到mysql数据库中发生乱码时.请检查以下几个地 ... -
设计模式之-代理模式-Proxy
2015-04-28 21:24 867使用代理模式之前需要知道代理模式能做什么? 能有哪些好处以及 ... -
构建高并发、服务化、低耦合企业级脚骨: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 1218Java正则表达式: package pack.ja ... -
Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCache
2014-11-10 20:03 6247错误信息: [org.springframework.be ... -
Collections工具类中的frequency方法统计单词出现的次数
2013-11-05 21:30 2812最近发现了一个Collections中有一个很好用的方法: ... -
Java 压缩Excel文件生成.zip文件
2013-05-08 22:22 7948首先创建文件目录,然后生成Excel文件到创建的目录下, ... -
Java 解压缩zip文件
2013-05-08 13:14 8350不借助于其他的第三方 ... -
Jxl操作Excel设置背景、字体颜色、对齐方式、列的宽度
2013-04-06 22:26 57700最近项目中需要用到导出Excel文件,以下是我写了一个通过j ... -
java获取字节的长度.
2012-05-17 22:00 6743我们经常要获取中文,数字,或者英文字符所占字节的长度,下面就列 ... -
StringBuffer-reverse()字符反转功能
2012-05-17 21:42 7091在书上看到一个这样的例子, 采用最简便的方式把一串字符串反转过 ... -
java 打开IE
2012-05-23 22:14 1298Runtime.getRuntime().exec(" ...
相关推荐
大数据是信息技术领域的一个重要分支,它涉及到数据的采集、存储、管理、分析与应用等多个方面。随着互联网、物联网、云计算等技术的发展,数据的规模和复杂性呈爆炸性增长,对数据处理技术提出了更高的要求。...
知识点:Apache Ant 简介与使用指南 一、引言 Apache Ant 是一款由 Apache Software Foundation 开发的 Java 基础构建工具。这款工具的显著特点在于其构建文件采用 XML 格式编写,充分利用了 XML 的开放标准、便携...
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 ...
12. Explain the concept of polymorphism in Java.Answer: Polymorphism is the ability of an object to take on many forms. In Java, it is achieved through method overriding and method overloading. Method...
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 ...
- **Project Structure**: Understanding the structure of an Xcode project is crucial. Projects typically consist of files such as source code files (.m), interface definition files (.h), resource files...
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 ...
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 ...
- **Static Typing to an Inherited Class(对继承类进行静态类型)**:解释了如何将静态类型应用于继承的类。 综上所述,Objective-C基础教程覆盖了从入门到进阶的多个方面,适合Objective-C初学者系统学习该语言...
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................