部分手机出现java.lang.NoClassDefFoundError的解决办法

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Kac930/article/details/79164599
谷歌规定单个dex文件中的方法不能超过65535的限制。
Android应用程序(APK)在Dalvik可执行文件的形式包含可执行的字节码文件(DEX)文件,其中包含已编译的代码来运行你的应用程序。Dalvik可执行规格限制一个Dex文件包含65535个方法:包括Android框架方法、Library方法的总数、和你自己的代码方法总数。因为65535等于64×1024,这一限制被称为“64k引用限制”。 

这个极限就要求我们配置应用程序的构建过程,需要生成多个DEX文件,所以称为multidex 配置。

编写代码时候如果发现部分手机异常java.lang.NoClassDefFoundError,那么你就要考虑65535的问题了,解决办法
1.配置build.gradle (app),加一句        multiDexEnabled true

2.在依赖中添加 compile 'com.android.support:multidex:1.0.1' 支持包用于5.0以下系统

3.如果你的项目中用到Application类,那么让它继承android.support.multidex.MultiDexApplication类就可以,如果你的Application已经继承了别的类,并且改动不方便的话,那么还有另外一种使用方式,覆写attachBaseContext()方法:

ok,这样就完事了。

展开阅读全文

加载项目出现java.lang.NoClassDefFoundError错误。

07-20

java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedExceptionrn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:169)rn at org.springframework.scripting.config.LangNamespaceHandler.class$(LangNamespaceHandler.java:45)rn at org.springframework.scripting.config.LangNamespaceHandler.init(LangNamespaceHandler.java:45)rn at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:123)rn at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.(DefaultNamespaceHandlerResolver.java:96)rn at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.(DefaultNamespaceHandlerResolver.java:83)rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createDefaultNamespaceHandlerResolver(XmlBeanDefinitionReader.java:498)rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.createReaderContext(XmlBeanDefinitionReader.java:487)rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468)rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363)rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313)rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)rn at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)rn at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)rn at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)rn at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)rn at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)rn at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:448)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:552)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rnrn运行是没什么问题,但是就是看着不爽啊。 说是groovy-all-1.5.3.jar版本错误,但是我都换了好几个版本了,但还是一直报这个,求高手指导指导。 论坛

RCP发布出现 java.lang.NoClassDefFoundError 异常

08-31

我将自己写的一个项目打包成jar文件后在Eclipse中选择添加jar,将这个项目的jar包引入,然后使用这个jar包中的类,比如rnSwapDepositInfo zw = new SwapDepositInfo();rn此时Eclipse不会报任何错误,在我本地运行也通过,但是RCP发布后,在我的机器上可以显示正常,但是在其它部分的机器上,点发布后的程序后,就出现以上异常是怎么回事?(注:SWT工程)rnrnjava.lang.NoClassDefFoundError: cn/bestwiz/swt/xtable/beans/SwapDepositInforn at cn.bestwiz.fes.front.comp.SwapDepositCompsite.initCompsite(SwapDepositCompsite.java:154)rn at cn.bestwiz.fes.front.comp.BaseCompsite.(BaseCompsite.java:24)rn at cn.bestwiz.fes.front.comp.SwapDepositCompsite.(SwapDepositCompsite.java:57)rn at cn.bestwiz.fes.front.view.SwapDepositView.createPartControl(SwapDepositView.java:17)rn at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:332)rn at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:197)rn at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:566)rn at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:290)rn at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:525)rn at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:140)rn at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:268)rn at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)rn at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:394)rn at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1144)rn at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1097)rn at org.eclipse.ui.internal.PartStack.presentationSelectionChanged(PartStack.java:795)rn at org.eclipse.ui.internal.PartStack.access$1(PartStack.java:781)rn at org.eclipse.ui.internal.PartStack$1.selectPart(PartStack.java:123)rn at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation$1.handleEvent(TabbedStackPresentation.java:126)rn at org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:267)rn at org.eclipse.ui.internal.presentations.util.AbstractTabFolder.fireEvent(AbstractTabFolder.java:276)rn at org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder.access$1(DefaultTabFolder.java:1)rn at org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder$2.handleEvent(DefaultTabFolder.java:84)rn at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)rn at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)rn at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:952)rn at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:937)rn at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:709)rn at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3171)rn at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1953)rn at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:288)rn at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)rn at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)rn at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)rn at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)rn at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1930)rn at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1894)rn at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:422)rn at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)rn at cn.bestwiz.fes.front.Application.run(Application.java:34)rn at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)rn at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)rn at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)rn at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)rn at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)rn at org.eclipse.core.launcher.Main.basicRun(Main.java:280)rn at org.eclipse.core.launcher.WebStartMain.basicRun(WebStartMain.java:63)rn at org.eclipse.core.launcher.Main.run(Main.java:977)rn at org.eclipse.core.launcher.WebStartMain.main(WebStartMain.java:42)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at com.sun.javaws.Launcher.executeApplication(Unknown Source)rn at com.sun.javaws.Launcher.executeMainClass(Unknown Source)rn at com.sun.javaws.Launcher.continueLaunch(Unknown Source)rn at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)rn at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)rn at com.sun.javaws.Launcher.run(Unknown Source)rn at java.lang.Thread.run(Unknown Source)rnrn有知道的请告诉我。在线等。。。。谢谢~~ 论坛

出现commons.mail发送email出现:java.lang.NoClassDefFoundError错误

11-06

我编译成功了,但是执行的时候出现如下错误:rnjava.lang.NoClassDefFoundError: TestEmailrnCaused by: java.lang.ClassNotFoundException: TestEmailrn at java.net.URLClassLoader$1.run(URLClassLoader.java:200)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:188)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:307)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:252)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)rnCould not find the main class: TestEmail. Program will exit.rnException in thread "main" rnrnrn我的环境变量设置的为(CLASSPATH):rn.;%JAVA_HOME%\lib;D:\java\lib\commons-email-1.1.jar;D:\java\lib\commons-lang-2.4.jar;D:\java\lib\mail.jarrnJAVA_HOME也设置了,bin目录也在path变量中加入了,但是运行的时候就是出错,大家帮个忙吧,多谢了!rnrnrn我的代码如下,是从网上找的:rn[code=Java]rnrnimport org.apache.commons.mail.EmailException;rnimport org.apache.commons.mail.HtmlEmail;rnrnrnpublic class mailSender rnrn/**rn * @param argsrn */rnpublic static void main(String[] args) rn //不要使用SimpleEmail,会出现乱码问题rn HtmlEmail email = new HtmlEmail();rn tryrn //这里是发送服务器的名字:,163的如下:rn email.setHostName("smtp.163.com");rn //编码集的设置rn email.setCharset("gbk");rn //收件人的邮箱rn email.addTo("abcd@163.com");rn //发送人的邮箱rn email.setFrom("abcd@163.com", "发送人名称");rn //如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码rn email.setAuthentication("abcd","abcd");rn email.setSubject("下午3:00会议室讨论,请准时参加");rn //要发送的信息rn email.setMsg("下午3:00会议室讨论,请准时参加");rn //发送rn email.send();rn catch (EmailException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rnrnrnrnrnrn[/code] 论坛

java.lang.NoClassDefFoundError:

07-02

严重: Servlet.service() for servlet BackGroundService threw exceptionrnjava.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStreamrn at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:191)rn at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:350)rn at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)rn at liuzuochen.sample.upload.BackGroundService.processFileUpload(BackGroundService.java:130)rn at liuzuochen.sample.upload.BackGroundService.doPost(BackGroundService.java:202)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)rn at java.lang.Thread.run(Thread.java:619)rn请高手帮忙!!!!!rn 论坛

??java.lang.NoClassDefFoundError

09-22

小程序如下:rn<%@ page language="java" import="org.globus.gram.Gram" %>rn<%@ page contentType="text/html" %>rn<%rn int i=Gram.getActiveJobs();rn out.print(i);rn%>rnimport用到的包我已经放到webapps/ROOT/WEB-INF/lib下了,还是出现以下错误,不知道要怎么办```rnrndescription: The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnjavax.servlet.ServletException: org/apache/log4j/Categoryrn org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)rn org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)rn org.apache.jsp.test.jobsub_005f2_jsp._jspService(jobsub_005f2_jsp.java:66)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:810)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:810)rnrnrnroot cause rnrnjava.lang.NoClassDefFoundError: org/apache/log4j/Categoryrn org.apache.jsp.test.jobsub_005f2_jsp._jspService(jobsub_005f2_jsp.java:52)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:810)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:810)rnrn谢谢各位先^^ 论坛

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