java.lang.StackOverflowError

版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者。 https://blog.csdn.net/lmb55/article/details/78896590

上午处理一个多层级的json返回时,遇到一个错误:java.lang.StackOverflowError。

查了一下资料:StackOverflowError是由于当前线程的栈满了,也就是函数调用层级过多导致的

仔细查看了一下我的代码,调用层级貌似也不多哦。问题是出在哪里呢?然后debug了一下,返现问题出在result里面的items节点上,我需要的是items节点里面的字段,当我把它们取出来之后,items还是存在于result中的,所以会一直走if语句,直到栈满,加了一行条码,在把result中的items取出来之后,将其从result中移除,问题完美解决。
这里写图片描述

入参报文如下:
这里写图片描述

展开阅读全文

java.lang.StackOverflowError 怎么办

11-14

我的程序中有一个递归函数,这个函数本身不是死循环,当数据量不是特别大的时候,比如说100.程序可以得出正常结果rn但是当我把数据改成200的时候,就会出现java.lang.StackOverflowError这个异常,我知道这个异常产生的原因是因为我的对递归层数太多。rn大家有什么好办法帮我解决这个问题吗?rn我看到jvm的栈内存默认只有0.5-1m,有点太小了rn我想增加jvm的栈内存,可是不知道应该怎么增加。rn我按照网上的说法,修改了我的eclipse.ini文件成这样rnrn# Automatically generated by the VMware Installer - DO NOT REMOVErn-vmrn/usr/bin/javarn# Automatically generated by the VMware Installer - DO NOT REMOVErn-startuprnplugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jarrn--launcher.libraryrnplugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.1.1.R36x_v20100810rn-showsplashrnorg.eclipse.platformrn--launcher.XXMaxPermSizern[color=#FF0000]1000[/color]mrn--launcher.defaultActionrnopenFilern-vmargsrn-Xms[color=#FF0000]500[/color]mrn-Xmx[color=#FF0000]1500[/color]mrnrn可是问题还是您没有解决,因为据我所知这个方法只是增大了jvm的堆内存,而没有增大栈内存。rnrn大家有什么好办法帮我解决这个问题吗?rnrn最好能有有效的办法增加jvm的栈内存rnrn据说把递归函数改写成循环可以避免这个问题,但是如果改写这个的话太麻烦了。rn而且把递归改成循环是不是可以解决问题,这个也不清除。rn请大家帮帮我rn谢谢拉。rn 论坛

SQL递归查询-——java.lang.StackOverflowError,求解!

08-15

目前在练习尚学堂马士兵BBS项目,在Eclipse中运行Tomcat,连接Mysql,在做树状结构展现时(jsp文件)发生java.lang.StackOverflowError。rn 在网上看了这个异常的发生原因,一种是递归程序陷入死循环,内存耗尽;一种是JVM内存过小,递归过度消耗内存。rn 对照视频中的代码,没发现我的代码有什么错误;检查Eclipse的eclipse.ini的配置文件,“Xms40m-Xmx512m”,内存也不小。rn 下面我把SQL语句和JSP代码贴出来,希望大家能帮我分析下原因,万分感谢。rnrnSQL部分:rn[code=sql]rncreate database bbs;rnrnuse bbs;rnrncreate table articlern(rnid int primary key auto_increment, //帖子idrnpid int, //回复帖子的id,0代表主题帖rnrootid int,rntitle varchar(255),rncont text,rnpdate datetime,rnisleaf int //叶子节点,0表示叶子结点,1表示非叶子结点rn);rnrnuse bbs;rninsert into article values(null,0,1,"蚂蚁大战大象","蚂蚁大战大象",now(),1);rninsert into article values(null,1,1,"大象被打趴下了","大象被打趴下了",now(),1);rninsert into article values(null,2,1,"蚂蚁也不好过","蚂蚁也不好过",now(),0);rninsert into article values(null,2,1,"瞎说","瞎说",now(),1);rninsert into article values(null,4,1,"没有瞎说","没有瞎说",now(),0);rninsert into article values(null,1,1,"怎么可能","怎么可能",now(),1);rninsert into article values(null,6,1,"怎么没有可能","怎么没有可能",now(),0);rninsert into article values(null,6,1,"可能性是很大的","可能性是很大的",now(),0);rninsert into article values(null,2,1,"大象进医院了","大象进医院了",now(),1);rninsert into article values(null,9,1,"护士是蚂蚁","护士是蚂蚁",now(),0);rn[/code]rnrnJSP部分:rn[code=text]rn<%@ page language="java" contentType="text/html; charset=gbk"rn pageEncoding="gbk"%>rn<%@ page import="java.sql.*" %>rnrn<%!rnString str = "";rnprivate void tree(Connection conn,int id,int level) rn Statement stmt = null;rn ResultSet rs = null;rn String preStr = ""; //前缀字符rn rn for(int i=0;i" +rn preStr + rs.getString("title") + "";rn if(rs.getInt("isleaf") != 0) //不是叶子节点rn tree(conn,rs.getInt(id),level+1);rn rn rn catch(SQLException e) rn e.printStackTrace();rn finally rn try rn if(rs != null) rn rs.close();rn rs = null;rn rn rn if(stmt != null) rn stmt.close();rn stmt = null;rn rn catch(SQLException e) rn e.printStackTrace();rn rn rnrn%>rnrnrnrn<%rnClass.forName("com.mysql.jdbc.Driver");rnString url = "jdbc:mysql://localhost:3306/bbs?user=root&password=123";rnConnection conn = DriverManager.getConnection(url);rnStatement stmt = conn.createStatement();rnResultSet rs = stmt.executeQuery("select * from article where pid= 0");//主题帖结果集rnwhile(rs.next()) //展现主题贴下的回复帖rn str += "" + rs.getInt("id") + "" +rn rs.getString("title") + "";rn if(rs.getInt("isleaf") != 0) rn tree(conn,rs.getInt("id"),1);rn rnrnrnrs.close();rnstmt.close();rnconn.close();rn%>rnrnrn rn Insert title herernrnrn rn<%= str %>rnrnrnrnrn[/code] 论坛

E/AndroidRuntime(28782): java.lang.StackOverflowError

12-25

12-25 13:20:54.741: E/AndroidRuntime(28782): java.lang.StackOverflowErrorrn12-25 13:20:54.741: E/AndroidRuntime(28782): at java.util.HashMap$EntrySet.iterator(HashMap.java:940)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:589)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeMapInternal(Parcel.java:591)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Bundle.writeToParcel(Bundle.java:1619)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeBundle(Parcel.java:605)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.content.Intent.writeToParcel(Intent.java:6842)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeParcelable(Parcel.java:1254)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writeValue(Parcel.java:1173)rn12-25 13:20:54.741: E/AndroidRuntime(28782): at android.os.Parcel.writrn12-25 13:20:56.871: D/Process(28782): killProcess, pid=28782rn12-25 13:20:56.871: D/Process(28782): dalvik.system.VMStack.getThreadStackTrace(Native Method)rn12-25 13:20:56.881: D/Process(28782): java.lang.Thread.getStackTrace(Thread.java:599)rn12-25 13:20:56.881: D/Process(28782): android.os.Process.killProcess(Process.java:956)rn12-25 13:20:56.881: D/Process(28782): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:108)rn12-25 13:20:56.881: D/Process(28782): java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)rn12-25 13:20:56.881: D/Process(28782): java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)rn12-25 13:20:56.881: D/Process(28782): dalvik.system.NativeStart.main(Native Method)rn 论坛

求助关于java.lang.StackOverflowError的解决方法

04-19

我目前出现的情况如下[img=https://img-bbs.csdn.net/upload/201404/19/1397890755_646194.jpg][/img]运行的测试类如下:rnpackage com.gsq.day3.many2many;rnrnimport java.util.Set;rnrnimport org.hibernate.Session;rnimport org.junit.Before;rnimport org.junit.Test;rnrnimport com.gsq.day1.hello.HibernateUtil;rnrnpublic class Many2ManyTestrnrn @Beforern public void save()rn rn Teacher t1 = new Teacher();rn t1.setName("t1");rnrn Teacher t2 = new Teacher();rn t2.setName("t2");rnrn Student s1 = new Student();rn s1.setName("s1");rnrn Student s2 = new Student();rn s2.setName("s2");rnrn t1.getStu().add(s1);rn t1.getStu().add(s2);rnrn t2.getStu().add(s1);rn t2.getStu().add(s2);rnrn s1.getTea().add(t1);rn s1.getTea().add(t2);rnrn s2.getTea().add(t1);rn s2.getTea().add(t2);rnrn Session session = HibernateUtil.getInstance().getSession();rn session.beginTransaction();rnrn session.save(t1);rn session.save(t2);rn session.save(s1);rn session.save(s2);rnrn session.getTransaction().commit();rn session.close();rn rnrn @Testrn public void get()rn rn System. out .println( " 内存信息 :" + toMemoryInfo ()); rn Session session = HibernateUtil.getInstance().getSession();rnrn Teacher t = (Teacher) session.get(Teacher.class, 1l);rn Set ss = t.getStu();rnrn System.out.println(t);rn for (Student s : ss)rn System.out.println(s);rnrn session.close();rn rn /** rn rn * 获取当前 jvm 的内存信息 rnrn * @return rnrn */ rn rn public static String toMemoryInfo() rn rn Runtime currRuntime = Runtime.getRuntime (); rn rn int nFreeMemory = ( int ) (currRuntime.freeMemory() / 1024 / 1024); rn rn int nTotalMemory = ( int ) (currRuntime.totalMemory() / 1024 / 1024); rn rn return nFreeMemory + "M/" + nTotalMemory + "M(free/total)" ; rn rn rnrnrn其中 toMemoryInfo 是网上查找的计算关于当前jvm内存信息的函数,测得 内存信息 :47M/61M(free/total)。rn网上查找得知可能是我的jvm 虚拟内存太少的缘故,我按照方法改了之后测得的数据还是这么多,下图是我的eclipse的配置文件的详细信息:[img=https://img-bbs.csdn.net/upload/201404/19/1397890998_108754.jpg][/img]rn下图是我的eclipse种设置的信息:[img=https://img-bbs.csdn.net/upload/201404/19/1397891086_43408.jpg][/img]rn想问一下我是不是配置jvm的信息没有写好出错了,配置参考来自于:http://ybzshizds.iteye.com/blog/1139660rn还请高手指点迷津 论坛

Exception in thread "main" java.lang.StackOverflowError

11-07

class Linkrn class Nodern private String data;rn private Node next;rn public Node(String data)rn this.data=data;rn rn public void add(Node newnode)//增加节点rn if(this.next==null)rn this.next=newnode;rn rn this.next.add(newnode); rn rn rn public void print()//打印rn System.out.println(this.data+"\t");rn if(this.next!=null)rn this.next.print();rn rn rn public boolean search(String data)rn if(this.data==data)rn return true;rn elsern if(this.next!=null) rn this.next.search(data);rn rn return false;rn rn rn rn public void delete(Node previous,String data)rn if(data.equals(this.data))rn previous.next=this.next;rn else rn if(this.next!=null)rn this.next.delete(this, data);rn rn rn rn ;rn private Node root;rn public void addNode(String data)rn Node newnode=new Node(data);rn if(this.root==null)rn this.root=newnode;rn rn this.root.add(newnode);rn rn public void printNode()rn if(this.root!=null)rn this.root.print();rn rn rn public boolean contains(String name)rn return this.root.search(name);rn rn public void deleteNode(String data)rn if(this.contains(data))rn if(this.root.data.equals(data))rn this.root=this.root.next;rn elsern this.root.next.delete(root, data);rn rn rn rn rn public class LinkDemo rn public static void main(String[] args)rn Link l=new Link();rn l.addNode("A");rn l.addNode("B");rn l.addNode("C");rn l.addNode("D");rn l.addNode("E");rn System.out.println("---------删除之前--------");rn l.printNode();rn l.deleteNode("C");rn l.deleteNode("A"); rn System.out.println("---------删除之后--------");rn l.printNode();rn System.out.println(l.contains("A"));rn rn rnrnrnthis.next.add(newnode); this.next.print(); this.next.search(data);屏蔽这3句得到结果rn---------删除之前--------rnA rn---------删除之后--------rnA rntruernrn我不想屏蔽这3句rn没屏蔽的错误Exception in thread "main" java.lang.StackOverflowErrorrn at 折半递归非递归.Link$Node.add(LinkDemo.java:14)rn at 折半递归非递归.Link$Node.add(LinkDemo.java:14)rnLinkDemo.java:14 指的是this.next.add(newnode);rn依次都是这样 论坛

请教: java.lang.StackOverflowError 栈溢出咋解决

08-09

package com.example.lightrip;rnrnimport java.util.Timer; rnimport java.util.TimerTask; rnimport android.app.Activity; rnimport android.media.MediaPlayer; rnimport android.os.Bundle; rnimport android.os.Environment; rnimport android.view.Menu;rnimport android.view.View; rnimport android.widget.Button; rnimport android.widget.SeekBar; rnimport android.widget.SeekBar.OnSeekBarChangeListener; rnrnpublic class Spotdetail1 extends Activity rnrn rn public SeekBar seekbar; rn private boolean ifplay = true; rn public MediaPlayer mPlayer; rn private Timer mTimer; rn private TimerTask mTimerTask; rn private Button btn2;rn @Overridern protected void onCreate(Bundle savedInstanceState) rn rn onCreate(savedInstanceState);rn setContentView(R.layout.spotdetail_1);rn seekbar = (SeekBar) findViewById(R.id.seekbar1);rn seekbar.setMax(mPlayer.getDuration());rn seekbar.setOnSeekBarChangeListener(new MySeekbar());rn btn2= (Button)findViewById(R.id.btn2); rn btn2.setOnClickListener(new Mclick()); rn rn rn rn rn class Mclick extends Activity implements View.OnClickListenerrn rn public void onClick(View v)rn rn rn mPlayer = MediaPlayer.create(this, R.raw.father);rn mPlayer.start();rn btn2.setText("暂停");rn mTimer = new Timer(); rn mTimerTask = new TimerTask()rn rn public void run()rn rn seekbar.setProgress(mPlayer.getCurrentPosition());rn rn ;rn mTimer.schedule(mTimerTask, 0, 10);rn rn rn rn rn rn rn rn class MySeekbar implements OnSeekBarChangeListener rn rn rn @Overridern public void onProgressChanged(SeekBar seekBar, int progress,rn boolean fromUser) rn // TODO Auto-generated method stubrn rn rnrn @Overridern public void onStartTrackingTouch(SeekBar seekBar) rn // TODO Auto-generated method stubrn rn rnrn @Overridern public void onStopTrackingTouch(SeekBar seekBar) rn // TODO Auto-generated method stubrn mPlayer.seekTo(seekbar.getProgress());rn rn rnrn rn rnrn rn 这是logcat信息rnrn[img=https://img-bbs.csdn.net/upload/201508/09/1439091693_491452.png][/img] 论坛

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