Hello World!

……用代码敲开每一个World的大门

MyEclipse开发中遇到的错误(连载)

 

>>1.严重: Servlet.service() for servlet jsp threw except
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.qiantai.index_jsp._jspService(index_jsp.java:108)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
at java.lang.Thread.run(Thread.java:619)

这个是怎么回事 (已解决问题)


最佳答案
这是你的jsp页面运行中有空指针异常,就是引用了一个为null的对象,跟踪代码进去看看是哪个对象为null报错。
其他答案
java.lang.NullPointerException
空指针异常,看你在jsp页面操作了什么,最好把代码贴出来,否则没法具体定位。


>>2.如何解决多重web应用中webapp. root重用的问题
tomcat6中部署了两个web应用,都采用的是struts2+spring+hibernate框架,记

录日志都用了log4j,结果webroot.app被重用了,启动tomcat时,出现错误,部分

错误信息如下:严重: Exception sending context initialized event to

listener instance of class

org.springframework.web.util.Log4jConfigListener
java.lang.IllegalStateException: Web app root system property already

set to different value: 'webapp.root' = [D:\Program Files\tomcat6

\webapps\esis\] instead of [D:\Program Files\tomcat6\webapps\esisOne\]

- Choose unique values for the 'webAppRootKey' context-param in your

web.xml files!
 at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty

(WebUtils.java:132)
 at org.springframework.web.util.Log4jWebConfigurer.initLogging

(Log4jWebConfigurer.java:117)
 at

org.springframework.web.util.Log4jConfigListener.contextInitialized

(Log4jConfigListener.java:51)
 at org.apache.catalina.core.StandardContext.listenerStart

(StandardContext.java:3827)
 at org.apache.catalina.core.StandardContext.start

(StandardContext.java:4334)
 at org.apache.catalina.core.ContainerBase.addChildInternal

(ContainerBase.java:791)


推荐答案
检举 | 2008-10-14 15:36 是你的两个Web应用的web.xml文件定义了相同的webAppRootKey, 如:

### app1:
<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>app1.root</param-value>
</context-param>

### app2:
<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>app2.root</param-value>
</context-param>

 

At the end there are three possible solutions for the initial problem:

(1) Provide any of your applications with a unique 'webAppRootKey'.
(2) Set the servlet context parameter 'log4jExposeWebAppRoot' to  
'false'. This eliminates the use of log file locations relative to  
the web application's root directory but still allows a log4j config  
location outside the classpath.
(3) Remove the 'Log4jConfigListener' from your application's web.xml.

What do you think is the best solution and should be incorporated  
into the riot skeleton project?

>>3.无法解析导入org.eclipse.swt
在编写一个网页浏览器用的是eclipse3.2中文版
代码看的是网上的教程
package mySimpleBrowser;
//导入声明
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;

public class MySimpleBrowser {

但是无法解析导入org.eclipse
下面有红色的波浪线
而且教程中“步骤1:新建项目“MySimpleBrowser”
选择“文件”|“新建”|“项目”命令,在新建项目对话框内选择“SWT/Jface Java Project”,”
我的新建里只有java project前面没有SWT/Jface
这是什么问题
谢谢回答

最佳答案
右键点击项目 -> Build Path -> Config Build Path...
然后选择Libraries标签页,点击Add External JARs...
再到你的eclipse安装目录下的plugins目录下寻找 org.eclipse.swt.win32.win32.x86_XXXXX.jar(XXXXX是版本号)。

>>4.Tomcat:Caused by: java.lang.OutOfMemoryError: PermGen space
2007-03-31 20:58
项目中遇到了系统停止响应的问题,查看日志发现

Tomcat报告Caused by: java.lang.OutOfMemoryError: PermGen space异常,开始以为是程序内存泄漏导致的内存溢出,网上查了一下,原来是另有原因,不过确实是内存溢出

PermGen space的全称是Permanent Generation space,是指内存的永久保存区域,
这块内存主要是被JVM存放Class和Meta信息的,Class在被Loader时就会被放到PermGen
space中,
它和存放类实例(Instance)的Heap区域不同,GC(Garbage Collection)不会在主程序运
行期对
PermGen space进行清理,所以如果你的应用中有很多CLASS的话,就很可能出现PermGen
space错误,
这种错误常见在web服务器对JSP进行pre compile的时候。如果你的WEB APP下都用了大
量的第三方jar, 其大小
超过了jvm默认的大小(4M)那么就会产生此错误信息了。
解决方法: 手动设置MaxPermSize大小

设置参数:-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m

Tomcat中,修改TOMCAT_HOME/bin/catalina.sh(linux系统下start.sh会调用它来启动tomcat,windows下调用catalina.bat,修改类似)

在文件头部注释后加入
JAVA_OPTS='-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m'


如果tomcat运行多个系统,将相同的第三方jar文件移置到tomcat/shared/lib目录下,这样可以达到减少
jar 文档重复占用内存的目的。

 

 

