Java.Lang.Stackoverflow Error. Suspected Too Many Views

java.lang.StackOverFlow error. Suspected too many views?

You have (way) too many nested layouts. You can check out the official Android blog at d.android.com to get tips and tricks on how to optimize layouts.

StackOverflowError on Switching Views

Your activity's layout hierarchy is too deep, meaning you have way too many layouts in the XML of that activity. I suggest reading about how to flatten and optimize your layout.

There are many questions and answers in SO regarding this:

java.lang.StackOverFlow error. Suspected too many views?

Stackoverflow: Caused by nested views?

Android StackOverflow Error

You have too many nested viewgroups (see: java.lang.StackOverFlow error. Suspected too many views? for tips on how to reduce some of them)

Too many views despite reusing layouts

By loooking your xml layout, does appear that you are trying to display rows of data on the screen. You can use a ListAdapter instead and create the layout of the row within the Adapter.

You will have less code but the number of views will remain those only displayed (ignoring cliped views off the scroll)

I get error when I go to previous activity the third time

Your StackOverflowError is probably caused by too many nested views(as also hinted by your logcat content).

Look at the following links for further reference:

Android StackOverflow Error

java.lang.StackOverFlow error. Suspected too many views?

Stackoverflow: Caused by nested views?

Stackoverflow: Caused by nested views?

What is the maximum number of nested layouts?

There is no specific value. You run out of stack space when you run out of stack space, and that will be contingent upon what you are doing. The main application thread has an 8KB stack, last I heard.

That being said, if Hierarchy View is showing a depth of 10 or more (root to deepest leaf), I start to get nervous, and by 15 you are likely to start running into exceptions. Your image, which is nearly illegible, appears to have a depth substantially higher than that.

You seem to have a number of wasted layers. If you have a layer in Hierarchy View, on the critical path, that has one parent and one child, that is a prime candidate to be removed, as it may not be adding any value. You have at least 5 of these candidates. Even cleaning all of that up may not be sufficient, but it is a starting point.

Exception in thread main java.lang.StackOverflowError

Since your array is sorted from smallest to largest, when you try to insert the, say, 15000th node using insertPrep (see the loop in tree()), you are going to recursively call insert(AvlNode node, AvlNode newNode) 15000 times.

This is due to the test in insert

  if (node.key > newNode.key){
if(node.left!=null){node.left=insert(node.left , newNode);}
else{node.left=newNode;}
}

The recursions are too deep

Recursion is probably not your best choice to find the location in the tree and you should resort to a loop which will be more efficient anyway because you do not have to accumulate the frames between the calls.

Alternatively, use a language such as Scala that knows about tail recursion and automatically unfolds tail recursions to loops at compile time.

EDIT
The explanation for the Overflow is probably over simplistic. See comments below



Related Topics



Leave a reply



Submit