Java递归时报错

作者: 操作系统  发布:2019-12-21
/***xxx20181018*从整形ArrayListsource中抽取n个元素,所构成的组合为ArrayListArrayListIntegerresult*@paramArrayListIntegersource*@paramintn*@returnArrayListArrayListIntegerresult*/publicstaticArrayListArrayListIntegerCombinationT(ArrayListIntegersource,intn){System.out.println("CombinationT(source,n):source.size()="+source.size()+";n="+n);ArrayListArrayListIntegerresult=newArrayListArrayListInteger();if(n==1){for(inti=0;isource.size();i++){Objectt=source.get(i);ArrayLista=newArrayList();a.add(t);result.add(a);}}elseif(source.size()==n){result.add(source);}else{ArrayListIntegerpsource=newArrayListInteger();//[source.size()-1];for(inti=0;isource.size()-1;i++){psource.add(source.get(i));}//报错信息所提示的84行代码result.addAll(CombinationT(psource,n));ArrayListArrayListIntegertmp=CombinationT(psource,n-1);for(inti=0;itmp.size();i++){ArrayListIntegerrs=newArrayListInteger();for(intj=0;jn-1;j++){rs.add(tmp.get(i).get(j));}rs.add(source.get(source.size()-1));result.add(rs);}}returnresult;}

[ERROR]-19:41:20-DruidDataSource-initdatasourceerrorcom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Couldnotcreateconnectiontodatabaseserver.Attemptedreconnect3times.Givingup.atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)atjava.lang.reflect.Constructor.newInstance(Constructor.java:423)atcom.mysql.jdbc.Util.handleNewInstance(Util.java:411)atcom.mysql.jdbc.Util.getInstance(Util.java:386)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)atcom.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2297)atcom.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2218)atcom.mysql.jdbc.ConnectionImpl.init(ConnectionImpl.java:797)atcom.mysql.jdbc.JDBC4Connection.init(JDBC4Connection.java:47)atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)atjava.lang.reflect.Constructor.newInstance(Constructor.java:423)atcom.mysql.jdbc.Util.handleNewInstance(Util.java:411)atcom.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)atcom.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)atcom.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1358)atcom.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1414)atcom.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:602)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)atcom.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:43)atcom.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:218)atcom.jfinal.core.Config.startPlugins(Config.java:107)atcom.jfinal.core.Config.configJFinal(Config.java:53)atcom.jfinal.core.JFinal.init(JFinal.java:63)atcom.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)atorg.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)atorg.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)atorg.apache.catalina.core.ApplicationFilterConfig.init(ApplicationFilterConfig.java:108)atorg.apache.catalina.core.StandardContext.filterStart(StandardContext.java:5037)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5739)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)atorg.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1707)atorg.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1697)atjava.util.concurrent.FutureTask.run(FutureTask.java:266)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)atjava.lang.Thread.run(Thread.java:748)Causedby:java.sql.SQLException:java.lang.ClassCastException:java.math.BigIntegercannotbecasttojava.lang.Longatcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)atcom.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1023)atcom.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3451)atcom.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2260)...34moreCausedby:java.lang.ClassCastException:java.math.BigIntegercannotbecasttojava.lang.Longatcom.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:974)...36more[ERROR]-19:41:20-DruidDataSource-dataSourceiniterrorcom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Couldnotcreateconnectiontodatabaseserver.Attemptedreconnect3times.Givingup.atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)atjava.lang.reflect.Constructor.newInstance(Constructor.java:423)atcom.mysql.jdbc.Util.handleNewInstance(Util.java:411)atcom.mysql.jdbc.Util.getInstance(Util.java:386)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)atcom.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2297)atcom.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2218)atcom.mysql.jdbc.ConnectionImpl.init(ConnectionImpl.java:797)atcom.mysql.jdbc.JDBC4Connection.init(JDBC4Connection.java:47)atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)atjava.lang.reflect.Constructor.newInstance(Constructor.java:423)atcom.mysql.jdbc.Util.handleNewInstance(Util.java:411)atcom.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)atcom.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)atcom.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1358)atcom.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1414)atcom.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:602)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)atcom.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:43)atcom.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:218)atcom.jfinal.core.Config.startPlugins(Config.java:107)atcom.jfinal.core.Config.configJFinal(Config.java:53)atcom.jfinal.core.JFinal.init(JFinal.java:63)atcom.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)atorg.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)atorg.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)atorg.apache.catalina.core.ApplicationFilterConfig.init(ApplicationFilterConfig.java:108)atorg.apache.catalina.core.StandardContext.filterStart(StandardContext.java:5037)atorg.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5739)atorg.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)atorg.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1707)atorg.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1697)atjava.util.concurrent.FutureTask.run(FutureTask.java:266)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)atjava.lang.Thread.run(Thread.java:748)Causedby:java.sql.SQLException:java.lang.ClassCastException:java.math.BigIntegercannotbecasttojava.lang.Longatcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)atcom.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1023)atcom.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3451)atcom.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2260)...34moreCausedby:java.lang.ClassCastException:java.math.BigIntegercannotbecasttojava.lang.Longatcom.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:974)...36more[INFO]-19:41:20-DruidDataSource-{dataSource-1}inited[ERROR]-19:41:20-Config-Pluginstarterror:com.jfinal.plugin.activerecord.ActiveRecordPlugin.com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Couldnotcreateconnectiontodatabaseserver.Attemptedreconnect3times.Givingup.com.jfinal.plugin.activerecord.ActiveRecordException:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Couldnotcreateconnectiontodatabaseserver.Attemptedreconnect3times.Givingup.atcom.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:55)atcom.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:218)atcom.jfinal.core.Config.startPlugins(Config.java:107)atcom.jfinal.core.Config.configJFinal(Config.java:53)atcom.jfinal.core.JFinal.init(JFinal.java:63)atcom.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)atorg.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.ja

地点这一个java写的整合措施在多次递归调用CombinationT后边世:Exceptioninthread"main"java.lang.StackOverflowErroratcom.fh.xt.utils.Combination.CombinationT(Combination.java:84卡塔尔(قطر‎atcom.fh.xt.utils.Combination.CombinationT(Combination.java:84卡塔尔国atcom.fh.xt.utils.Combination.CombinationT(Combination.java:84卡塔尔(英语:State of Qatar)...的栈溢出报错,如何改善本领防止栈溢出???

本文由金沙澳门官网送注册58发布于操作系统,转载请注明出处:Java递归时报错

关键词: