執(zhí)手麥田的咖啡空間  
          專(zhuān)注于Java的學(xué)習(xí)研究
          公告
          • 于喧鬧網(wǎng)界之中,尋一處僻靜之所,與三二好友,品程序、論思想,其樂(lè)何融融!
            執(zhí)手麥田的咖啡館——在這里關(guān)注JAVA的學(xué)習(xí)研究
          日歷
          <2011年10月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導(dǎo)航

          留言簿(2)

          隨筆分類(lèi)(13)

          隨筆檔案(13)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

           

          今天在調(diào)試一個(gè)簡(jiǎn)單的JAVA手機(jī)小程序的時(shí)候,遇到了一個(gè)讓我頭痛了半天的問(wèn)題。但最終得以解決,將方法寫(xiě)上,說(shuō)不定還有一些朋友也遇到了類(lèi)似的情況。

          這個(gè)程序是一個(gè)關(guān)于在手機(jī)上顯示圖片的程序,分成兩段:

          1、MainCanvas.java部分

          內(nèi)容如下:

          import java.io.IOException;

          import javax.microedition.lcdui.Canvas;
          import javax.microedition.lcdui.Graphics;
          import javax.microedition.lcdui.Image;

          public class MainCanvas extends Canvas {

          public Image m_Image;
          MainCanvas(){
             try{
             
              m_Image=Image.createImage("/IM.png");
             
             }
             catch(IOException e){
             
                }
          }
          protected void paint(Graphics g){
             g.drawImage(m_Image,0,0,Graphics.TOP|Graphics.LEFT);
          }

          }

          2、MyCartoonMidlet.java部分

          內(nèi)容如下:

          ukimport javax.microedition.lcdui.Display;
          import javax.microedition.midlet.MIDlet;
          import javax.microedition.midlet.MIDletStateChangeException;


          public class MyCartoonMidlet extends MIDlet {

          public MainCanvas m_MainCanvas;
          public MyCartoonMidlet() {
             // TODO 自動(dòng)生成構(gòu)造函數(shù)存根
          }

          protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
             // TODO 自動(dòng)生成方法存根

          }

          protected void pauseApp() {
             // TODO 自動(dòng)生成方法存根
                  
          }

          protected void startApp() throws MIDletStateChangeException {
             m_MainCanvas=new MainCanvas();
             Display.getDisplay(this).setCurrent(m_MainCanvas);
             while(true){
              m_MainCanvas.repaint();
             }

          }

          }

          過(guò)程是調(diào)用目錄下的一個(gè)叫做 IIM.PNG的文件

          在調(diào)試過(guò)程中,編譯器老是報(bào)Java.lang.NullPointerException 的錯(cuò)誤,順藤摸瓜,發(fā)現(xiàn)是找不到圖片的問(wèn)題才導(dǎo)致拋出這樣的異常。可是我已經(jīng)把圖片放到了程序目錄下呀。于是一度認(rèn)為是編程環(huán)境出了問(wèn)題。可事實(shí)并非如此。查找了半天資料才發(fā)現(xiàn),原來(lái)圖片應(yīng)該放在verified\classes下,把文件放進(jìn)去,所有問(wèn)題都解決了。OK!

          posted on 2007-04-25 10:44 執(zhí)手麥田 閱讀(20961) 評(píng)論(17)  編輯  收藏 所屬分類(lèi): 咖啡館
          評(píng)論:
          • # re: 關(guān)于Java.lang.NullPointerException  路過(guò) Posted @ 2007-04-25 20:00
            終于找到了,我今天也遇到了這個(gè)問(wèn)題,謝謝提供參考。  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  ddd Posted @ 2007-04-26 12:36
            放到class path下的話(huà),都可以的吧。。。  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException   Posted @ 2007-05-01 00:49
            我是玩游戲玩著玩著會(huì)彈出這個(gè)問(wèn)題
            請(qǐng)問(wèn)有什么解決方法?  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  佛前青蓮 Posted @ 2007-05-26 17:54
            我試過(guò)了,沒(méi)用的.我把文件放在/rushmore/classes/images/mountrushmore.jpg
            還是會(huì)拋出這個(gè)java.lang.NullPointerException
            請(qǐng)教高手別的方法  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException[未登錄](méi)  june Posted @ 2007-06-13 10:51
            我也遇到這個(gè)問(wèn)題了
            我是改一個(gè)程序,那個(gè)程序只有在連接局域網(wǎng)的時(shí)候才正常
            不然就會(huì)彈出這個(gè)錯(cuò)誤
            不知道什么原因
            哪位大俠指點(diǎn)一下  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  程序員 Posted @ 2007-07-23 08:53
            java.lang.NullPointerException
            插入數(shù)據(jù)庫(kù)的時(shí)候出現(xiàn)的異常,怎么辦啊?請(qǐng)教各位大俠指導(dǎo)!  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  飄逸的云 Posted @ 2007-08-10 20:11
            我機(jī)子以前不會(huì)出現(xiàn)這種情況的,但是不知道為什么后來(lái)無(wú)論怎么樣都是這樣,我氣死了:
            比如import javax.microedition.midlet.MIDlet;
            import javax.microedition.midlet.MIDletStateChangeException;
            import javax.microedition.lcdui.Form;
            import javax.microedition.lcdui.Display;

            public class MidLetTest0 extends MIDlet {
            Display display;
            Form form=new Form("手機(jī)高級(jí)界面測(cè)試");
            public MidLetTest0() {
            // TODO 自動(dòng)生成構(gòu)造函數(shù)存根
            }

            protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
            // TODO 自動(dòng)生成方法存根

            }

            protected void pauseApp() {
            // TODO 自動(dòng)生成方法存根

            }

            protected void startApp() throws MIDletStateChangeException {
            // TODO 自動(dòng)生成方法存根
            display.setCurrent(form);
            }

            }
            程序就會(huì)提示:


            Running with locale: Chinese_People's Republic of China.936
            startApp threw an Exception
            java.lang.NullPointerException
            java.lang.NullPointerException
            at MidLetTest0.startApp(+8)
            at javax.microedition.midlet.MIDletProxy.startApp(+7)
            at com.sun.midp.midlet.Scheduler.schedule(+270)
            at com.sun.midp.main.Main.runLocalClass(+28)
            at com.sun.midp.main.Main.main(+116)
            Execution completed.
            3407162 bytecodes executed
            32 thread switches
            1646 classes in the system (including system classes)
            17656 dynamic objects allocated (527024 bytes)
            2 garbage collections (457012 bytes collected)



            這是怎么回事,我覺(jué)得還是環(huán)境出了問(wèn)題,希望高手能幫幫我QQ:104684539  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException   Posted @ 2007-09-20 11:39
            對(duì)象為空  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  J2ME游戲開(kāi)發(fā) Posted @ 2007-10-20 20:15
            今天也出了這個(gè)問(wèn)題.......按著你的方法試了一試 居然成功了
            我愛(ài)死你了 捆饒我一下午的問(wèn)題解決了
            感謝你!!!!!!!!!!  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  楊堯 Posted @ 2008-11-06 10:25
            java.lang.NullPointerException
            at org.eclipse.datatools.sqltools.data.internal.ui.editor.TableDataTableCursor.registerCellEditorsListener(TableDataTableCursor.java:108)
            at org.eclipse.datatools.sqltools.data.internal.ui.editor.TableDataTableCursor.<init>(TableDataTableCursor.java:39)
            at org.eclipse.datatools.sqltools.data.internal.ui.editor.TableDataTableCursorExternalEditingSupport.<init>(TableDataTableCursorExternalEditingSupport.java:46)
            at org.eclipse.datatools.sqltools.data.internal.ui.editor.TableDataEditor.createPartControl(TableDataEditor.java:124)
            at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:661)
            at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:428)
            at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594)
            at org.eclipse.ui.internal.EditorReference.getEditor(EditorReference.java:266)
            at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2820)
            at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2729)
            at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2721)
            at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2673)
            at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
            at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2668)
            at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2652)
            at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2635)
            at org.eclipse.datatools.sqltools.data.internal.ui.editor.EditTableDataAction.run(EditTableDataAction.java:44)
            at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
            at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
            at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
            at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
            at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
            at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
            at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
            at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
            at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
            at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
            at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
            at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
            at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
            at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
            at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
            at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
            at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
            at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
            at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
            at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
            at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
            at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
            at org.eclipse.equinox.launcher.Main.run(Main.java:1236)

              回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  mxg618@126.com Posted @ 2009-03-15 17:00
            <%!
            String id;
            String title;
            String content;
            String author;
            String keywords;
            int currid;
            String sql="";
            ResultSet rstmp=null;
            %>
            <jsp:useBean id="conn" scope="page" class="k.kk" ></jsp:useBean>
            <%
            rstmp=conn.executeQuery("select max(id) As maxid from ness");
            if(rstmp.next()) currid=rstmp.getInt( "maxid" )+1;

            if(request.getParameter("title")!=null)
            title=request.getParameter("title");
            if(request.getParameter("content")==null)
            content=request.getParameter("content");
            if(request.getParameter("keyw")!=null)
            keywords=request.getParameter("keyw");
            if(request.getParameter("author")==null)
            author=request.getParameter("author");
            if(request.getParameter("title")!=null){
            sql=" insert into news values("+currid;
            sql+=",'"+ title+"','"+content+"',";
            sql+="date(),'"+ keywords +"','"+author+"')'";
            conn.executeQuery(sql);

            out.println("<hr>");
            out.println("<h2>添加成功</h2>");
            out.println("<hr>");
            }
            else{
            out.println("<hr>");
            out.println("<h2>添加正確的信息在錄入</h2>");
            out.println("<hr>");
            }

            %>


            </body>
            </html>


            java.lang.NullPointerException

              回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  ShaDi Posted @ 2009-06-09 18:31
            hi all, please can you translate it to english..i really dont understand theese letters.. i need to resolve it. thanks  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException[未登錄](méi)  QQ Posted @ 2009-07-17 15:53
            @ShaDi
            You have to put your pictures in this path -verified\classes.
            Hope it can help you!  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  J2ME初學(xué)者 Posted @ 2009-07-19 02:16
            public void keyPressed(int key){
            int i=0;
            if(key==-2||key==56){
            this.n+=1;
            System.out.println(pointer_1[i]);
            grap.drawImage(this.pointer_1[i], 62, fxy+20*i, 0);

            grap.drawImage(this.pointer_2[i+1], 62, fxy+20*(i+1), 0);
            i++;
            if(this.n==5) n=0;
            if(i>=4) i=0;
            }
            }
            我在paint()方法中已能調(diào)出圖片,可是在這里卻拋出java.lang.NullPointerException異常,能幫我看看是什么原因嗎?謝謝  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  劉攀攀 Posted @ 2010-11-05 19:48
            你可用tomcat部署了工程  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException[未登錄](méi)  hj Posted @ 2011-09-26 15:11
            你真會(huì)吹,圖片不存在,只會(huì)達(dá)不到效果而已  回復(fù)  更多評(píng)論   

          • # re: 關(guān)于Java.lang.NullPointerException  云鶴 Posted @ 2011-10-09 16:30
            org.apache.jasper.JasperException: java.lang.NullPointerException
            org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
            org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
            org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
            org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
            javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


            root cause

              回復(fù)  更多評(píng)論   

           
          Copyright © 執(zhí)手麥田 Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 曲麻莱县| 理塘县| 贺州市| 邯郸县| 乌海市| 昌黎县| 嵊州市| 株洲县| 敖汉旗| 宝应县| 通化县| 乐业县| 大名县| 三江| 平原县| 宁南县| 峨眉山市| 乌兰县| 文山县| 安丘市| 上饶市| 大同县| 宿迁市| 富蕴县| 黔西县| 汉寿县| 武平县| 格尔木市| 永兴县| 南京市| 桃园市| 海伦市| 台湾省| 上蔡县| 华宁县| 大厂| 四子王旗| 周至县| 称多县| 扶风县| 丘北县|