 >>5.关于java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream

(本文基于MyEclipse6.5其他IDE不知)
万分感谢黑毛,(有人如是说,黑色头发简称黑毛。。。。),老紫竹,孙yujia
接收邮件:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
当出现以上错误时,恭喜您已经离接收邮件不远了,否则请您解决好所有的异常后再来看这个帖子。

javax.mail和javax.activation这两个包已经在javaEE5当中属于基础包了,就是JDK中自带了已经,但是里面的方法与现在外面的mail.jar和activation.jar有一些出入,所以初学者在直接copy别人代码的时候往往会出现上面的错误。
废话不多说下面是解决方法
进到

X:\Program Files\MyEclipse 6.5\myeclipse\eclipse\plugins\com.genuitec.eclipse.j2eedt.core_6.5.0.zmyeclipse650200806\data\libraryset\EE_5

这个路径里,可以看到javaee.jar,用rar把这个文件打开,然后进到javax文件夹里,删除mail.jar和activation.jar(我的javaee.jar里,这两个东西是文件夹,总之删掉就OK,不过要注意备份一下)

删掉之后运行下面的代码,经行简单的修改以后就可以实现接收邮件的功能了!我已经测试过完全可行。


package com.oa.mail;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Properties;

import javax.mail.BodyPart;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;

import sun.misc.BASE64Decoder;

public class MailReceiver{

    public static void main(String[] args){

        MailReceiver receiver = new MailReceiver();
        receiver.setHost("pop3.pchome.com.tw");
        receiver.setUsername("xxxxxx");//您的邮箱账号
        receiver.setPassword("yyyyyy");//您的邮箱密码
        receiver.setAttachPath("f:\\email");//您要存放附件在什么位置?绝对路径
        try{
            receiver.reveiveMail();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    public void reveiveMail() throws Exception {

        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        Store store = session.getStore("pop3");
        store.connect(getHost(), getUsername(), getPassword());

        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message message[] = folder.getMessages();
        System.out.println("Messages''s length: " + message.length);

        //FetchProfile profile = new FetchProfile();
        //profile.add(FetchProfile.Item.ENVELOPE);
        //folder.fetch(message, profile);
       
        for (int i = 0; i < message.length; i++) {
           
            //message[i].setFlag(Flags.Flag.DELETED, true);//必须先设置:folder.open(Folder.READ_WRITE);
            handleMultipart(message[i]);
        }
        if (folder != null) {
            folder.close(true);
        }
        if (store != null) {
            store.close();
        }
    }

    private void handleMultipart(Message msg) throws Exception {
   
        String disposition;
        Multipart mp = (Multipart) msg.getContent();
        int mpCount = mp.getCount();
        for (int m = 0; m < mpCount; m++) {
            handle(msg);
            BodyPart part = mp.getBodyPart(m);
            disposition = part.getDisposition();
            if (disposition != null && disposition.equals(Part.ATTACHMENT)) {
                saveAttach(part, getAttachPath());
            } else {
                System.out.println(part.getContent());
            }
        }
    }

    private static void handle(Message msg) throws Exception {
       
        System.out.println("邮件主题:" + msg.getSubject());//测试
        System.out.println("邮件作者:" + msg.getFrom()[0].toString());
        System.out.println("发送日期:" + msg.getSentDate());
    }

    private static void saveAttach(BodyPart part, String filePath) throws Exception {

        String temp = part.getFileName();
        String s = temp.substring(8, temp.indexOf("?="));
        String fileName = base64Decoder(s);
        System.out.println("有附件:" + fileName);

        InputStream in = part.getInputStream();
        FileOutputStream writer = new FileOutputStream(new File(filePath+"\\" + fileName));
        byte[] content = new byte[255];
        while ((in.read(content)) != -1) {
            writer.write(content);
        }
        writer.close();
        in.close();
    }

    private static String base64Decoder(String s) throws Exception {
       
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] b = decoder.decodeBuffer(s);
       
        return (new String(b));
    }

    private String host = null;
    private String username = null;
    private String password = null;
    private String attachPath = null;
   
    public String getAttachPath() {
        return attachPath;
    }

    public void setAttachPath(String attachPath) {
        this.attachPath = attachPath;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

 

>>6. 在MyEclipse中修改项目的默认编码:右键点击项目->properties->Resource,在这个栏目下面就可以更改默认编码了。如下图所示:

 

 

>>7.MyEclipse中设置java文件和编译生成的class文件分别存放不同的位置?

Window->preferences->Java->Build Path->选择右边的Folders即可,如图所示:

 >>8.一些基本的对象不识别了,String,int这些都报错,说明是jre jar包的问题,可以右键点击项目,Build Path -> conifg build path,然后重新加载系统默认的jar环境即可。

 

>>9.Myeclipse出现错误: Multiple operations have reported errors Select an error to view its details

在myeclipse中保存时总是弹出错误提示框:
错误信息:
Multiple operations have reported errors Select an error to view its details
Update Progress

在网上找了下:
解决办法:
1.关闭myeclipse
2.找到MYEclipse的安装路径:比如:
D:\Program Files\MyEclipse 6.6\eclipse\configuration\org.eclipse.update 下
删除last.config.stamp 这个文件
3.重启myeclipse

 

>>10.java.lang.ClassCastException: java.util.concurrent.ConcurrentHashMap$Values cannot be cast to java.util.List
2012-03-08 13:59:04 ERROR BaseDispatchAction:216 - try catch exception:
java.lang.ClassCastException: java.util.concurrent.ConcurrentHashMap$Values cannot be cast to java.util.List
 at com.autonavi.monitor.action.StatisticsAction.flowDistributionStatistics(StatisticsAction.java:1158)
 at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
 at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
 at com.autonavi.core.web.struts.action.BaseDispatchAction.execute(BaseDispatchAction.java:213)
 at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
 at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)
 at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
 at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at com.autonavi.monitor.acegi.LogoutFilter.doFilter(LogoutFilter.java:54)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:229)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:286)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at org.acegisecurity.concurrent.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:95)
 at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
 at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
 at com.autonavi.monitor.acegi.FilterChainProxy.doFilter(FilterChainProxy.java:21)
 at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:77)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Thread.java:619)


