java 动态代理报 空指针异常

在学习动态代理时 遇到一个莫名奇妙的异常 还望各位大佬能提点一下。。代码如下:
接口:
public interface UserService {
public int saveUser(String dosth);
}
委托类:
public class UserServiceImpl implements UserService {
@Override
public int saveUser(String dosth) {
System.out.println(dosth);
return 1;
}
}
测试main方法:
public static void main(String[] args) {
UserService us = new UserServiceImpl();
UserService usp = (UserService) Proxy.newProxyInstance(us.getClass().getClassLoader(), us.getClass().getInterfaces(),new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//
System.out.println("before...");
Object obj = method.invoke(us, args);
System.out.println(obj);
System.out.println("after...");
return obj;
}
});
System.out.println(usp.saveUser("租房子"));
}

此时代码没什么问题:
运行结果: before...
租房子
1
after...
1
可是我把 invoke 方法里的 return obj 改为 return null 时 测试时会报空指针异常:
运行结果如下:
before...
租房子
1
after...
Exception in thread "main" java.lang.NullPointerException
at com.sun.proxy.$Proxy0.saveUser(Unknown Source)
at dynamicProxy.impl.dynamicProxy.main(dynamicProxy.java:27)

不是很理解 为什么感觉是 invoke 方法被执行了以后 还报我的代理对象空指针??搞了半天了~~~

1个回答

