java 空指针异常找不到原因? 这怎么解决? [问题点数:40分]

Bbs1
本版专家分:5
结帖率 50%
Bbs6
本版专家分:7833
Blank
红花 2015年2月 扩充话题大版内专家分月排行榜第一
Blank
黄花 2018年5月 扩充话题大版内专家分月排行榜第二
2015年1月 扩充话题大版内专家分月排行榜第二
Blank
蓝花 2018年6月 扩充话题大版内专家分月排行榜第三
2018年3月 扩充话题大版内专家分月排行榜第三
2014年12月 扩充话题大版内专家分月排行榜第三
Bbs9
本版专家分:62305
Blank
GitHub 绑定GitHub第三方账户获取
Blank
银牌 2013年11月 总版技术专家分月排行榜第二
Blank
铜牌 2013年10月 总版技术专家分月排行榜第三
Blank
红花 2014年3月 Java大版内专家分月排行榜第一
2014年1月 Java大版内专家分月排行榜第一
2013年12月 Java大版内专家分月排行榜第一
2013年11月 Java大版内专家分月排行榜第一
2013年10月 Java大版内专家分月排行榜第一
Bbs2
本版专家分:489
Bbs2
本版专家分:114
Blank
黄花 2014年1月 C/C++大版内专家分月排行榜第二
Bbs2
本版专家分:489
Bbs1
本版专家分:25
Bbs5
本版专家分:2428
Java指针异常怎么解决
Exception in thread "main" <em>java</em>.lang.NullPointerExceptionrn at com.hulliu.Airport.check(Airport.<em>java</em>:19)rn at com.hulliu.Test.main(Test.<em>java</em>:20)rnrn19行前后代码rn public void check(String endPoint)rn //查询rn Airline p=air.indexOf(endPoint);rn if(p!=null)rn p.check();rn elsern System.out.println("无到达该地点航班");rn rnindexOf方法rnpublic Airline indexOf(String x)rn int j = 0;// j为计数器rn while (j < curLen )rn // 从顺序表中的首结点开始查<em>找</em>,直到listElem[j]指向元素x或到达顺序表的表尾rn if(listElem[j].endPoint.equals(x))rn Airline e = listElem[j];rn return e;rn rn j++;rn rn return null;rn rn
我这指针异常!?没看懂是什么原因
[code=Java]rnCollection collection = processes.values();rn Iterator iter = collection.iterator();rn //int i = 0;rn while(iter.hasNext())rn Process process1 = iter.next();rn System.out.println(process1.str+process1.height);rn if(process1.height!=process.height) //如果与执行的优先权不相等,认为是等待进程,优先权加一rn pros.add(process1); //[color=#FF0000]没错,就是这句抛出<em>空</em><em>指针</em><em>异常</em>[/color]rn System.out.println(process1.str+"被阻塞!");rn rn rn[/code]rnrn显示如下:rnprocess340.0rnprocess230.0rn抛出Exception in thread "main" <em>java</em>.lang.NullPointerExceptionrn at ncist.threadTest.ProcessAction.changHeight(ProcessAction.<em>java</em>:41)rnrn<em>空</em><em>指针</em><em>异常</em>??rn可是从输出看我的process1有值,进入if语句后就变成<em>空</em><em>指针</em>了??rn我把if语句去掉,正常显示,如下:rnprocess340.0rnprocess230.0rnprocess110.0
老是指针异常但是不到异常原因,。。。。。
![图片说明](https://img-ask.csdn.net/upload/201709/14/1505365962_109301.png)rnrn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505365972_502628.png)rnrn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505369108_798318.png)rnrn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505369118_901025.png)rn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505370644_599473.png)rn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505370660_933617.png)rn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505370673_374014.png)rn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505370719_564838.png)rn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505370729_857160.png)rn![图片说明](https://img-ask.csdn.net/upload/201709/14/1505370740_175815.png)rnrn现在的问题已经拿红色的圈标出来了,userMapper.login(user)这里面的user用debugrn显示是有值的,但是将这边的值传递给User userDb以后,userDb用debug显示就是rnnull值,这是为什么,写了好几次了,在进行给值的时候,是要进行一下 (user)强转的,rn但是这次写就没有提示让我进行强转,中间的(user)是自己加上去的。。为什么值传递rn不过去呢?报<em>空</em><em>指针</em><em>异常</em>。。(这个<em>空</em><em>指针</em><em>解决</em>了,但是页面又跳转不聊了。。图片都放出来了)rnrn谢谢热情的亲们,所有的问题都<em>解决</em>了,<em>空</em><em>指针</em><em>异常</em>是数据库中密码用MD5加密生成rn加密文生错了,已经改正,后来的跳转跳不了是应为Controller中没有写@ResposBodyrn我前端页面用的ajax后面必须有@ResposBody把这个注解给丢了。。。谢谢亲们!!
指针异常怎么解决啊...
这是一个简单的窗体,但运行时不能显示内部窗体,并报<em>空</em><em>指针</em><em>异常</em>,这是怎么回事啊...求指教...rnimport <em>java</em>x.swing.*;rnimport <em>java</em>.awt.*;rnimport <em>java</em>.awt.event.*;rnpublic class swing窗体rn public static void main(String args[])rn Mywindow win=new Mywindow();rn win.validate();rn rnrnclass Mywindow extends JFramern JButton button1,button2;rn JTextArea text;rn JScrollPane scroll;rn JInternalFrame interframe;rn JSplitPane splitOne,splitTwo;rn Mywindow()rn setSize(300,300);rn setVisible(true);rn Container con=getContentPane();rn con.setLayout(new GridLayout(1,2));rn button1=new JButton("button1");rn button2=new JButton("button2");rn text=new JTextArea(6,12);rn scroll=new JScrollPane(text);rn splitOne=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,button1,button2);rn splitTwo=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,splitOne,scroll);rn interframe.setSize(200,200);rn interframe.setVisible(true);rn Container interCon=interframe.getContentPane();rn interCon.setLayout(new FlowLayout());rn interCon.add(splitTwo);rn JDesktopPane desk=new JDesktopPane();rn desk.add(interframe);rn getContentPane().add(desk);rn setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn rn
java 指针异常
一、<em>空</em><em>指针</em><em>异常</em>产生的主要<em>原因</em>: 1、当一个对象不存在时又调用其方法会产生<em>异常</em>obj.method() // obj对象不存在; 2、当访问或修改一个对象不存在的字段时会产生<em>异常</em>obj.method() // method方法不存在; 3、字符串变量未初始化;  4、接口类型的对象没有用具体的类初始化。 二: <em>解决</em>办法:        1. 控制台上点击出错的行数,一步步往上查<em>找</em>,点击调...
java指针处理方法
<em>空</em><em>指针</em><em>异常</em>产生的主要<em>原因</em>如下: (1)当一个对象不存在时又调用其方法会产生<em>异常</em>obj.method() // obj对象不存在 (2)当访问或修改一个对象不存在的字段时会产生<em>异常</em>obj.method() // method方法不存在 <em>空</em><em>指针</em>的<em>解决</em>办法:        重点关注报错发生的所在行,通过<em>空</em><em>指针</em><em>异常</em>产生的两条主要<em>原因</em>诊断具体的错误。同时为了避免<em>空</em><em>指针</em>的发生,最好在做判断处理时将“n
java常见的指针异常解决方法
摘自<em>java</em>技术栈微信公众号,原创栈长。 公众号传送门 <em>空</em><em>指针</em>是我们 Java 开发人员经常遇到的一个基本<em>异常</em>,这是一个极其普遍但似乎又无法根治的问题。 本文,栈长将带你了解什么是<em>空</em><em>指针</em>,还有如何有效的避免<em>空</em><em>指针</em>。 什么是<em>空</em><em>指针</em>? 当一个变量的值为 null 时,在 Java 里面表示一个不存在的<em>空</em>对象,没有实际内容,没有给它分配内存,null 也是对象成员变量的默认值。所以,一个对象如果没有进...
JAVA出现指针异常(初学者)
在初学JAVA时,讲到面向对象就会出现<em>空</em><em>指针</em><em>异常</em>的情况。这是很常见很普通的错误,鉴于最近代码报错都是这个<em>原因</em>。 故收集一些资料方法备用。(<em>java</em>.long.nullpointerexception <em>空</em><em>指针</em><em>异常</em>) 在面向对象的语言中,<em>指针</em>也是对象的引用。而<em>空</em><em>指针</em>,就是<em>指针</em>的内容为<em>空</em>(也可以理解为这个<em>指针</em>没有指向一块内存)。由于这是一个<em>空</em>的<em>指针</em>,指向了声明类型的类的<em>空</em>对象,所以你在应用这个对象的
java指针异常是什么、怎么发生、如何处理
<em>java</em><em>空</em><em>指针</em><em>异常</em>是什么、怎么发生、如何处理 文章目录<em>java</em><em>空</em><em>指针</em><em>异常</em>是什么、怎么发生、如何处理<em>空</em><em>指针</em>是什么<em>空</em><em>指针</em>怎么发生<em>空</em><em>指针</em>怎么处理 如果看到本文,请立即右上角,因为写完之后发现有问题. <em>空</em><em>指针</em>是什么 打开 NullPointerException源码 开头就写明出现 NullPointerException的<em>原因</em>: Invoking a method from a null object...
libmysqlclient_r.so.16不到原因解决
报错 django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory 错误<em>原因</em>: 报这个错误是因为mysql没有装全,mysql的所有rpm包如下: ...
求救贴。。指针异常怎么解决
[img=https://img-bbs.csdn.net/upload/201406/18/1403081244_128931.jpg][/img]rn File pathFile = new File(descDir);rn rn if(!pathFile.exists())rn rn pathFile.mkdirs();rn rn rn rn ZipFile zip = new ZipFile(zipFile);rn rn for(Enumeration entries = (Enumeration) zip.getEntry(descDir);entries.hasMoreElements( );)rn rn ZipEntry entry = (ZipEntry)entries.nextElement();rn rn String zipEntryName = entry.getName( );rn rn InputStream in = zip.getInputStream(entry);rn rn String outPath = (descDir+zipEntryName).replaceAll("\\*", "/");;rnfor的那一行是129行rn File zipFile = new File("e:/压缩.zip");rn rn String path = "e:/zipfile";rnrn unZipFiles(zipFile, path);rn最后那个是219行
指针异常原因分析
/**不懂为什么会引发<em>空</em><em>指针</em><em>异常</em> * Description: * * @author * @version 1.0 */ class Base { public Base() { test(); } public void test() //①号test方法 { Syste
getServletContext()指针异常原因
getServletContext()<em>空</em><em>指针</em><em>异常</em>的<em>原因</em>getServletContext()<em>空</em><em>指针</em><em>异常</em>的<em>原因</em>getServletContext()<em>空</em><em>指针</em><em>异常</em>的<em>原因</em>getServletContext()<em>空</em><em>指针</em><em>异常</em>的<em>原因</em>getServletContext()<em>空</em><em>指针</em><em>异常</em>的<em>原因</em>
指针异常常见原因
<em>空</em><em>指针</em><em>异常</em>出现在对引用类型的操作上,当引用变量指向为<em>空</em>仍然去操作它的方法和属性时。 1、当在栈区声明了引用类型的变量,而未让该引用变量指向堆区的内存时(即只声明未初始化),再操作该引用变量则出<em>空</em><em>指针</em>错。如下例: Map m; //因m没有初始化(m = new HashMap()),所以m仍是<em>空</em><em>指针</em>。 m.get("one"); 2、既声明又初始化了引用变量,但操作该引用变量的语句
Java指针预防
equals方法把确定不是null的作为对象调用,尽量当参数而不是对象使用 String s = null; String m = &amp;amp;quot;s&amp;amp;quot;; //true m.equals(s); //false s.equals(m); 在两者返回相同结果的时候偏向使用valueOf()而非``toString()` double price = getPrice(); System.out.pri...
Java指针捕获
一、<em>空</em><em>指针</em><em>异常</em>产生的主要<em>原因</em>如下:1、当一个对象不存在时又调用其方法会产生<em>异常</em>obj.method() // obj对象不存在;2、当访问或修改一个对象不存在的字段时会产生<em>异常</em>obj.method() // method方法不存在;3、字符串变量未初始化; 4、接口类型的对象没有用具体的类初始化。二、实现思路:1、利用<em>空</em><em>指针</em><em>异常</em>的表现之一:对<em>空</em>字符串进行操作。2、设置一个<em>空</em>的字符串,然后对其进行查...
java指针异常怎么弄啊?
调用showOpenDialog方法弹出的对话框如果我什么都不选直接关掉的话为什么会弹<em>空</em><em>指针</em><em>异常</em>啊。
一次Java指针异常排查经历
同理先说背景:我们的一个注册中心服务,多节点部署,客户端会hash到一个节点,启动定时任务与之通信拉取配置。突然有业务线说客户端大量报超时<em>异常</em>。 首先当然赶紧让业务线把<em>异常</em>日志发给我。先分析了一下日志,<em>找</em>到了对应的超时<em>异常</em>,根据堆栈信息分析出是拉取配置任务大量连续超时,再定位到是哪一台服务。 因为之前线上出现过超时情况,是因为代码效率太低,每个拉取配置的请求要处理将近750ms,导致了请求队列...
java.lang.NullPointerException 指针异常解决
<em>java</em>.lang.NullPointerException com.psger.dao.UserBeanDao.getUserBeanByUsername(UserBeanDao.<em>java</em>:33)
指针异常解决
这个<em>异常</em>都是因为调用null对象的方法 , ,就是一个对象还没有没有正常初始化 就先调用它的方法 比如 Object obj=null; obj.toString(); 这就会抛出 这个<em>异常</em> 今天在写一个struts2的程序的时候出现了这个<em>异常</em>,<em>异常</em>的提示位置是在action的execute方法里面,程序是这样的,表单提交参数给action,然后在execute里面调用这个参数的方法,既然
解决指针异常
笔者在开发安卓的过程中经常遇到<em>空</em><em>指针</em><em>异常</em>的情况:<em>java</em>.lang.NullPointerException举个例子: private ListView listview; private MyAdapter myAdapter; /**列表的数据源*/ private List&amp;lt;String&amp;gt; listData; @Override protected void onCreate...
Java HashMap 指针异常怎么处理
[code=<em>java</em>]package indi.fishing.PlaneGame.PlaneGamev1;rn/**rn * 作者:fishingrn * 创作时间:2018/1/17rn * 更新日期:2018/1/28rn * rn */rnrnimport <em>java</em>x.imageio.ImageIO;rnimport <em>java</em>x.swing.*;rnrnimport <em>java</em>.io.File;rnimport <em>java</em>.io.IOException;rnimport <em>java</em>.util.HashMap;rnimport <em>java</em>.awt.Graphics;rnimport <em>java</em>.awt.Graphics2D;rnimport <em>java</em>.awt.Point;rnimport <em>java</em>.awt.event.KeyAdapter;rnimport <em>java</em>.awt.event.KeyEvent;rnimport <em>java</em>.awt.image.BufferedImage;rnrn@SuppressWarnings("serial")rnpublic class PlaneGame extends JFrame rn /**rn * 作者:fishingrn * 窗口rn */rn public static void main(String[] args) throws IOExceptionrn new PlaneGame();rn rn rn //<em>找</em>到游戏的资源目录rn public static String path1 = System.getProperty("user.dir")+"\\File\\indi\\fishing\\PlaneGame\\photos";rn //存储图片文件rn public static HashMap maps1 = new HashMap<>();rn //加载游戏资源rn staticrn //拿到该目录下面所有的文件rn File[] files1 = new File(path1).listFiles();rn for (int i = 0; i < files1.length; i++)rn //保存起来rn try rn maps1.put(files1[i].getName(),ImageIO.read(files1[i]));rn catch (IOException e) rn e.printStackTrace();rn rn //System.out.println(files[i].getName());rn rn rn /*创建一个构造方法*/rn PlaneGameClassOne jp;rn public PlaneGame()rn //设置标题rn this.setTitle("fishing 打飞机v1");rn //设置窗口居中rn// this.setLocationRelativeTo(null); rn //点击x结束运行rn this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); rn //设置窗体大小rn this.setSize(640, 700);rn //设置窗口不可改动大小rn this.setResizable(false);rn //创建一个小面板rn PlaneGameClassOne jp = new PlaneGameClassOne();rn this.setContentPane(jp);rn this.addKeyListener(new KeyListener());rn //设置窗口可见rn this.setVisible(true);rn rn /**添加一个适配器*/rn class KeyListener extends KeyAdapterrn public void keyPressed(KeyEvent ex) rn jp.keyPressed(ex);rn rn rnrn /**rn * 作者:fishingrn * 容器rn */rnrn@SuppressWarnings("serial")rnclass PlaneGameClassOne extends JPanel //throws NullPointerException rnrn /*按下键盘*/rn public void keyPressed(KeyEvent e) throws NullPointerExceptionrn //键码值rn try rn if(e.getKeyCode() == KeyEvent.VK_W)rn planePoint.y -= 10;rn if(e.getKeyCode() == KeyEvent.VK_S)rn planePoint.y += 10; rn if(e.getKeyCode() == KeyEvent.VK_A)rn planePoint.x -= 10;rn if(e.getKeyCode() == KeyEvent.VK_D)rn planePoint.x += 10;rn rn catch(NullPointerException ex) rn ex.printStackTrace();rn rn repaint();rn rn rn /*初始化坐标*/rn //背景坐标rn Point bgPoint = new Point(0, 0);rn //飞机坐标rn Point planePoint = new Point(270, 550);rn //启动线程rn public PlaneGameClassOne() rn new Thread(new BgThread()).start();rn rn @Overridern public void paint(Graphics g)rn //重叠rn super.paint(g);rn rn //创建一个绘制容器rn BufferedImage image = new BufferedImage(640, 700, BufferedImage.TYPE_INT_RGB);rn //创建一个画笔rn Graphics2D gs = image.createGraphics();rn //绘制背景rn gs.drawImage(PlaneGame.maps1.get("city.jpg"), bgPoint.x, bgPoint.y, this);rn gs.drawImage(PlaneGame.maps1.get("city.jpg"), bgPoint.x, bgPoint.y-715, this);rn //绘制飞机rn gs.drawImage(PlaneGame.maps1.get("plane.jpg"), planePoint.x, planePoint.y, this);rn rn //更新画板rn g.drawImage(image, 0, 0, this);rn rn rn class BgThread implements Runnablern rn @Overridern public void run() rn while (true) rn if(bgPoint.y == 700) rn bgPoint.y = -15;rn rn bgPoint.y += 1;rn try rn Thread.sleep(10);rn catch(InterruptedException ex) rn Thread.currentThread().interrupt();rn rn repaint();rn rn rn rnrn[/code]rn<em>异常</em>:rn[code=<em>java</em>]Exception in thread "AWT-EventQueue-0" <em>java</em>.lang.NullPointerExceptionrn at indi.fishing.PlaneGame.PlaneGamev1.PlaneGame$KeyListener.keyPressed(PlaneGame.<em>java</em>:73)rn at <em>java</em>.awt.Component.processKeyEvent(Component.<em>java</em>:6491)rn at <em>java</em>.awt.Component.processEvent(Component.<em>java</em>:6310)rn at <em>java</em>.awt.Container.processEvent(Container.<em>java</em>:2236)rn at <em>java</em>.awt.Window.processEvent(Window.<em>java</em>:2025)rn at <em>java</em>.awt.Component.dispatchEventImpl(Component.<em>java</em>:4889)rn at <em>java</em>.awt.Container.dispatchEventImpl(Container.<em>java</em>:2294)rn at <em>java</em>.awt.Window.dispatchEventImpl(Window.<em>java</em>:2746)rn at <em>java</em>.awt.Component.dispatchEvent(Component.<em>java</em>:4711)rn at <em>java</em>.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.<em>java</em>:1954)rn at <em>java</em>.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.<em>java</em>:806)rn at <em>java</em>.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.<em>java</em>:1074)rn at <em>java</em>.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.<em>java</em>:945)rn at <em>java</em>.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.<em>java</em>:771)rn at <em>java</em>.awt.Component.dispatchEventImpl(Component.<em>java</em>:4760)rn at <em>java</em>.awt.Container.dispatchEventImpl(Container.<em>java</em>:2294)rn at <em>java</em>.awt.Window.dispatchEventImpl(Window.<em>java</em>:2746)rn at <em>java</em>.awt.Component.dispatchEvent(Component.<em>java</em>:4711)rn at <em>java</em>.awt.EventQueue.dispatchEventImpl(EventQueue.<em>java</em>:758)rn at <em>java</em>.awt.EventQueue.access$500(EventQueue.<em>java</em>:97)rn at <em>java</em>.awt.EventQueue$3.run(EventQueue.<em>java</em>:709)rn at <em>java</em>.awt.EventQueue$3.run(EventQueue.<em>java</em>:703)rn at <em>java</em>.security.AccessController.doPrivileged(Native Method)rn at <em>java</em>.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.<em>java</em>:80)rn at <em>java</em>.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.<em>java</em>:90)rn at <em>java</em>.awt.EventQueue$4.run(EventQueue.<em>java</em>:731)rn at <em>java</em>.awt.EventQueue$4.run(EventQueue.<em>java</em>:729)rn at <em>java</em>.security.AccessController.doPrivileged(Native Method)rn at <em>java</em>.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.<em>java</em>:80)rn at <em>java</em>.awt.EventQueue.dispatchEvent(EventQueue.<em>java</em>:728)rn at <em>java</em>.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.<em>java</em>:201)rn at <em>java</em>.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.<em>java</em>:116)rn at <em>java</em>.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.<em>java</em>:105)rn at <em>java</em>.awt.EventDispatchThread.pumpEvents(EventDispatchThread.<em>java</em>:101)rn at <em>java</em>.awt.EventDispatchThread.pumpEvents(EventDispatchThread.<em>java</em>:93)rn at <em>java</em>.awt.EventDispatchThread.run(EventDispatchThread.<em>java</em>:82)[/code]
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然后一运行程序就报<em>空</em><em>指针</em><em>异常</em>:md.update(str.getBytes());想问问应该怎么修改n
是什么原因,怎么解决?
公司的局域网慢的很.rnrn有几台机器,在没有上网的情况下却一直对外发数据.rnrnsp3 补丁也打了rnsqlserver 2000 补丁也打了rnrn杀毒软件 macfree 也是下载的最新的病毒库.rnrn还是不行啊!rnrn真郁闷!!!
如何解决java指针异常?很急,在线等。
-
Java编程中指针(NullPointerException)的防范经验分享
在写代码的过程中,出现最多的<em>异常</em>可能就是<em>空</em><em>指针</em><em>异常</em>了。说白了,<em>空</em><em>指针</em><em>异常</em>就是你拿一个不存在的对象,去访问它的成员属性或者方法。我们暂且看下面的代码: public static String getString() { return null; } public static void main(String[] args) { // 此处返回null String st...
java指针异常问题 为何会出现指针异常
-
关于Java指针异常的几种情况的总结
1,NullPointerException 由 RuntimeException 派生出来,是一个运行级别的<em>异常</em>。意思是说可能会在运行的时候才会被抛出,而且需要看这样的运行级别<em>异常</em>是否会导致你的业务逻辑中断。 2,<em>空</em><em>指针</em><em>异常</em>发生在对象为<em>空</em>,但是引用这个对象的方法。例如: String s = null; //对象s为<em>空</em>(null) int length = s.length();//发生<em>空</em><em>指针</em>...
java指针异常java.lang.NullPointException原因解决办法
一.什么是<em>java</em><em>空</em><em>指针</em><em>异常</em> 我们都知道<em>java</em>是没有<em>指针</em>的,这里说的&amp;quot;<em>java</em><em>指针</em>&amp;quot;指的就是<em>java</em>的引用,我们不在这里讨论叫<em>指针</em>究竟合不合适,而只是针对这个<em>异常</em>本身进行分析。<em>空</em><em>指针</em>就是<em>空</em>引用,<em>java</em><em>空</em><em>指针</em><em>异常</em>就是引用本身为<em>空</em>,却调用了方法,这个时候就会出现<em>空</em><em>指针</em><em>异常</em>。可以理解,成员变量和方法是属于对象的(除去静态),在对象中才存在相对应的成员变量和方法,然后通过对象去调用这些成员变量和方法...
java指针异常
(position不等于0)rnString temp[] = new String[15];rnif (position!=0)rnfor (int i=0; i < 15; i++) rn temp[i] = ss[i] + ": "+ ss[(position) * 15 + i].replaceAll(" ", "");rn rnrn这怎么就产生<em>空</em><em>指针</em><em>异常</em>了呢?求救啊 各位大神……
osworkflow提示指针异常是什么原因
long flowId=workflow.initialize("DefaultWorkFlow", 100, null);rnrn执行main方法时候到上面那句就包<em>空</em><em>指针</em><em>异常</em>,为什么呢?rn[code=Java]rnpublic static void main(String args[]) throws InvalidActionException, InvalidRoleException, InvalidInputException, InvalidEntryStateException, WorkflowException, MalformedURLExceptionrn Workflow workflow=new BasicWorkflow("mywf");rn Configuration config = new DefaultConfiguration();rn workflow.setConfiguration(config);rn long flowId=workflow.initialize("DefaultWorkFlow", 100, null);rnrn System.out.println(flowId);rn int[] steps = workflow.getAvailableActions(flowId, null);rn System.out.println(steps[0]);rn rn workflow.doAction(flowId, steps[0], null);rn rn System.out.println(workflow.getAvailableActions(flowId, null).length);rn rn[/code]rnrn<em>java</em>.lang.NullPointerExceptionrn at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.<em>java</em>:595)rn at com.yourcompany.struts.Test.main(Test.<em>java</em>:21)rnException in thread "main"
java.lang.NullPointerException 指针异常问题
1.所谓的<em>指针</em>,就是<em>java</em>中的对象的引用。比如String s;这个s就是<em>指针</em>。  2.所谓的<em>空</em><em>指针</em>,就是<em>指针</em>的内容为<em>空</em>,比如上面的s,如果令它指向null,就是<em>空</em><em>指针</em>。 3.所谓的<em>空</em><em>指针</em><em>异常</em>,就是一个<em>指针</em>是<em>空</em><em>指针</em>,你还要去操作它,既然它指向的是<em>空</em>对象,它就不能使用这个对象的方法。比如上面的s假如为null,你还要用s的方法,比如s.equals( String x);那么就会产生<em>空</em><em>指针</em><em>异常</em>
关于Java指针异常的几种情况的总结(java.lang.NullPointerException)
在外文网站上看到的: 1. Calling the instance method of a null object.  2. Accessing or modifying the field of a null object.  3. Taking the length of null as if it were an array.  4. Accessing or modifying 
Java中指针异常及其处理
在Java中,null值可以被分配给一个对象的引用,表示该对象当前正在指向未知的数据。当程序试图访问这个引用时,将会抛出 NullPointerException。 那么如何避免程序抛出<em>空</em><em>指针</em><em>异常</em>? 1、避免去调用可能为null的对象的方法(静态方法除外) String str = null; if(str.equals(&quot;Test&quot;)) { /* The code ...
Java处理指针异常
在Java语言在,null被分配给一个对象的引用以表示对象指向未知数据块。当应用程序使用或访问一个指向null的引用,会被抛出。 下列情况会抛出NullPointerException 。 调用null对象的方法。访问或修改null对象的域。如果null是一个数组,并获取null的长度。如果null对象是一个对象数组,并访问会修改null对象的子元素。如果对象是一个 Throwable值,并抛出n...
这AppCrash怎么解决
[code=C#]rn日志名称: Applicationrn来源: Application Errorrn日期: 2012/10/20 14:38:21rn事件 ID: 1000rn任务类别: (100)rn级别: 错误rn关键字: 经典rn用户: 暂缺rn计算机: USER-4SMCSKGQH0rn描述:rn错误应用程序名称: SMSTask.exe,版本: 1.0.0.0,时间戳: 0x507cf1bern错误模块名称: clr.dll,版本: 4.0.30319.1,时间戳: 0x4ba1d9efrn<em>异常</em>代码: 0xc00000fdrn错误偏移量: 0x00355bc5rn错误进程 ID: 0x19f8rn错误应用程序启动时间: 0x01cdae8d66157173rn错误应用程序路径: D:\new\SMSTask.exern错误模块路径: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dllrn报告 ID: bd566db3-1a80-11e2-90d6-848f69dccfdbrn事件 Xml:rnrn rn rn 1000rn 2rn 100rn 0x80000000000000rn rn 16857825rn Applicationrn USER-4SMCSKGQH0rn rn rn rn SMSTask.exern 1.0.0.0rn 507cf1bern clr.dllrn 4.0.30319.1rn 4ba1d9efrn c00000fdrn 00355bc5rn 19f8rn 01cdae8d66157173rn D:\new\SMSTask.exern C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dllrn bd566db3-1a80-11e2-90d6-848f69dccfdbrn rnrnrn[/code]
这错误怎么解决
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
这怎么解决
[Fatal Error] main.pas(7): Unit DBTables was compiled with a different version of db.TFieldTypern可是我的窗体上没有放dbtables啊
这错误怎么解决
Warning: Section [RegKeys] registry value "Simplified Chinese" contains 1 bytes of data - please verify. If incorrect, the wrong binary format may be in use.rnWarning: Section [RegKeys] registry value "Traditional Chinese" contains 1 bytes of data - please verify. If incorrect, the wrong binary format may be in use.rnWarning: Section [Shortcuts] has no datarnError: CAB file "E:\workplace\TestFrame\Frame2008-240\Frame2008Setup\Debug\Frame2008Setup.CAB" could not be createdrn这错误怎么<em>解决</em>?
这应该怎么解决
用jcreator写<em>java</em>程序,提示错误:package org.apache.struts.action does not exist.我已经把struts.jar文件放到系统的classpath里面,为什么还<em>找</em><em>不到</em>呢?还有就是我下的是struts1.1版本,教材里说的struts.tld文件根本没有,还有那个example也<em>找</em><em>不到</em>啊?
指针错误 java.lang.NullPointerException
<em>空</em><em>指针</em><em>异常</em>,碰见这个错误真是挺恶心的,得去不停的debug。   <em>空</em><em>指针</em>错误 <em>java</em>.lang.NullPointerException   错误<em>原因</em>: 使用基本的JAVA数据类型,变量的值要么已经是默认值,如果没有对其正常赋值,程序便不能通过编译,因此使用基本的JAVA数据类型(double,float,boolean,char,int,long)一般不会引起<em>空</em><em>指针</em><em>异常</em>。由此可见,<em>空</em>...
常见的指针解决办法
1、变量没有初始化 JsonObject config=null; config.put("jdbcUrl","jdbc:postgresql://*.*.*.*:5432/data"); config.put("maximumPoolSize",20); config.put("username","*"); config.put("password","*");
Java中避免指针的几个方法
equals Object类中的equals 方法在非<em>空</em>对象引用上实现相等关系,具有对称性 x.equals(y) 和 y.equals(x) 结果是一样的,但当x == null时会抛出<em>空</em><em>指针</em><em>异常</em> 例如: String x = null; String y = "world"; if(x.equals(y)){ // <em>java</em>.lang.NullPointerException }
关于java指针异常原因解决方法
<em>java</em>中<em>空</em><em>指针</em><em>异常</em>,是一种很常见很普通的错误,初学的时候可能会感觉很难<em>解决</em>,代码写多了就好啦,下面总结一些<em>java</em>中<em>空</em><em>指针</em><em>异常</em>的一些内容。 首先,在开始之前,还是想说,对于一门编程语言,你要了解它的一些知识,不是仅仅会编程就可以了。所以,在了解<em>空</em><em>指针</em><em>异常</em>之前或者之后,还是去看看<em>java</em>中内存的分配的相关内容吧。 <em>指针</em>的概念就不多说了,在面向对象的
Java中equals方法造成指针异常原因解决方案
前言 博主最近在做一个项目的调试工作,期间遇到了一个会导致抛出<em>空</em><em>指针</em><em>异常</em>的小问题,说它是小问题,是因为真的只是在写代码的时候注意一下就好了,但是这里还要写一个博客,就是为了剖析这个问题,然后给自己做个备忘,也给看博客的各位提个醒。 bug描述 迭代1
怎么解决这问题
输出来的时候多了一行。怎么让输出文件与导入文件的行数一样?rn#include "iostream"rn#include "iomanip"rn#include "fstream"rn#include"stdio.h"rn#include"stdlib.h"rn#include"cstring"rn#include"cmath"rnusing namespace std;rnint main()rnrn ifstream ifile("AMM.LHZ.20060801000000.txt");//输入文件rn ofstream ofile("notimepingfang.txt");rnrn char buffer[8];rn char result[16];rn int i=0;rn long temp=0;rn //string s=new string(' ',8);rn double y;rn cout<<>y;//改变次方数yrnrnwhile(!ifile.eof())rn rn rn ifile.getline(buffer,8,'\n');rnrn temp=atol(buffer);rn temp=pow(temp,y);rn sprintf(result,"%d",temp);rn ofile<
这怎么解决啊?
<em>java</em>的下拉列表组件JComboBox中,不能出现同名项,不然重名项选不上。永远只返回第一项。rn 而我现在需要对重名项进行操作,可又选不上,怎么办啊?
请问,这怎么解决
从文本中读取字符到数组,rn我的数组定义的是二维string型的,要将文本中的每一行中的字符串分别读到数组元素中rn,可是每一行的数据全部读到每维的第一个元素中了,这是怎么回事啊?请问高手怎么解rn决?rn文本中每一行当中的字符串是以<em>空</em>格为分隔符的。
这问题怎么解决???
package untitled1;rnimport <em>java</em>.text.DecimalFormat;rnimport <em>java</em>.text.NumberFormat;rnimport <em>java</em>.util.Locale;rnpublic class Untitled1 rn public static void main(String[] args) rnDecimalFormat df = null;rn// 得到一个NumberFormat 对象并rn// 强制转换为一个 DecimalFormat 对象rntry rndf = (DecimalFormat)rnNumberFormat.getInstance(Locale.GERMAN);rnrncatch (ClassCastException e) rnSystem.err.println(e);rnrn// 设置格式模式rndf.applyPattern("###0.00");rn// format a numberrnString aa=df.format(0);rnSystem.out.println(aa);rn//return aa;rnrnrn为什么输出结果会是0,00,不是0.00,怎么<em>解决</em>呢?
Java避免指针
Java避免<em>空</em><em>指针</em> ==== 1.<em>空</em><em>指针</em>引起的<em>原因</em> ---- * 调用<em>空</em>对象的方法 * 访问或更新<em>空</em>对象的变量 * 获取<em>空</em>集合的长度 * 访问或更新<em>空</em>集合中的内容 * 抛出<em>空</em>的Throwable对象 * 同步<em>空</em>对象 2.避免<em>空</em><em>指针</em> ---- 为避免<em>空</em><em>指针</em>,应当在使用之前确保对其做了适当的初始化。 1. 比较字符串时,模板在前,如: > Sting str = null; > if("te
Java 指针异常java.lang.NullPointerException)
Java <em>空</em><em>指针</em><em>异常</em>(<em>java</em>.lang.NullPointerException),顾名思义,即对象没有进行实例化便进行了使用。实例化的意义,就是将对象实例的地址赋值给对象符号。   比如 String a = new String();即在堆中将String的实例构造后,将
Java中如何处理指针异常
英文原文地址:http://examples.<em>java</em>codegeeks.com/<em>java</em>-basics/exceptions/<em>java</em>-lang-nullpointerexception-how-to-handle-null-pointer-exception/?utm_source=tuicool      在Java语言在,null被分配给一个对象的引用以表示对象指向未知数据块。当应用程序使
java指针异常?明明没有显示,却总是错误
我是<em>java</em>初学者,写了个老师给的作业,但是如题,明明都没有红线画出,却总是显示: Exception in thread "main" <em>java</em>.lang.NullPointerException
Java中遇到的报错信息为:指针异常的情况
1、null.equals() 2、定义引用变量,但是没有初始化就直接操作这个变量
这问题怎么解决
这问题怎么<em>解决</em>rn看了下面就应该知道我想要的东西rnrn当我选择“1”的时候我希望显示1的内容rn选择“2”的时候我希望显示2的内容rnrnrnrnrn rn 无标题文档rnrn rnrn rn 选择rn rn rn --请选择--rn 1rn 2rn 3rn rn rn 此处显示 id "a" 的内容rn 此处显示 id "b" 的内容rn 此处显示 id "c" 的内容rnrnrnrnrn
这问题怎么解决
当我按住A键的时候一直输出 aaaaaaa 这时按住A在按B就输出rnaaaaaaaab 这时候我放开B键 但是A键是一直按着的 但是这时候A键失效了 怎么让A键不失效啊 ???rn也有遇到这样问题的人吧
JAVA内存泄露的原因解决
https://juejin.im/post/5c9ccaff6fb9a070fe0ded51
不到 'ndis.h',怎么解决
<em>找</em><em>不到</em> 'ndis.h',怎么<em>解决</em>
不到主方法,怎么解决
同样的一个程序放到不同的项目中,有的能执行,有的就<em>找</em><em>不到</em>主方法。rn程序如下:rnrnpackage com.test;rnrnpublic class Testa rnrn /**rn * @param argsrn */rn public static void main(String args[])rn String rand = "abCd";rn String check = "AbcD";rn if(check.equalsIgnoreCase(rand))rn System.out.println("xiangdeng");rn rn rnrn错误提示:rn<em>java</em>.lang.NoClassDefFoundError: com/test/Testarn弹出提示:rnCould not find the main class.Progeram will exit.rn补充说明:rn写了这么多程序还没遇见过这样的问题,明明有主方法,jvm却硬说没有。页面在其他项目里也可以执行。会不会是这个项目有什么问题呀?
不到原因!!
我刚配了一台电脑,装的是XP的系统,每次开机的时候鼠标光标在,可是移动鼠标却不动,只有拔下来重插才可以。换了2000的系统,连光标都没有了,请问各位高手是什么问题?rn
不到原因
我做了一个Applet小程序。程序是这样的:通过访问数据库,取得数据,然后在小程序中根据取得的数据绘制曲线,引用了Graphics2D,所以安装了j2re.(其中数据库是Access数据库,通过建立一数据库名为数据源的ODBC访问的)。这个程序在AppletViewer中运行正常,但是嵌入IE后,就不能正常运行了,<em>原因</em>是访问被拒绝,也就是数据库不能访问了,这个问题怎么<em>解决</em>!
不到原因
我在程序中用了EHlib4.0,在DbGridEh中无论怎么设置title为那种对齐方式都是居中对齐rn当使用sumlist的时候,将footer的valuetype设置成fvtavg的时候总是一次查询能显示结果,第二次就报ADOQ: Field 'PH' not found.我把控件删除了重新装也不行rnrnrn
java编译不到符号,怎么解决???
[img=https://img-bbs.csdn.net/upload/201401/16/1389853675_543150.png][/img]
指针异常...为什么...没
报错信息rn[img=https://img-bbs.csdn.net/upload/201805/08/1525744764_104173.jpg][/img]rn报错类的位置rn[img=https://img-bbs.csdn.net/upload/201805/08/1525744780_808737.jpg][/img]rn已经注入了rn[img=https://img-bbs.csdn.net/upload/201805/08/1525744797_766844.jpg][/img]rndaorn[img=https://img-bbs.csdn.net/upload/201805/08/1525744817_235736.jpg][/img]rnservicern[img=https://img-bbs.csdn.net/upload/201805/08/1525744841_517548.jpg][/img]rnxmlrn[img=https://img-bbs.csdn.net/upload/201805/08/1525744852_647306.jpg][/img]
求帮助,不到哪个指针异常。。。。
[color=#FF0000]下面的代码报错提示为<em>空</em><em>指针</em><em>异常</em>,但是没有<em>找</em>到,请大家帮忙看下~[/color][color=#FF0000][/color]rnrnpackage com.googlemap;rnrnimport android.content.Context;rnimport android.content.Intent;rnimport android.content.SharedPreferences;rnimport android.content.res.Resources;rnimport android.database.Cursor;rnimport android.graphics.Canvas;rnimport android.graphics.Paint;rnimport android.graphics.Point;rnimport android.graphics.RectF;rnimport android.graphics.Paint.Style;rnimport android.location.Location;rnimport android.location.LocationListener;rnimport android.location.LocationManager;rnimport android.os.Bundle;rnimport android.util.Log;rnimport android.view.KeyEvent;rnimport android.view.Menu;rnimport android.view.MenuItem;rnimport android.view.View;rnimport android.view.View.OnClickListener;rnimport android.widget.Button;rnimport android.widget.Toast;rnrnimport com.google.android.maps.GeoPoint;rnimport com.google.android.maps.MapActivity;rnimport com.google.android.maps.MapController;rnimport com.google.android.maps.MapView;rnimport com.google.android.maps.MyLocationOverlay;rnimport com.google.android.maps.Overlay;rnimport com.googlemap.R;rnrnpublic class ShowTrack extends MapActivity rn // 定义菜单需要的常量rn private static final int MENU_NEW = Menu.FIRST + 1;rn private static final int MENU_CON = MENU_NEW + 1;rn private static final int MENU_DEL = MENU_CON + 1;rn private static final int MENU_MAIN = MENU_DEL + 1;rnrn private TrackDbAdapter mDbHelper;rn private LocateDbAdapter mlcDbHelper;rnrn private static final String TAG = "ShowTrack";rn private static MapView mMapView;rn private MapController mc;rnrn protected MyLocationOverlay mOverlayController;rn private Button mZin;rn private Button mZout;rn private Button mPanN;rn private Button mPanE;rn private Button mPanW;rn private Button mPanS;rn private Button mGps;rn private Button mSat;rn private Button mTraffic;rn private Button mStreetview;rn private String mDefCaption = "";rn private GeoPoint mDefPoint;rnrn private LocationManager lm;rn private LocationListener locationListener;rnrn private int track_id;rn private Long rowId;rnrn /** Called when the activity is first created. */rn public void onCreate(Bundle icicle) rn super.onCreate(icicle);rn setContentView(R.layout.show_track);rn findViews();rn centerOnGPSPosition();rn revArgs();rn // ///////////////rn //mDbHelper = new TrackDbAdapter(this);rn //mDbHelper.open();rnrn //mlcDbHelper = Track.getDbHelp();rn //new LocateDbAdapter(this);rn //mlcDbHelper.open();rnrn paintLocates();rn startTrackService();rn rnrn private void startTrackService() rn Intent i = new Intent("com.iceskysl.iTracks.START_TRACK_SERVICE");rn i.putExtra(LocateDbAdapter.TRACKID, track_id);rn startService(i); rn rn rn private void stopTrackService() rn stopService(new Intent("com.iceskysl.iTracks.START_TRACK_SERVICE")); rn rnrn private void paintLocates() rn mlcDbHelper = new LocateDbAdapter(this);rn mlcDbHelper.open();rn Cursor mLocatesCursor = mlcDbHelper.getTrackAllLocates(track_id);rn startManagingCursor(mLocatesCursor);rn Resources resources = getResources();rn Overlay overlays = new LocateOverLay(resourcesrn .getDrawable(R.drawable.icon), mLocatesCursor);rn mMapView.getOverlays().add(overlays);rn mlcDbHelper.close();rn rnrn private void revArgs() rn Log.d(TAG, "revArgs.");rn Bundle extras = getIntent().getExtras();rn if (extras != null) rn String name = extras.getString(TrackDbAdapter.NAME);rn //String desc = extras.getString(TrackDbAdapter.DESC);rn rowId = extras.getLong(TrackDbAdapter.KEY_ROWID);rn track_id = rowId.intValue();rn Log.d(TAG, "rowId=" + rowId);rn if (name != null) rn setTitle(name);rn rn rn rnrn protected boolean isRouteDisplayed() rn // TODO Auto-generated method stubrn return false;rn rnrn private void findViews() rn Log.d(TAG, "find Views");rn // Get the map view from resource filern mMapView = (MapView) findViewById(R.id.mv);rn mc = mMapView.getController();rnrn SharedPreferences settings = getSharedPreferences(Setting.SETTING_INFOS, 0);rn String setting_gps = settings.getString(Setting.SETTING_MAP, "10");rn mc.setZoom(Integer.parseInt(setting_gps));rnrn // Set up the button for "Pan East"rn mPanE = (Button) findViewById(R.id.sat);rn mPanE.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn panEast();rn rn );rn // Set up the button for "Zoom In"rn mZin = (Button) findViewById(R.id.zin);rn mZin.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn zoomIn();rn rn );rn // Set up the button for "Zoom Out"rn mZout = (Button) findViewById(R.id.zout);rn mZout.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn zoomOut();rn rn );rn // Set up the button for "Pan North"rn mPanN = (Button) findViewById(R.id.pann);rn mPanN.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn panNorth();rn rn );rnrn // Set up the button for "Pan East"rn mPanE = (Button) findViewById(R.id.pane);rn mPanE.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn panEast();rn rn );rnrn // Set up the button for "Pan West"rn mPanW = (Button) findViewById(R.id.panw);rn mPanW.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn panWest();rn rn );rn // Set up the button for "Pan South"rn mPanS = (Button) findViewById(R.id.pans);rn mPanS.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn panSouth();rn rn );rnrn // Set up the button for "GPS"rn mGps = (Button) findViewById(R.id.gps);rn mGps.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn centerOnGPSPosition();rn rn );rn // Set up the button for "Satellite toggle"rn mSat = (Button) findViewById(R.id.sat);rn mSat.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn toggleSatellite();rn rn );rnrn // Set up the button for "Traffic toggle"rn mTraffic = (Button) findViewById(R.id.traffic);rn mTraffic.setOnClickListener(new OnClickListener() rn // @Overridern public void onClick(View arg0) rn toggleTraffic();rn rn );rnrn
android多线程出现指针异常怎么解决
一个activity里面有2个网络请求,但是其中一个网络请求的参数是根据另外一个网络请求获得的数据决定的,这两个网络请求要怎么写,我这么写出现了<em>空</em><em>指针</em><em>异常</em>,下面是代码rn[code=<em>java</em>]public void getPartNum() rn final String url = "http://" + Constant.IP_ADDRESS + ":8081/FightLandlordServer/getGroupPeopleInfo.jsp";rn final Map map = new HashMap<>();rn String groupName = spGroup.getSelectedItem().toString();rn map.put("groupName", groupName);rnrn new Thread() rn @Overridern public void run() rn String result = HttpConnection.doPostWithParams(url, map, "gbk");rn Bundle bundle = new Bundle();rn bundle.putString("tempMsg", result);rn Message message = new Message();rn message.what = Constant.GET_GROUP_PEOPLE;rn message.setData(bundle);rn handler.sendMessage(message);rn rn .start();rn rnrn //获取分组信息rn public void getGroup()rn final String url = "http://" + Constant.IP_ADDRESS + ":8081/FightLandlordServer/getGroupInfo.jsp";rn final Map map = new HashMap<>();rn map.put("groupName", "groupName");rnrn new Thread()rn @Overridern public void run()rn String result = HttpConnection.doPostWithParams(url, map, "gbk");rn Bundle bundle = new Bundle();rn bundle.putString("tempMsg", result);rn Message message = new Message();rn message.what=Constant.GET_NOT_NULL;rn message.setData(bundle);rn handler.sendMessage(message);rn rn .start();rn [/code]rn就是下面那个请求是获取分组的,然后将这些分组信息添加到Spinner中,然后上面的那个就是从Spinner中选择分组信息,再根据所选择的分组信息获取相对应的组员信息,怎样避免这个<em>空</em><em>指针</em>问题
这个指针异常实在不知道怎么解决
<em>java</em>.lang.NullPointerExceptionrn at sunyang.dao.BaseDAO.getSession(BaseDAO.<em>java</em>:18)rn at sunyang.dao.impl.ForumDAO.countBack(ForumDAO.<em>java</em>:94)rn at sunyang.dao.impl.ReforumDAO.delete(ReforumDAO.<em>java</em>:86)rn at sunyang.service.ForumService.deleteReforum(ForumService.<em>java</em>:82)rn at sunyang.action.ForumAction.deleteReforum(ForumAction.<em>java</em>:141)rnrn下面是按报错的顺序的代码rnrn[code=Java]public class BaseDAO rn private SessionFactory sessionFactory;rnrn public SessionFactory getSessionFactory() rn return sessionFactory;rn rnrn public void setSessionFactory(SessionFactory sessionFactory) rn this.sessionFactory = sessionFactory;rn rnrn public Session getSession() rn Session session = sessionFactory.openSession();rn return session;rn rn[/code]rn[code=Java] public Integer countBack(int forum_id) rn Session session = getSession();rn String hql = "select forum.countback from Forum forum where forum.id=?";rn Query query = session.createQuery(hql);rn query.setParameter(0, forum_id);rn List coutbacklist = query.list();rn session.close();rn int coutback = (Integer) coutbacklist.get(0);rn return coutback;rn [/code]rnrn[code=Java] public boolean delete(int reforum_id, int forum_id) rn try rn String hql = "delete from Reforum reforum where reforum.id="+reforum_id;rn Session session = getSession();rn Transaction tx = session.beginTransaction();rn Query querydeleteReforum = session.createQuery(hql);rn int b=querydeleteReforum.executeUpdate();rn tx.commit();rn session.close();rn ForumDAO fdao = new ForumDAO();rn int countback = fdao.countBack(forum_id);rn fdao.removeCountBack(countback, forum_id);rn if (b != 0) rn return true;rn else rn return false;rn rnrn catch (Exception e) rn e.printStackTrace();rn rn return false;rn [/code]rnrn[code=Java] public void deleteReforum(int reforum_id, int forum_id) rn try rn rfdao.delete(reforum_id, forum_id);rn catch (Exception e) rn e.printStackTrace();rn rn [/code]rnrn[code=Java] public String deleteReforum() rn try rn //Map request = (Map) ActionContext.getContext().get("request");rn forumservice.deleteReforum(Integer.parseInt(request.getParameter("reforum_id")),rn Integer.parseInt(request.getParameter("forum_id")));rn forum_id = Integer.parseInt(request.getParameter("forum_id"));rnrn catch (Exception e) rn e.printStackTrace();rn rn return "success";rn [/code]rnrn其他的action也是这么用的没问题,就这个有问题,比较郁闷,这个rn[code=Java] public Session getSession() rn Session session = sessionFactory.openSession();rn return session;rn [/code]rnSession是从sessionFactory得到的,这个<em>异常</em>是sessionFactory里产生的?
web工程login时提示指针异常,怎么解决
<em>异常</em>信息:严重: Servlet.service() for servlet jsp threw exceptionrn<em>java</em>.lang.NullPointerExceptionrn at org.apache.jsp.check_jsp._jspService(check_jsp.<em>java</em>:72)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.<em>java</em>:70)rn at <em>java</em>x.servlet.http.HttpServlet.service(HttpServlet.<em>java</em>:717)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.<em>java</em>:388)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.<em>java</em>:313)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.<em>java</em>:260)rn at <em>java</em>x.servlet.http.HttpServlet.service(HttpServlet.<em>java</em>:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.<em>java</em>:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.<em>java</em>:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.<em>java</em>:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.<em>java</em>:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.<em>java</em>:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.<em>java</em>:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.<em>java</em>:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.<em>java</em>:293)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.<em>java</em>:859)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.<em>java</em>:602)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.<em>java</em>:489)rn at <em>java</em>.lang.Thread.run(Thread.<em>java</em>:619)rn2012-4-29 10:59:08 org.apache.catalina.core.StandardWrapperValve invokern下面的是源码:rnrnrnrnrn rn 验证页面rnrnrn rn 密码: rn 确认密码: rn 性别: rn 职业: rn 个人爱好:rnrn
指针异常怎么解决,刚学java求指教
package com.db;rnrnimport com.bean.CardBean;rnimport <em>java</em>.sql.*;rnimport <em>java</em>.util.ArrayList;rnimport <em>java</em>.util.List;rnrnpublic class CardDBrn rn private String dbDriver = "com.mysql.jdbc.Driver";rn private String dbUrl = "jdbc:mysql://localhost:3306/telcard?characterEncoding=utf8";rn private String dbUser ="root";rn private String dbPass ="123456";rn rn private Connection getDBConn()rn rn Connection conn = null;rn try rn Class.forName(dbDriver);rn conn = DriverManager.getConnection(dbUrl,dbUser,dbPass);rn catch (Exception e) rn rn e.printStackTrace();rn rn return conn;rn rn rn public int addOneCard(CardBean card) rnrn int i = 0;rn String sql = "insert into card values(?,?,?,?)";rn Connection conn = getDBConn();rn try rn PreparedStatement preStmt = conn.prepareStatement(sql);rn preStmt.setString(1, card.getCardId());rn preStmt.setString(2, card.getCardType());rn preStmt.setString(3, card.getMoney());rn preStmt.setString(4, card.getCardArea());rnrn i = preStmt.executeUpdate();rn catch (SQLException e) rn e.printStackTrace();rn rn return i;rnrn rnrn public int deleteOneCard(String cardID) rn int i = 0;rn String sql = "delete from card where CardID='"+cardID+"'";rn Connection cnn = getDBConn();rn try rn Statement stmt = cnn.createStatement();rn i = stmt.executeUpdate(sql);rn catch (SQLException e) rn e.printStackTrace();rn rn return i;rn rnrn public int updateOneCard(CardBean card) rn int i = 0;rn String sql = "update card set CardType=?,Money=?,CardArea=? where CardID='"rn + card.getCardId()+"'";rn Connection cnn = getDBConn();rn try rn PreparedStatement preStmt = cnn.prepareStatement(sql);rn preStmt.setString(1, card.getCardType());rn preStmt.setString(2, card.getMoney());rn preStmt.setString(3, card.getCardArea());rn i = preStmt.executeUpdate();rn catch (SQLException e) rn e.printStackTrace();rn rn return i;rn rnrn public List findCardById(String cardID) rn List cards = new ArrayList();rn String sql = "select * from card where CardID like '%"+cardID+"%'";rn Connection cnn =getDBConn();rn try rn Statement stmt = cnn.createStatement();rn ResultSet rs = stmt.executeQuery(sql);rn while(rs.next())rn CardBean card = new CardBean();rn card.setCardId(rs.getString(1));rn card.setCardType(rs.getString(2));rn card.setMoney(nullToString(rs.getString(3)));rn card.setCardArea(nullToString(rs.getString(4)));rn cards.add(card);rn rn catch (SQLException e) rn e.printStackTrace();rn rn return cards;rn rnrn rn private String nullToString(Object obj )rn if(null == obj)rn return "";rn rn return String.valueOf(obj);rn rnrnrn[img=https://img-bbs.csdn.net/upload/201610/11/1476146406_583312.png][/img]
一个指针异常,不知道怎么解决,帮帮忙
代码:rnString gh = rs.getString(3);rnIUserInfoDao userdao = new UserInfoDao();rnIUserInfo clr = userdao.findByGh(gh);rnString xm = clr.getXm();rnrnroot cause rn<em>java</em>.lang.NullPointerExceptionrn org.apache.jsp.TSFAczshow_jsp._jspService(TSFAczshow_jsp.<em>java</em>:235)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.<em>java</em>:97)rn <em>java</em>x.servlet.http.HttpServlet.service(HttpServlet.<em>java</em>:802)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.<em>java</em>:334)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.<em>java</em>:314)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.<em>java</em>:264)rn <em>java</em>x.servlet.http.HttpServlet.service(HttpServlet.<em>java</em>:802)rnrn
Android Studio指针异常,怎么解决啊???
13:12:16.142 14848-14848/cn.eoe.handclock E/AndroidRuntime: FATAL EXCEPTION: mainrn[b]<em>java</em>.lang.NullPointerExceptionrn at cn.eoe.handclock.widget.HandClock.onMeasure(HandClock.<em>java</em>:36)[/b]rn at android.view.View.measure(View.<em>java</em>:12723)rn at android.view.ViewGroup.measureChildWithMargins(ViewGroup.<em>java</em>:4698)rn at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.<em>java</em>:1369)rn at android.widget.LinearLayout.measureVertical(LinearLayout.<em>java</em>:660)rn at android.widget.LinearLayout.onMeasure(LinearLayout.<em>java</em>:553)rn at android.view.View.measure(View.<em>java</em>:12723)rn at android.view.ViewGroup.measureChildWithMargins(ViewGroup.<em>java</em>:4698)rn at android.widget.FrameLayout.onMeasure(FrameLayout.<em>java</em>:293)rn at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.<em>java</em>:141)rn at android.view.View.measure(View.<em>java</em>:12723)rn at android.view.ViewGroup.measureChildWithMargins(ViewGroup.<em>java</em>:4698)rn at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.<em>java</em>:400)rn at android.view.View.measure(View.<em>java</em>:12723)rn at android.view.ViewGroup.measureChildWithMargins(ViewGroup.<em>java</em>:4698)rn at android.widget.FrameLayout.onMeasure(FrameLayout.<em>java</em>:293)rn at android.view.View.measure(View.<em>java</em>:12723)rn at android.view.ViewGroup.measureChildWithMargins(ViewGroup.<em>java</em>:4698)rn at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.<em>java</em>:1369)rn at android.widget.LinearLayout.measureVertical(LinearLayout.<em>java</em>:660)rn at android.widget.LinearLayout.onMeasure(LinearLayout.<em>java</em>:553)rn at android.view.View.measure(View.<em>java</em>:12723)rn at android.view.ViewGroup.measureChildWithMargins(ViewGroup.<em>java</em>:4698)rn at android.widget.FrameLayout.onMeasure(FrameLayout.<em>java</em>:293)rn at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.<em>java</em>:2092)rn at android.view.View.measure(View.<em>java</em>:12723)rn at android.view.ViewRootImpl.performTraversals(ViewRootImpl.<em>java</em>:1064)rn at android.view.ViewRootImpl.handleMessage(ViewRootImpl.<em>java</em>:2442)rn at android.os.Handler.dispatchMessage(Handler.<em>java</em>:99)rn at android.os.Looper.loop(Looper.<em>java</em>:137)rn at android.app.ActivityThread.main(ActivityThread.<em>java</em>:4424)rn at <em>java</em>.lang.reflect.Method.invokeNative(Native Method)rn at <em>java</em>.lang.reflect.Method.invoke(Method.<em>java</em>:511)rn at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.<em>java</em>:784)rn at com.android.internal.os.ZygoteInit.main(ZygoteInit.<em>java</em>:551)rn at dalvik.system.NativeStart.main(Native Method)rnrn[b]HandClock源代码:[/b]rnpackage cn.eoe.handclock.widget;rnrnimport android.annotation.SuppressLint;rnimport android.content.Context;rnimport android.graphics.Bitmap;rnimport android.graphics.BitmapFactory;rnimport android.graphics.Canvas;rnimport android.graphics.Paint;rnimport android.graphics.Rect;rnimport android.os.Handler;rnimport android.util.AttributeSet;rnimport android.view.View;rnrnimport <em>java</em>.util.Calendar;rnrnpublic class HandClock extends View implements Runnable rn private Bitmap bitmap;rn private float scale;rn private float handCenterWidthScale;rn private float handCenterHeightScale;rn private int minuteHandSize;rn private int hourHandSize;rn private Handler handler=new Handler();rnrn @Overridern public void run() rn //重新绘制viewrn invalidate();rn //重新设置定时器,在60s后调用run方法rn handler.postDelayed(this,60*1000);rn rn @Overridern protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) rn super.onMeasure(widthMeasureSpec, heightMeasureSpec);rn [b] setMeasuredDimension((int) (bitmap.getWidth() * scale),rn (int) (bitmap.getHeight() * scale));]//这里:<em>java</em>.lang.NullPointerExceptionrn at cn.eoe.handclock.widget.HandClock.onMeasure(HandClock.<em>java</em>:36)[/b]rn rn @Overridern protected void onDraw(Canvas canvas) rn super.onDraw(canvas);rn @SuppressLint("DrawAllocation") Paint paint=new Paint();rn @SuppressLint("DrawAllocation") Rect src=new Rect();rn @SuppressLint("DrawAllocation") Rect target=new Rect();rn src.left=0;rn src.top=0;rn src.right=bitmap.getWidth();rn src.bottom=bitmap.getHeight();rnrn target.left=0;rn target.top=0;rn target.bottom=(int)(src.bottom*scale);rn target.right=(int)(src.right*scale);rn //画表盘图像rn canvas.drawBitmap(bitmap,src,target,paint);rn //计算表盘中心点的横纵坐标rn float centerX=bitmap.getWidth()*scale*handCenterWidthScale;rn float centerY=bitmap.getHeight()*scale*handCenterHeightScale;rn //表盘中心点画一个半径为5的实心圆圈rn canvas.drawCircle(centerX,centerY,5,paint);rn //设置分针为3个像素粗rn paint.setStrokeWidth(3);rn Calendar calendar=Calendar.getInstance();rn int currentMinute=calendar.get(Calendar.MINUTE);rn int currentHour=calendar.get(Calendar.HOUR);rn //计算分针和时间的弧度rn double minuteRadian=Math.rn toRadians((360-((currentMinute*6)-90))%360);rn double hourRadian=Math.rn toRadians((360-((currentHour*30)-90))%360-(30*currentMinute/60));rn //在表盘上画分针rn canvas.drawLine(centerX,centerY,(int)(centerX+minuteHandSize*Math.rn cos(minuteRadian)),(int)(centerY-minuteHandSize*Math.sin(minuteRadian)),rn paint);rn //设置时针为4个像素粗rn paint.setStrokeWidth(4);rn //在表盘上画时针rn canvas.drawLine(centerX,centerY,rn (int)(centerX+hourHandSize*Math.cos(hourRadian)),rn (int)(centerY-hourHandSize*Math.sin(hourRadian)),paint);rn rnrn public HandClock(Context context,AttributeSet attrs) rn super(context, attrs);rn //读取相应的属性值rn int clockImageResourceId = attrs.getAttributeResourceValue(null,rn "clockImageSrc", 0);rn if (clockImageResourceId >0) rn bitmap = BitmapFactory.decodeResource(getResources(), clockImageResourceId);rn scale = attrs.getAttributeFloatValue(null, "scale", 1);rn handCenterWidthScale = attrs.getAttributeFloatValue(null,rn "handCenterWidthScale", bitmap.getWidth() / 2);rn handCenterHeightScale = attrs.getAttributeFloatValue(null,rn "handCenterHeightScale", bitmap.getHeight() / 2);rn //在读取分针和时针长度后,将其值按图像的缩放比例进行缩放rn minuteHandSize = (int) (attrs.getAttributeIntValue(null,rn "minuteHandSize", 0) * scale);rn hourHandSize = (int) (attrs.getAttributeIntValue(null,rn "hourHandSize", 0) * scale);rn int currentSecond = Calendar.getInstance().get(Calendar.SECOND);rn //将定时器设在0分钟时执行run方法rn handler.postDelayed(this, (60 - currentSecond) * 1000);rn rn rnrn @Overridern protected void onDetachedFromWindow() rn super.onDetachedFromWindow();rn //删除回调类rn handler.removeCallbacks(this);rn rnrn[b]Mainactivity:[/b]rnpackage cn.eoe.handclock;rnrnimport android.content.Intent;rnimport android.os.Bundle;rnimport android.support.v7.app.AppCompatActivity;rnimport android.view.View;rnimport android.widget.Button;rnrnimport cn.eoe.handclock.widget.TestHandClock1;rnimport cn.eoe.handclock.widget.TestHandClock2;rnrnpublic class MainActivity extends AppCompatActivity implements View.OnClickListener rn @Overridern public void onClick(View v) rn Intent intent;rn switch (v.getId()) rn case R.id.btnHandClock1:rn intent = new Intent(this, TestHandClock1.class);rn startActivity(intent);rn break;rn case R.id.btnHandClock2:rn intent = new Intent(this, TestHandClock2.class);rn startActivity(intent);rn break;rn rn rn protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.main);rn Button btnHandClock1=findViewById(R.id.btnHandClock1);rn Button btnHandClock2=findViewById(R.id.btnHandClock2);rn btnHandClock1.setOnClickListener(this);rn btnHandClock2.setOnClickListener(this);rn rnrn[b]rnmainXML文件:[/b]rnrnrnrnrnrn[b]HandClock1Xml文件:[/b]rnrnrnrn rnrnrnrn编译都显示没问题,运行起来就变成了这样子rn[img=https://img-bbs.csdn.net/upload/201902/17/1550412252_348766.png][/img]rn[img=https://img-bbs.csdn.net/upload/201902/17/1550412271_645443.png][/img]rnrn那位大哥大姐能解解惑吗???
指针异常了好久都不知道怎么解决
[code=<em>java</em>]rnrnimport <em>java</em>.awt.*;rnimport <em>java</em>x.swing.*;rnrnpublic class ceshi extends JFrame rnrnprivate static final int PRE_WIDTH = 500;rnprivate static final int PRE_HEIGTH = 400;rnprivate String []mOp = "MC", "MR", "MS", "M+";rnrnrnceshi()rnrn initislize();rnrnvoid initislize()rnrn this.setTitle("计算器");rn this.setResizable(false);rn setBounds(400, 400, 500, 500); rnrn JPanel panel = new JPanel();rn panel.setLayout(new BorderLayout(10,1)); //BorderLayout中各区域相邻控件的间隔rn panel.setPreferredSize(new Dimension(PRE_WIDTH, PRE_HEIGTH));rnrnrntryrnrn JButton [] mButton = getMButton(); [color=#FF0000]//就是这里有问题[/color]rn JPanel panel1 = new JPanel();rn panel1.setLayout(new GridLayout(5,1,0,5));rn for(JButton b: mButton)rn panel1.add(b);rn panel.add(panel1, BorderLayout.WEST);rnrncatch(NullPointerException e)rnrn System.out.println("又<em>异常</em>了,怎么做");rnrnrnrnrnrnrnadd(panel);rnrnsetVisible(true);rnvalidate();rnrnrnrn//创建左侧操作按件rnJButton [] getMButton()rnrnJButton [] result = new JButton[mOp.length];rnrnfor(int i = 0; i
大神帮忙看下这个 指针异常 怎么解决 
<em>java</em>.lang.NullPointerExceptionrnat com.ids.emr.client.technician.shared.models.plan.orderlabtest.OrderLabExaminationModel.getDisplayName(OrderLabExaminationModel.<em>java</em>:114)rnat com.ids.emr.client.technician.shared.models.plan.orderlabtest.OrderLabExaminationModel.toString(OrderLabExaminationModel.<em>java</em>:134)rnrn @Overridern    public String getDisplayName() rn return labExam.getDisplayName() + " - " + labTestTime.getDisplayName();rn rnrn
指针异常!感谢解决
package pagination;rnimport <em>java</em>.util.List;rnimport org.springframework.orm.hibernate3.HibernateTransactionManager;rnimport com.session.local.HibernateSessionFactory;rnrn/**rn * @author rn *rn */rnrn数据库分页基类:rnpublic abstract class Pagination rn private String sql;rn public final int pageSize=2; // 每页显示的行数rn private int rowsCount; // 总行数rn private int pagesCount; // 总页数rn private HibernateTransactionManager transactionManager;rn public void setTransactionManager(HibernateTransactionManager transactionManager)rn rn this.transactionManager=transactionManager;rn rn rnrn // 在设置SQL语句时计算总行数和总页数,rn // 这样总行数只要查询一次,可以提高效率!rn public void setSQL(String sql) rn this.sql = sql;rn rn // 获取总行数并计算总页数rn this.rowsCount = countRows();rn this.pagesCount = countPages();rn rnrn public String getSQL() rn return sql;rn rnrnrn public int getRowsCount() rn return rowsCount;rn rnrn public int getPagesCount() rn return pagesCount;rn rnrn public List getPage(int page) rn rn List list = HibernateSessionFactory.getSession().createQuery(this.sql)rn .setFirstResult((page-1)*pageSize)rn .setMaxResults(pageSize) .list(); rn return list;rn rn rn //计算总记录数rn private int countRows() rn String countSql = this.sql;rn int fromPos = countSql.indexOf(" from ");rn countSql = countSql.substring(fromPos);rn countSql = "select count(*) " + countSql;rn List list= HibernateSessionFactory.getSession().createQuery(countSql).list();rn int count =(Integer)list.get(0);rn return count;rn rnrn // 计算总页数rn private int countPages() rn if ((rowsCount % pageSize) == 0) rn return rowsCount / pageSize;rn else rn return (rowsCount /pageSize + 1);rn rn rnrn rn rnrnrn public String execute() rn ActionContext context = ActionContext.getContext();rn HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);rn String action = request.getParameter("action");rn if (action.equals("0")) rn String sql="select * from Users";rn<em>空</em><em>指针</em><em>异常</em>: uado.setSQL(sql);rn List users =uado.getPage(1);// 获取当前页码的用户记录rn request.setAttribute("users", users);rn request.setAttribute("pageSize", uado.pageSize);// 每页显示的行数rn request.setAttribute("rowscount", uado.getRowsCount());// 总记录数rn request.setAttribute("pageno", 1);// 当前页码rn request.setAttribute("pagescount",uado.getPagesCount());// 总页数rn rn
解决listView.setAdapter()出现指针异常
<ListView
指针异常解决
[img=https://img-bbs.csdn.net/upload/201705/15/1494819049_934679.png][/img]rn效果图中是在listview显示数据,点击导航栏的“首页”在点击“发现”,listview数据没加载出来时我再次点击首页是正常的我再一次点击“发现”就闪退了 <em>空</em><em>指针</em><em>异常</em>’
一个指针异常,求解决
package com.example.checkapplication;rnimport <em>java</em>.util.ArrayList;rnimport <em>java</em>.util.List;rnimport android.app.Activity;rnimport android.app.ActivityManager;rnimport android.os.Bundle;rnimport android.view.View;rnimport android.widget.AdapterView;rnimport android.widget.ArrayAdapter;rnimport android.widget.Button;rnimport android.widget.ListView;rnimport android.widget.Toast;rnpublic class MainActivity extends Activity rnprivate ActivityManager mActivityManager;rnprivate int intGetTastCounter = 30;rnpublic Button mButton1;rnpublic ListView mListView1;rnpublic ArrayList arylistTask;rn@Overridernprotected void onCreate(Bundle savedInstanceState) rnsuper.onCreate(savedInstanceState);rnsetContentView(R.layout.main);rnmButton1 = (Button)findViewById(R.id.button1);rnmListView1 = (ListView)findViewById(R.id.list);rnmButton1.setOnClickListener(new Button.OnClickListener()rnrnrn@Overridernpublic void onClick(View v) rn// TODO Auto-generated method stubrntryrn//j对象向系统取得ACTIVITY_SERVICErnmActivityManager = (ActivityManager)rnMainActivity.this.getSystemService(ACTIVITY_SERVICE);rnarylistTask = new ArrayList();rnListmRunningTasks =rnmActivityManager.getRunningTasks(intGetTastCounter);rnint i = 1;rnfor(ActivityManager.RunningTaskInfo amTask:mRunningTasks)rnarylistTask.add(""+(i++)+": "+rnamTask.baseActivity.getClassName()+"(ID=" + amTask.id +")");rnrnArrayAdapter aryAdapter1 = new ArrayAdapterrn(MainActivity.this,R.layout.simple_list_item_1,arylistTask);rnif(aryAdapter1.getCount()==0)rnmMakeTextToast(rngetResources().getTextrn(R.string.str_err_no_running_task).toString(),true);rnrnrnelse rnmListView1.setAdapter(aryAdapter1);rnrnrncatch(SecurityException e)rnmMakeTextToast(rngetResources().getText(R.string.str_err_permission).toString(),truern);rnrnrnrnrnprivate void mMakeTextToast(String str, boolean islong) rn// TODO Auto-generated method stubrnif(islong==true)rnToast.makeText(MainActivity.this,str, Toast.LENGTH_LONG).show();rnrnelsernToast.makeText(MainActivity.this,str, Toast.LENGTH_SHORT).show();rnrnrnrn);rnmListView1.setOnItemSelectedListenerrn(new ListView.OnItemSelectedListener()rnrnrn@Overridernpublic void onItemSelected(AdapterView parent, View v,rnint id, long arg3) rn// TODO Auto-generated method stubrnmMakeTextToast(arylistTask.get(id).toString(),false);rnrnrnrnrnrnprivate void mMakeTextToast(String str, boolean islong) rn// TODO Auto-generated method stubrnif(islong==true)rnToast.makeText(MainActivity.this,str, Toast.LENGTH_LONG).show();rnrnelsernToast.makeText(MainActivity.this,str, Toast.LENGTH_SHORT).show();rnrnrnrnrn@Overridernpublic void onNothingSelected(AdapterView parent) rn// TODO Auto-generated method stubrnrnrnrnrn);rnrnrnrnrn
解决指针异常的一些经验
Caused by: <em>java</em>.lang.NullPointerException at com.example.kongjian_10.MainActivity.writeThink(MainActivity.<em>java</em>:25) at <em>java</em>.lang.reflect.Method.invokeNative(Native Method) at <em>java</em>
指针异常,如何解决
环境: Myeclipse2014 , win8.1操作系统, JDK7, tomcat7rnrn运行 top.jsp文件,发生<em>异常</em>,错误信息如下:rnorg.apache.jasper.JasperException: <em>java</em>.lang.NullPointerExceptionrnrnrn上次的错误信息也是 Exception(只是指明了错误行在下面[color=#FF0000]红色的代码[/color]),这次重启myeclipes后无法重现上次的error报错信息了,只是报错:org.apache.jasper.JasperException: <em>java</em>.lang.NullPointerException。上次报错能定位到 文件 top.jsp的代码,信息是:rnrn rn[color=#FF0000] 0))rn Iterator it=cpdd.iterator(); rn while(it.hasNext())rn rn Ssort s=(Ssort)it.next();rn%> rnrnrn[b]BasetableFactory.<em>java</em>相关代码如下:[/b]rnrnpublic abstract class BasetableFactory rn private static final String classname = "com.dao.DbBasetableFactory";rn private static BasetableFactory factory;rnrn public static BasetableFactory getInstance() rn if (factory == null) rn try rn Class c = Class.forName(classname);rn factory = (BasetableFactory) c.newInstance();rn catch (ClassNotFoundException ex) rn ex.printStackTrace();rn catch (IllegalAccessException ex1) rn ex1.printStackTrace();rn catch (InstantiationException ex1) rn ex1.printStackTrace();rn rn rn return new BasetableFactoryProxy(factory);rn rnrnrn[color=#FF0000]请各位高手帮忙看看: top.jsp这行代码([color=#FF0000] );[/color])到底是哪里有问题,如何修改,谢谢?[/color]
java xml 指针异常困惑了几天了?求解决~
package itat.org.xml;nnimport <em>java</em>.util.ArrayList;nimport <em>java</em>.util.List;nnimport org.dom4j.Document;nimport org.dom4j.DocumentException;nimport org.dom4j.Element;nimport org.dom4j.io.SAXReader;nnpublic class TestXML04 n public static void main(String[]ages)n try n SAXReader reader = new SAXReader();n Document d = reader.read(TestXML04.class.getClassLoader().getResource("xml/books.xml"));//获取类路径名的文件夹n Element root = d.getRootElement();//获得根元素n Element e = findByTitle(d, "<em>java</em>编程思想");n System.out.println(e.elementText("price"));n catch (DocumentException e) n e.printStackTrace();n n n private static Element findByTitle(Document d,String title)n Element root = d.getRootElement();n List eles = root.elements("book");n for(Element e:eles)n String t = e.elementTextTrim("title");//获得返回的一个去掉<em>空</em>格的元素文本(title)n if(t.equals(title))//比较传进来的title和获得的n return e;n n n return null;n n private static void tran()n SAXReader reader = new SAXReader();n try n Document d = reader.read(TestXML04.class.getClassLoader().getResource("xml/books.xml"));//获取类路径名的文件夹n Element root = d.getRootElement();//获得根元素n List eles = root.elements("book");//获得返回的一个元素的集合n List books = new ArrayList();//新建一个Book集合n for(Element e:eles)//遍历Element集合中所以元素n Book b = new Book();//新建一个Bookn b.setId(Integer.parseInt(e.attributeValue("id")));//遍历出来的元素id的值包装拆箱成int类型set给Bookn b.setTitle(e.elementText("title"));n b.setAuthor(e.elementText("author"));n b.setPrice(Double.parseDouble(e.elementText("price")));n n for(Book b:books)n System.out.println(b);n nn catch (DocumentException e) n e.printStackTrace();nn nn nnn```n n```nnn n <em>java</em>编程思想n Brucre Eckeln 89.00n n n C++编程思想n Brucre Eckeln 69.00n n n headfirst in <em>java</em>n Orellyn 79.00n nn![图片说明](https://img-ask.csdn.net/upload/201511/09/1447082417_151558.png)n
Android 7.x不到libsqlite.so文件的原因解决
在开发项目的时候我们免不了使用一些第三方的库来进行快速开发,有些第三方库只是简单的一个jar包,但是有些使用了jni开发,因此会包含so库文件。比如环信等聊天sdk,都会用到libsqlite.so文件。但是Android不同版本对so文件的访问权限也不同,7.x则更为苛刻。 <em>解决</em>方法:下载附件中的so文件,放到对应的文件夹下,如libs/armv7-abi/libsqlite.so,并注意你的
解决指针异常NullPointException
如何<em>解决</em><em>空</em><em>指针</em><em>异常</em> 这个问题。。有很多的造成<em>原因</em>,不过一般都是unity<em>找</em><em>不到</em>你给的条件。<em>解决</em><em>空</em><em>指针</em>的一般的步骤。 1.你要相信,unity<em>找</em><em>不到</em>不是unity的问题,肯定是你的路径。。或者说条件没写正确。 2.看路径,比如说Gameobject.Find("fhafajf");find里面的层级关系要写对,字母或者是<em>空</em>格都不要错 3.有些是你没有赋值,比如一个animation,你在用之
指针异常如何解决,求教。
开发平台使用的是金蝶的OperaMasks。rn[code=<em>java</em>] public List find(String string) rn // TODO Auto-generated method stubrn return getHibernateTemplate().find(string);rn rn[/code]rn[code=<em>java</em>]2012-12-13 11:24:42 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet Faces Servlet threw exceptionrn<em>java</em>.lang.NullPointerExceptionrn at dao.impl.BaseDao.find(BaseDao.<em>java</em>:33)rn at service.impl.BaseService.find(BaseService.<em>java</em>:34)rn at bean.LoginBean.sub(LoginBean.<em>java</em>:34)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.<em>java</em>:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.<em>java</em>:25)rn at <em>java</em>.lang.reflect.Method.invoke(Method.<em>java</em>:597)rn at org.operamasks.faces.binding.ModelBean.invokeMethod(ModelBean.<em>java</em>:319)rn at org.operamasks.faces.binding.ModelBean.invokeAction(ModelBean.<em>java</em>:394)rn at org.operamasks.faces.binding.impl.ActionMethodAdapter.invoke(ActionMethodAdapter.<em>java</em>:66)rn at org.operamasks.faces.binding.impl.CompositeMethodAdapter.invoke(CompositeMethodAdapter.<em>java</em>:62)rn at org.operamasks.faces.application.impl.ActionListenerImpl.processAction(ActionListenerImpl.<em>java</em>:109)rn at <em>java</em>x.faces.component.UICommand.broadcast(UICommand.<em>java</em>:386)rn at <em>java</em>x.faces.component.UIViewRoot.broadcastEvent(UIViewRoot.<em>java</em>:491)rn at <em>java</em>x.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.<em>java</em>:451)rn at <em>java</em>x.faces.component.UIViewRoot.processApplication(UIViewRoot.<em>java</em>:794)rn at org.operamasks.faces.lifecycle.InvokeApplication.execute(InvokeApplication.<em>java</em>:42)rn at org.operamasks.faces.lifecycle.LifecycleImpl.doPhase(LifecycleImpl.<em>java</em>:135)rn at org.operamasks.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.<em>java</em>:83)rn at <em>java</em>x.faces.webapp.FacesServlet.service(FacesServlet.<em>java</em>:244)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.<em>java</em>:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.<em>java</em>:206)rn at org.operamasks.faces.webapp.filter.DefaultSuffixRedirector.doFilter(DefaultSuffixRedirector.<em>java</em>:73)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.<em>java</em>:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.<em>java</em>:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.<em>java</em>:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.<em>java</em>:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.<em>java</em>:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.<em>java</em>:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.<em>java</em>:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.<em>java</em>:291)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.<em>java</em>:859)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.<em>java</em>:602)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.<em>java</em>:489)rn at <em>java</em>.lang.Thread.run(Thread.<em>java</em>:619)[/code]
不到符号的原因求大神解决
我创建了一个ISimpleStack接口,有两个实现类,放在stackpack,然后在ISimpleStackDemo里导入包,import stackpack.*;运行会出现错误。[code=<em>java</em>][quote][/quote][/code]
这样的错误原因怎么解决
HTTP Status 500 - rnrn--------------------------------------------------------------------------------rnrntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnorg.apache.jasper.JasperException: /Config.jsp(0,0) Page directive: can't have multiple occurrences of contentTypernrn其中config.jsp代码如下:rnrnrnrn rn rn
33网吧工具超级模块下载
大金石可镂撒的撒旦阿斯顿阿斯顿 大家爱思考的记录卡机生理健康 相关下载链接:[url=//download.csdn.net/download/qq104030203/2982765?utm_source=bbsseo]//download.csdn.net/download/qq104030203/2982765?utm_source=bbsseo[/url]
最新软考网工历年真题解析(2004下-2010下)下载
计算机软考网络工程师的历年真题解析,软考官网上也有,不过没打包,需要的就拿去吧 相关下载链接:[url=//download.csdn.net/download/liuzhizhen001/3353611?utm_source=bbsseo]//download.csdn.net/download/liuzhizhen001/3353611?utm_source=bbsseo[/url]
zigbee 规范下载
zigbee 规范 相关下载链接:[url=//download.csdn.net/download/luohsh1/5273085?utm_source=bbsseo]//download.csdn.net/download/luohsh1/5273085?utm_source=bbsseo[/url]
相关热词 c#检测非法字符 c#双屏截图 c#中怎么关闭线程 c# 显示服务器上的图片 api嵌入窗口 c# c# 控制网页 c# encrypt c#微信网页版登录 c# login 居中 c# 考试软件
我们是很有底线的