像这样的错误:

java.lang.ClassCastException: java.util.concurrent.ConcurrentHashMap$Values cannot be cast to java.util.List


表示强制类型转换错误,不能直接把Map类型转换成List类型

>>11.

Eclipse启动时发生An internal error occurred during: "Initializing Java Tooling".错误的解决方法
 

删除当前工作目录下的WORKSPACE_HOME/.metadata/.plugins/org.eclipse.core.resources/.project,然后重新启动Eclipse (适用于MyEclipse6.0)

 

MyEclipse7.0是独立装起来的!! 

 把更新关掉也可以的!! Windows > Preferences > MyEclipse > Community Essentials,  把选项 "Search for new features on startup"的前勾去掉即可. 

 

MyEclipse8.5关闭自动更新

1. Window --> Preferences --> General --> Startup and Shutdown -->在列表项里面找到"Automatic Updates Scheduler " 项去掉前面的勾。(注意:要在下面列表框里面靠下面一点找到)

 

2. Window --> Preferences --> Myeclipse --> Maven4Myeclipse --> Maven --> "Download repository index updates on startup" 去掉前面的勾。

 

>>12.关于数据库的错误:

java.sql.SQLException: Unknown column 'time' in 'where clause'
报这个错表示数据表中没有这个字段

 

>>13.java.lang.IllegalStateException异常解决 

下面这段代码执行到it.remove()时报这个错误

/**
			 * 没有被当前用户占用的频道
			 */
			List<Channel> isUseChannelList = new ArrayList<Channel>();
			List<Channel> notUseChannelList = new ArrayList<Channel>();
			notUseChannelList.addAll(userChannelList);
			Iterator<Channel> it = channelList.iterator();
			for(;it.hasNext();) {
				int channelId = it.next().getChannelId();
				for(Channel channelTemp: notUseChannelList) {
					if(channelId == channelTemp.getChannelId()) {
						it.remove();
					}
				}
			}
			isUseChannelList.addAll(channelList);

之前执行正常着呢,为什么现在不行了呢,最后才发现是数据库里面数据的问题,这个表是用户和频道的关联表,所以用户和频道相当于表的主键,不同重复,一重复执行到这的时候就会报这样的错。

 

 

 

 

阅读更多
个人分类: 技巧
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