代理类中的代码,有返回值的话会有类型强转操作将null转为Integer再转为int,转换实际执行代码为((Integer)null).intValue(),所以会报控制针
如下为反编译代理类得到的方法
public final int saveUser(String var1) throws {
try {
return ((Integer)super.h.invoke(this, m3, new Object[]{var1})).intValue();
} catch (RuntimeException | Error var3) {
throw var3;
} catch (Throwable var4) {
throw new UndeclaredThrowableException(var4);
}
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java 拆箱报空指针异常
Integer  null值转换int为0 public static void main(String[] args){ Integer i = null; int a = i == null?0:i; System.out.println(a); }  
java编写程序报空指针异常(NullPointerException)
之前在编写java Application时候也遇到这种空指针问题,检查过后发现是因为没有对变量没有初始化赋值,昨天写javaweb项目,需要使用JDBC ,运行的时候老是报空指针异常,页面404...报错的代码: PreparedStatement pst = null; pst = conn.prepareStatement(sql); 红色标注的这行报空指针异常,找了半天错误才发现是...
Java报空指针异常怎么处理
这是一个MD5的工具类nn```n public class MD5 n n public static String getMD5(String str)n tryn MessageDigest md = MessageDigest.getInstance("MD5");n n md.update(str.getBytes());n n return new BigInteger(1,md.digest()).toString(16);n catch(Exception e)n e.printStackTrace();n return null;n n n nnn```n前台传输信息到后台nn```n MD5 pwd = new MD5();n @SuppressWarnings("static-access")n String password = pwd.getMD5(request.getParameter("password"));n```nn然后一运行程序就报空指针异常:md.update(str.getBytes());想问问应该怎么修改n
findViewById报空指针异常
这种情况是焦点被其他的控件抢夺了,所以你点击左边返回按钮是没有响应的(上面的代码原来是这样的 android:layout_width ="match_parent")
反射调用方法,报空指针异常
@Component public class OSSUtil { private static Logger log = LoggerFactory.getLogger(OSSUtil.class); private static OSSUtil ossUtil; @Autowired private OSSProperties ossProperties; ...
总是报空指针异常,急!
package com.xyls.spring;rnrnimport java.io.File;rnimport java.io.FileInputStream;rnimport java.io.IOException;rnimport java.io.InputStream;rnimport java.lang.reflect.InvocationTargetException;rnimport java.net.URI;rnimport java.net.URISyntaxException;rnimport java.util.Properties;rnrnimport com.sun.org.apache.commons.beanutils.BeanUtils;rnrnpublic class ActionFactory rn //private static URI uri;rn rn public static Action getAction(String actionName)rn rn Properties p = new Properties();rn rn /*FileInputStream fis = (FileInputStream) ActionFactory.class.getClassLoader().rn getResourceAsStream("config.properties");*/rn try rn //URI uri = ActionFactory.class.getClassLoader().getResource("config.properties").toURI();rn //p.load(new FileInputStream(new File(uri)));rn //p.load(new FileInputStream("config.properties"));rn rn p.load(ActionFactory.class.getClassLoader().getResourceAsStream("config.properties"));rn rn String actionImplName = (String) p.getProperty(actionName);rn rn rn String actionMessage = (String) p.getProperty(actionName+"_msg");rn rn Object obj = Class.forName(actionImplName).newInstance();rn //BeanUtils是Apache Commons BeanUtils提供的辅助类rn BeanUtils.setProperty(obj, "message", actionMessage);rn return (Action) obj;rn catch (IOException e) rn rn e.printStackTrace();rn catch (InstantiationException e) rn rn e.printStackTrace();rn catch (IllegalAccessException e) rn rn e.printStackTrace();rn catch (ClassNotFoundException e) rn rn e.printStackTrace();rn catch (InvocationTargetException e) rn rn e.printStackTrace();rn /*catch (URISyntaxException e) rn rn e.printStackTrace();rn */rn return null;rn rn rn rn public void testFactory()rn Action action = ActionFactory.getAction("theAction");rn System.out.println(action.execute("actionfactory"));rn rn rn public static void main(String[] args) rn new ActionFactory().testFactory();rn //System.out.println(new ActionFactory().getAction("theAction"));rn rnrnrnrnrn异常:Exception in thread "main" java.lang.NullPointerExceptionrn at java.util.Properties$LineReader.readLine(Properties.java:418)rn at java.util.Properties.load0(Properties.java:337)rn at java.util.Properties.load(Properties.java:325)rn at com.xyls.spring.ActionFactory.getAction(ActionFactory.java:28)rn at com.xyls.spring.ActionFactory.testFactory(ActionFactory.java:63)rn at com.xyls.spring.ActionFactory.main(ActionFactory.java:68)rnrnconfig.properties属性文件放在src下,内容为rntheAction=com.xyls.spring.impl.UpperActionrntheAction_msg=hellornrn
SSH2项目报空指针异常
大家帮我看看这个项目,怎么会出现空指针异常rnaction:rn[code=java]rnpublic class UserAction extends ActionSupport rn /**rn * rn */rn private static final long serialVersionUID = 1L;rn private List items=null;rn private ItemDAO itemDAO ;rn public void setItemDAO(ItemDAO itemDAO)rn this.itemDAO=itemDAO;rn rn @SuppressWarnings("unchecked")rn @Overridern public String execute() throws Exception rn // TODO Auto-generated method stubrn items = itemDAO.findAll();rn return SUCCESS;rn rn public static void main(String[] args) rn // TODO Auto-generated method stubrnrn rn rn public List getItems() rn return items;rn rn public void setItems(List items) rn this.items = items;rn rn rn rnrnrn[/code]rnDAO:rn[code=java]rnpackage com.lee.dao;rnrnimport java.util.List;rnimport org.hibernate.LockMode;rnimport org.slf4j.Logger;rnimport org.slf4j.LoggerFactory;rnimport org.springframework.context.ApplicationContext;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnrnimport com.lee.model.Item;rnrn/**rn * A data access object (DAO) providing persistence and search support for Itemrn * entities. Transaction control of the save(), update() and delete() operationsrn * can directly support Spring container-managed transactions or they can bern * augmented to handle user-managed Spring transactions. Each of these methodsrn * provides additional information for how to configure it for the desired typern * of transaction control.rn * rn * @see com.lee.model.Itemrn * @author MyEclipse Persistence Toolsrn */rnpublic class ItemDAO extends HibernateDaoSupport rn private static final Logger log = LoggerFactory.getLogger(ItemDAO.class);rn // property constantsrn public static final String ITEM_NAME = "itemName";rn public static final String SOURCE = "source";rn public static final String YEAR = "year";rn public static final String FUND = "fund";rn public static final String LEADER = "leader";rnrn protected void initDao() rn // do nothingrn rnrn public void save(Item transientInstance) rn log.debug("saving Item instance");rn try rn getHibernateTemplate().save(transientInstance);rn log.debug("save successful");rn catch (RuntimeException re) rn log.error("save failed", re);rn throw re;rn rn rnrn public void delete(Item persistentInstance) rn log.debug("deleting Item instance");rn try rn getHibernateTemplate().delete(persistentInstance);rn log.debug("delete successful");rn catch (RuntimeException re) rn log.error("delete failed", re);rn throw re;rn rn rnrn public Item findById(java.lang.Integer id) rn log.debug("getting Item instance with id: " + id);rn try rn Item instance = (Item) getHibernateTemplate().get(rn "com.lee.model.Item", id);rn return instance;rn catch (RuntimeException re) rn log.error("get failed", re);rn throw re;rn rn rnrn public List findByExample(Item instance) rn log.debug("finding Item instance by example");rn try rn List results = getHibernateTemplate().findByExample(instance);rn log.debug("find by example successful, result size: "rn + results.size());rn return results;rn catch (RuntimeException re) rn log.error("find by example failed", re);rn throw re;rn rn rnrn public List findByProperty(String propertyName, Object value) rn log.debug("finding Item instance with property: " + propertyNamern + ", value: " + value);rn try rn String queryString = "from Item as model where model."rn + propertyName + "= ?";rn return getHibernateTemplate().find(queryString, value);rn catch (RuntimeException re) rn log.error("find by property name failed", re);rn throw re;rn rn rnrn public List findByItemName(Object itemName) rn return findByProperty(ITEM_NAME, itemName);rn rnrn public List findBySource(Object source) rn return findByProperty(SOURCE, source);rn rnrn public List findByYear(Object year) rn return findByProperty(YEAR, year);rn rnrn public List findByFund(Object fund) rn return findByProperty(FUND, fund);rn rnrn public List findByLeader(Object leader) rn return findByProperty(LEADER, leader);rn rnrn public List findAll() rn log.debug("finding all Item instances");rn try rn String queryString = "from Item";rn return getHibernateTemplate().find(queryString);rn catch (RuntimeException re) rn log.error("find all failed", re);rn throw re;rn rn rnrn public Item merge(Item detachedInstance) rn log.debug("merging Item instance");rn try rn Item result = (Item) getHibernateTemplate().merge(detachedInstance);rn log.debug("merge successful");rn return result;rn catch (RuntimeException re) rn log.error("merge failed", re);rn throw re;rn rn rnrn public void attachDirty(Item instance) rn log.debug("attaching dirty Item instance");rn try rn getHibernateTemplate().saveOrUpdate(instance);rn log.debug("attach successful");rn catch (RuntimeException re) rn log.error("attach failed", re);rn throw re;rn rn rnrn public void attachClean(Item instance) rn log.debug("attaching clean Item instance");rn try rn getHibernateTemplate().lock(instance, LockMode.NONE);rn log.debug("attach successful");rn catch (RuntimeException re) rn log.error("attach failed", re);rn throw re;rn rn rnrn public static ItemDAO getFromApplicationContext(ApplicationContext ctx) rn return (ItemDAO) ctx.getBean("ItemDAO");rn rnrn[/code]rnxml:rn[code=java]rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn rn rn rn rn com/lee/model/Item.hbm.xmlrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rn
系统相册选择图片报空指针异常
用别人的代码练习的时候,到了选择图片,点击图片后就崩溃,系统报空指针异常,主要代码如下:rnrn /**rn * 跳转相册rn */rn private void toPicture() rn photoDialog.dismiss();rn Intent intent = new Intent(Intent.ACTION_PICK, null);rn intent.setDataAndType(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");rn startActivityForResult(intent, IMAGE_REQUEST_CODE);rn rn@Overridern public void onActivityResult(int requestCode, int resultCode, Intent data) rn switch (requestCode) rn case IMAGE_REQUEST_CODE: // 相册数据rn // 做非空判断,当我们觉得不满意想重新剪裁的时候便不会报异常,下同rn if (data != null) rn // 外界的程序访问ContentProvider所提供数据 可以通过ContentResolver接口rn ContentResolver resolver = getContentResolver();rn Uri originalUri = data.getData(); // 获得图片的urirn String[] proj = MediaStore.Images.Media.DATA;rn // 好像是android多媒体数据库的封装接口,具体的看Android文档rn Cursor cursor = getContentResolver().query(originalUri, proj, null, null, null);rn // 按我个人理解 这个是获得用户选择的图片的索引值rn [color=#FF0000] int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);[/color]rn // 将光标移至开头 ,这个很重要,不小心很容易引起越界rn cursor.moveToFirst();rn // 最后根据索引值获取图片路径rn String path = cursor.getString(column_index);rn //listImg.add(ImageCompressHelper.getInstance().compressIMG(this, path));rn listImg.add(path);rn updataIMG();rn rn break;rn rn super.onActivityResult(requestCode, resultCode, data);rn rnrn手机是4.4版本,也写了sd卡权限,后台报错是这一句: int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 求救啊各位!rn
注入dao 报空指针异常
碰到了一个 只有新司机才会犯的错误, 很傻的一个问题 , 我在一个类中写了一个方法, 然后在本类中另一方法调用竟然 是new了一个本类的对象去调用, ( 本类中的方法是可以直接写 方法名就可以调用的) 接下来 , 说由此引发的坑 开始 这里注入了 dao ,debug发现也不为空 但是 在后边调用方法的时候, 我new了一个本类的对象, 然后调用了 本类的方法, 该方法中使用...
filterconfig.getservletcontext报空指针异常?
在spring框架下会出现这个问题,若是不在框架下不会出现此问题,请大神恁解惑?![图片说明](http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/9.gif)![图片说明](http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/9.gif)![图片说明](http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/9.gif)
post请求报空指针异常
修改功能报空指针异常[img=https://img-bbs.csdn.net/upload/201703/05/1488719370_162160.png][/img][img=https://img-bbs.csdn.net/upload/201703/05/1488719393_593245.png][/img][img=https://img-bbs.csdn.net/upload/201703/05/1488719428_687769.png][/img]
junit测试报空指针异常
今天进行junit测试的时候出现了下面的错误(单纯进行某个某个方法出现下面的错误,如果都某个类进行测试,还不会出现) 下面给出解决方案 1.首先把junit4.4.jar的包 Remove 掉 2.然后 Add Library 选择如下 4.点击Next  最后点击选择  Junit4   最后OK 问题就解决了 (网上也有说,把Junit的包排到前面也可以解决该
关于junit 报空指针异常
1.junit没有build path 2.junit的版本有问题,就是说你该换一个junit 3.Android开发时把Android junit当做java junit使用了,如果你没有安装Android开发环境,就是你不是搞Android开发的,就是1.2的问题 4.如果前三种没解决问题,这里还有个通用的看日志。查看WorkSpace下的.metadata文件夹下的.log文件,看一下...
List报空指针异常
List list = null; list.add("key","value"); 解决办法 List list = new ArrayList(); 实例化一下好了
mybatis一直报空指针异常
调用mybatis中mapper.xml中所有的方法都报空指针异常(包括逆向工程生成的方法), 原因是:mapper.xml没有注入到对应的serviceImpl中
jstl 1.2.5报空指针异常
jstl 1.2.5报空指针异常 需要导入官方的四个包 并且jsp页面中的引入方式为:
使用QQ互联报空指针异常
按照文档资料 1 2 3 4 5 6 7 8     public void login()     {         mTencent = Tencent.createInstance(AppId, this.getApplicationContext());       
redisTemplate 报空指针异常
redisTemplate  报空指针异常 原因分析 1.是否引入正常jar包 2.调用redis工具类的时候是否@Resource自动注入 pom.xml                     org.springframework.boot             spring-boot-starter-data-redis         applicatio
清空arraylist,报空指针异常
[code=Java]rn private static ArrayList paramList = new ArrayList();rn ......rn public ArrayList checkValue(String str1, String str2) rn ......rn db = new DBUtil();rn paramList.clear();rn ......rn rn[/code]rnrn本来想每次调用checkValue方法的时候,先清空paramList,但是在eclipse中运行的结果报空指针异常,rn在执行paramList.clear()这句时报异常,rn异常信息为:rnjava.lang.NullPointerException at clear(), 请各位不吝赐教,谢谢!
R文件报空指针异常
各位大牛,我的R文件报空指针异常,google了许多答案,但结果不理想,请帮我看下rn @Overridern public View onCreateView(final LayoutInflater inflater, ViewGroup container,rn Bundle savedInstanceState) rn if (myPorintsFragmentRootView == null) rn myPorintsFragmentRootView =rn inflater.rn inflatern (R.rn layout.rn activity_mypoints,rn container, false);rn rn ViewGroup parent = (ViewGroup)rn myPorintsFragmentRootView.rn getParent();rn if (parent != null) rn parent.removeView(myPorintsFragmentRootView);rn rnrn ViewUtils.inject(this, myPorintsFragmentRootView);rn ImageLoadUtils.initImageLoadForLargeImage(context);rn initMainData();rn gridViewwokedui.setAdapter(wokedui);rn gridViewwokedui.setOnItemClickListener(new AdapterView.OnItemClickListener() rn @Overridern public void onItemClick(AdapterView parent, View view, int position, long id) rn HomeGoodsInfoBean homeGoodsInfoBean = homeGoodsInfoBeanForWokedui.get(position);rn onClickItems(homeGoodsInfoBean);rn rn );rn gridViewtuijian.setAdapter(tuijian);rn gridViewtuijian.setOnItemClickListener(new AdapterView.OnItemClickListener() rn @Overridern public void onItemClick(AdapterView parent, View view, int position, long id) rn HomeGoodsInfoBean homeGoodsInfoBean = homeGoodsInfoBeanForTuijian.get(position);rn onClickItems(homeGoodsInfoBean);rn rn );rn initSwipeLayout();rn return myPorintsFragmentRootView;rn rn
jar包报空指针异常
jar包中的这个静态成员无法加载,老哥们有遇见过类似的问题吗?rn是什么原因导致的rn再别的项目中可以用,这个项目就不行了rn这个是debug时的截图rn[img=https://img-bbs.csdn.net/upload/201812/11/1544518031_438951.png][/img]
String.length()>1 报空指针异常
@Override public ExpertEntity getExpertById(Long id) { ExpertEntity Expert = ExpertMapper.getObjectById(id); if (Expert.getFilepath().length()>1) { ... } return Expert; } 对象的Stirng的l...
JBoss启动报空指针异常
小弟是第一次使用JBoss,尝试过在MyEclipse中新建一个web项目部署到JBoss中没任何问题,可以运行,但是将公司给我的项目部署上去时候发生错误, 请各位大侠不吝指教,谢谢. 错误代码如下.rn09:30:15,315 WARN [EjbModule] EJB configured to bypass security. Please verify if this is intended. Bean=Sequence Deployment=vfsfile:/D:/jboss-5.1.0.GA/server/default/deploy/planest.war/rn09:30:15,631 ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:module="planest.war",service=EjbModule state=Create mode=Manual requiredState=Installedrnjava.lang.NullPointerExceptionrn at org.jboss.ejb.plugins.cmp.jdbc.SQLUtil.fixTableName(SQLUtil.java:172)rn at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.init(JDBCEntityBridge.java:157)rn at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.initStoreManager(JDBCStoreManager.java:435)rn at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:368)rn at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:172)rn at org.jboss.ejb.EjbModule.startService(EjbModule.java:495)rn at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:376)rn at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:322)rn at sun.reflect.GeneratedMethodAccessor80.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)rn at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)rn at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)rn at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)rn at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)rn at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:189)rn at $Proxy38.start(Unknown Source)rn at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)rn at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)rn at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)rn at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)rn at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)rn at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)rn at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)rn at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)rn at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)rn at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)rn at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)rn at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)rn at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)rn at org.jboss.system.ServiceController.doChange(ServiceController.java:688)rn at org.jboss.system.ServiceController.start(ServiceController.java:460)rn at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)rn at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)rn at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)rn at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)rn at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)rn at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)rn at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)rn at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)rn at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)rn at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)rn at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)rn at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)rn at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)rn at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)rn at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)rn at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)rn at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)rn at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)rn at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)rn at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)rn at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)rn at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)rn at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:361)rn at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)rn at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)rn at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)rn at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)rn at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)rn at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)rn at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)rn at org.jboss.system.server.profileservice.repository.AbstractProfileService.activateProfile(AbstractProfileService.java:306)rn at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:271)rn at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)rn at org.jboss.Main.boot(Main.java:221)rn at org.jboss.Main$1.run(Main.java:556)rn at java.lang.Thread.run(Thread.java:662)rn09:30:15,636 INFO [EjbModule] Undeployed Sequencern09:30:15,636 INFO [ProxyFactory] Unbind EJB Home 'SequenceGenerator' from jndi 'SequenceGenerator'rn09:30:15,638 INFO [EjbModule] Undeployed SequenceGeneratorrn09:30:15,644 ERROR [AbstractKernelController] Error installing to Real: name=vfsfile:/D:/jboss-5.1.0.GA/server/default/deploy/planest.war/ state=PreReal mode=Manual requiredState=Realrn谢谢大家了.
c3p0报空指针异常
javaweb项目使用c3p0连接数据库报空指针异常,但之前同样流程的项目却能正常运行.经检查发现c3p0的配置文件配置是正确的,但在运行时没有加载自定义的配置文件
getActionBar()报空指针异常
调用 getActionBar()的Activity类 public class WlanListActivity extends AppCompatActivity 在使用getActionBar("标题内容")的时候报空指针。 原因是要用AppCompatActivity类里的getSupportActionBar()
用自定义标签报空指针异常
用自定义标签报空指针异常:求高手指点:rnrnrnrnrnrnrn 1.0rn 1.0rn pageTagrn http://org.web.sshrnrn rn pagern com.util.PageTagrn tagdependentrn rn pagern truern truern com.util.PageUtilrn rn rnrnrnrnrnjsp页面:rnrnrnrnrnweb.xml配置:rnrnrn rn rn http://org.web.ssh.pageTagrn /WEB-INF/tlds/pageTag.tldrn rn rnrnrnrn
query.list()报空指针异常
代码如下:rnpublic List findOwnerFamily(User u)rn List list = null;rn Session session = SessionFactory.currentSession();rn Transaction t = null;rn tryrn t = session.beginTransaction();rn Query query = session.createQuery("from Family f where f.user.userEp=?").setParameter(0, u.getUserEp());rn System.out.println("--1--"+query.iterate().hasNext());rn System.out.println("--2--"+query == null);rn if(query != null)rn list = query.list();rn rn t.commit();rn catch(Exception e)rn t.rollback();rn e.printStackTrace();rn finallyrn session.close();rn rn System.out.println("--3--"+list.size());rn return list;rnrn打印处1: truern2: falsern3: 未打印rnrn就是在list = query.list();的地方报空指针异常。。。不知道是怎么回事。。rn明明query和query.iterator.hasnext()都是有值的。。。
android 报string空指针异常
原因是xml布局的分割线我用的view,但应该是View <View android:layout_width="1dp" android:layout_height="match_parent" android:background="@color/black_10"/>...
实体类报空指针异常
问题如下:传入的是orderShipping 使用 ordershipping接受,两个字段不同 orderShipping  ordershipping,所以报空指针了
mybatis一直报空指针异常????
mybatis一直报空指针异常????
android:Set报空指针异常
代码如下:rnpackage com.happy;rnrnrnrnrnimport com.person.PersonBean;rnimport com.service.PersonService;rnrnimport android.app.Activity;rnimport android.os.Bundle;rnimport android.util.Log;rnimport android.view.View;rnimport android.view.View.OnClickListener;rnimport android.widget.Button;rnimport android.widget.EditText;rnimport android.widget.Toast;rnrnrnpublic class addActivity extends Activity rn private EditText name;rn private EditText age;rn private EditText phone;rn private Button save;rn private static final String TAG="addActivity";rn protected void onCreate(Bundle savedInstanceState) rn // TODO Auto-generated method stubrn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity00);rn age=(EditText)findViewById(R.id.addActivity_age);rn name=(EditText)findViewById(R.id.addActivity_name);rn phone=(EditText)findViewById(R.id.addActivity_phone);rn save=(Button)findViewById(R.id.save_but);rn save.setOnClickListener(new SaveOnClickListener());rn rn rn private class SaveOnClickListener implements OnClickListenerrn PersonService service=new PersonService(addActivity.this);rn private PersonBean person;rnrn @Overridern public void onClick(View v) rn // TODO Auto-generated method stubrn String myName=name.getText().toString();rn rn Log.i(TAG, myName);rn int myAge=Integer.valueOf(age.getText().toString());rn String myPhone=phone.getText().toString();rn person.setName(myName);rn person.setAge(myAge);rn person.setPhone(myPhone);rn service.save(person);rn Toast.makeText(addActivity.this, "保存成功", 2000).show();rn rn rn rn rn rn rnrn//报错如下:person.setName(myName);空指针rn我在日志中查询到myName的结果可以获取,为什么set到personbean中会有空指针呢rn
strings.xml报空指针异常
进入strings.xml编辑文件时就会报空指针异常,请大家指教,多谢!
sql操作报空指针异常
java.lang.NullPointerException at ................................... 当确定上述空指针异常报错确实出在SQL语句执行上的时候,确定SQL语句内变量无误后,就很有可能是以下两种情况: 1.数据库服务没有正常启动(MySQL、oracle等数据库都会有此问题) 2.对Connection conn的conn输出一下,看看是不
Tomcat部署后报空指针异常!
java.lang.NullPointerExceptionn at com.fh.util.Jurisdiction.readMenu(Jurisdiction.java:44)n at com.fh.util.Jurisdiction.hasJurisdiction(Jurisdiction.java:33)n at com.fh.interceptor.LoginHandlerInterceptor.preHandle(LoginHandlerInterceptor.java:31)n at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134)n at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:954)n at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)n at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)n at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)n at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)n at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)n at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)n at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)n at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)n at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)n at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)n at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)n at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)n at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)n at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)n at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)n at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)n at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)n at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)n at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)n at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)n at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)n at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:83)n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)n at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)n at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)n at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)n at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)n at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)n at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)n at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)n at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)n at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)n at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)n at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)n at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)n at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)n at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1452)n at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)n at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)n at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)n at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)n at java.lang.Thread.run(Unknown Source)n之前部署好使过,后来把项目部署到另一个tomcat版本后就这样了。其他机器部署都没有问题。不知道原因在哪,求大神指点。
什么时候报空指针异常?
空指针异常是我们开发当中经常遇到的一种程序异常情况,也是最简单的一种异常,这是一个运行级别异常,也就是在运行时才会抛出该异常。空指针异常就是我们在对空对象进行的任何操作都会报空指针异常。因此当程序报该异常时找到报错的位置,先进行判断该对象是否为空再进行操作处理。...
setText方法报空指针异常
今天做开发的时候发现一个TextView的setText方法报空指针异常。当时就想着是不是TextView没有初始化,却发现它不为null。然后,就想着既然它不是空的,那就有可能是我传入的值是空的咯!令人沮丧的是我发现传入的值也不为空!!!究其原因,最后发现因为传入的是ArrayList.size()方法,即传入的值类型不对!
求助 httpClient.execute 报空指针异常
talk is cheaprnrn[code=java]rnpackage test;rnrnimport java.io.InputStream;rnrnimport org.apache.http.HttpEntity;rnimport org.apache.http.HttpResponse;rnimport org.apache.http.client.HttpClient;rnimport org.apache.http.client.methods.HttpGet;rnrnpublic class TestSpider rn //使用HttpClient创建一个客户端rn private static HttpClient httpClient = null;rn rn /**rn * @param path 目标网页的链接rn * @return 表示是否可读取页面rn * @throws Exception IO异常rn */rn rn public boolean downloadPage(String path) throws Exception rn InputStream is = null;rn //创建一个HttpGet类,相当于在浏览器(HttpClient)中输入了一个地址rn HttpGet httpGet = new HttpGet(path);rn HttpResponse response = httpClient.execute(httpGet);rn HttpEntity entity = response.getEntity();rn if(entity!=null) rn is = entity.getContent();rn rn rn int length;rn byte[] tmp = new byte[2048];rn while((length = is.read(tmp)) != -1) rn System.out.println(new String(tmp,0,length,"UTF-8"));rn rn rn rn return false;rn rn rn public static void main(String[] args) throws Exception rn TestSpider ts = new TestSpider();rn ts.downloadPage("http://www.baidu.com");rn rnrn[/code]rn[code=java]rnException in thread "main" java.lang.NullPointerExceptionrn at test.TestSpider.downloadPage(TestSpider.java:25)rn at test.TestSpider.main(TestSpider.java:43)rnrn[/code]
Spring自动装配报空指针异常
这几天在学Spring的自动装配,自己动手做一个小项目,但是被一个空指针异常卡住了。启动的时候弹出index.jsp,这是一个登陆页面:<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.
Spring自动装配报空指针异常。
Spring自动装配一个hibernateManage,第一个方法login()调用它的时候一切OK,第二个方法listRecordByUserId()调用它的时候却报空指针异常,为什么?n![图片说明](https://img-ask.csdn.net/upload/201702/28/1488247389_631782.png)
android解析json报空指针异常。
代码如下rn[code=Java]rnpackage com.student.activity;rnrnimport java.net.URI;rnimport java.util.ArrayList;rnimport java.util.HashMap;rnimport java.util.List;rnrnimport org.apache.http.HttpEntity;rnimport org.apache.http.HttpResponse;rnimport org.apache.http.client.HttpClient;rnimport org.apache.http.client.methods.HttpPost;rnimport org.apache.http.impl.client.DefaultHttpClient;rnimport org.apache.http.util.EntityUtils;rnimport org.json.JSONArray;rnimport org.json.JSONObject;rnrnimport android.app.Activity;rnimport android.os.Bundle;rnimport android.util.Log;rnimport android.widget.ListView;rnimport android.widget.SimpleAdapter;rnimport android.widget.Toast;rnrnpublic class StuManagerActivity extends Activity rn private static final String TAG = "StuManagerActivity";rn private List> list = null;rn private HashMap stu = null;rnrn private ListView listView = null;rn private static String url = "http://192.168.1.103:8080/StudentServer/getJsonStu.action";rnrn /** Called when the activity is first created. */rn @Overridern public void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.main);rnrn listView = (ListView) findViewById(R.id.stuList);rn rn getServerData(url);rn rnrn public void getServerData(String url) rn // 提供默认的HttpClient实现rn HttpClient client = new DefaultHttpClient();rn HttpPost request;rnrn try rn request = new HttpPost(new URI(url));rn HttpResponse response = client.execute(request);rn // 判断请求是否成功rn if (response.getStatusLine().getStatusCode() == 200) rn HttpEntity entity = response.getEntity();rn if (entity != null) rn String out = EntityUtils.toString(entity, "UTF-8");rn Log.i(TAG, out);rn JSONArray jsonArray = new JSONArray(out);rn System.out.println(jsonArray.length());rn list = new ArrayList>();rn System.out.println(list.size());rn rn for (int i = 0; i < jsonArray.length(); i++) rn JSONObject jsonObject = (JSONObject) jsonArray.get(i);rn String stuName = jsonObject.getString("studentName");rn String stuSex = jsonObject.getString("stuSex");rn String phone = jsonObject.getString("phone");rn rn stu.put("stuName", stuName);rn stu.put("stuSex", stuSex);rn stu.put("phone", phone);rn rn System.out.println(stuName);rn rn list.add(stu);rn System.out.println(list.size()+"");rn rn SimpleAdapter adapter = new SimpleAdapter(rn StuManagerActivity.this, list, R.layout.item,rn new String[] "stuName", "stuSex", "phone" ,rn new int[] R.id.stuName, R.id.stuSex, R.id.phone );rn rn listView.setAdapter(adapter);rn rn rn catch (Exception e) rn e.printStackTrace();rn Log.e(TAG, e.toString());rn Toast.makeText(StuManagerActivity.this, "获取数据失败!", Toast.LENGTH_LONG).show();rn rnrn rnrn[/code]rnrn
相关热词 c#检测非法字符 c#双屏截图 c#中怎么关闭线程 c# 显示服务器上的图片 api嵌入窗口 c# c# 控制网页 c# encrypt c#微信网页版登录 c# login 居中 c# 考试软件