Search Results

Search found 33227 results on 1330 pages for 'open stackoverflow'.

Page 70/1330 | < Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >

  • Exception in thread "main" java.lang.StackOverflowError

    - by Ray.R.Chua
    I have a piece of code and I could not figure out why it is giving me Exception in thread "main" java.lang.StackOverflowError. This is the question: Given a positive integer n, prints out the sum of the lengths of the Syracuse sequence starting in the range of 1 to n inclusive. So, for example, the call: lengths(3) will return the the combined length of the sequences: 1 2 1 3 10 5 16 8 4 2 1 which is the value: 11. lengths must throw an IllegalArgumentException if its input value is less than one. My Code: import java.util.HashMap; public class Test { HashMap<Integer,Integer> syraSumHashTable = new HashMap<Integer,Integer>(); public Test(){ } public int lengths(int n)throws IllegalArgumentException{ int sum =0; if(n < 1){ throw new IllegalArgumentException("Error!! Invalid Input!"); } else{ for(int i =1; i<=n;i++){ if(syraSumHashTable.get(i)==null) { syraSumHashTable.put(i, printSyra(i,1)); sum += (Integer)syraSumHashTable.get(i); } else{ sum += (Integer)syraSumHashTable.get(i); } } return sum; } } private int printSyra(int num, int count){ int n = num; if(n == 1){ return count; } else{ if(n%2==0){ return printSyra(n/2, ++count); } else{ return printSyra((n*3)+1, ++count) ; } } } } Driver code: public static void main(String[] args) { // TODO Auto-generated method stub Test s1 = new Test(); System.out.println(s1.lengths(90090249)); //System.out.println(s1.lengths(5)); } . I know the problem lies with the recursion. The error does not occur if the input is a small value, example: 5. But when the number is huge, like 90090249, I got the Exception in thread "main" java.lang.StackOverflowError. Thanks all for your help. :) I almost forgot the error msg: Exception in thread "main" java.lang.StackOverflowError at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:65) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:65) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:60)

    Read the article

  • Does this sound like a stack overflow?

    - by Jordan S
    I think I might be having a stack overflow problem or something similar in my embedded firmware code. I am a new programmer and have never dealt with a SO so I'm not sure if that is what's happening or not. The firmware controls a device with a wheel that has magnets evenly spaced around it and the board has a hall effect sensor that senses when magnet is over it. My firmware operates the stepper and also count steps while monitoring the magnet sensor in order to detect if the wheel has stalled. I am using a timer interrupt on my chip (8 bit, 8057 acrh.) to set output ports to control the motor and for the stall detection. The stall detection code looks like this... // Enter ISR // Change the ports to the appropriate value for the next step // ... StallDetector++; // Increment the stall detector if(PosSensor != LastPosMagState) { StallDetector = 0; LastPosMagState = PosSensor; } else { if (PosSensor == ON) { if (StallDetector > (MagnetSize + 10)) { HandleStallEvent(); } } else if (PosSensor == OFF) { if (StallDetector > (GapSize + 10)) { HandleStallEvent(); } } } this code is called every time the ISR is triggered. PosSensor is the magnet sensor. MagnetSize is the number of stepper steps that it takes to get through the magnet field. GapSize is the number of steps between two magnets. So I want to detect if the wheel gets stuck either with the sensor over a magnet or not over a magnet. This works great for a long time but then after a while the first stall event will occur because 'StallDetector (MagnetSize + 10)' but when I look at the value of StallDetector it is always around 220! This doesn't make sense because MagnetSize is always around 35. So the stall event should have been triggered at like 46 but somehow it got all the way up to 220? And I don't set the value of stall detector anywhere else in my code. Do you have any advice on how I can track down the root of this problem? The ISR looks like this void Timer3_ISR(void) interrupt 14 { OperateStepper(); // This is the function shown above TMR3CN &= ~0x80; // Clear Timer3 interrupt flag } HandleStallEvent just sets a few variable back to their default values so that it can attempt another move... #pragma save #pragma nooverlay void HandleStallEvent() { ///* PulseMotor = 0; //Stop the wheel from moving SetMotorPower(0); //Set motor power low MotorSpeed = LOW_SPEED; SetSpeedHz(); ERROR_STATE = 2; DEVICE_IS_HOMED = FALSE; DEVICE_IS_HOMING = FALSE; DEVICE_IS_MOVING = FALSE; HOMING_STATE = 0; MOVING_STATE = 0; CURRENT_POSITION = 0; StallDetector = 0; return; //*/ } #pragma restore

    Read the article

  • Python ValueError: not allowed to raise maximum limit

    - by Ricky Bobby
    I'm using python 2.7.2 on mac os 10.7.3 I'm doing a recursive algorithm in python with more than 50 000 recursion levels. I tried to increase the maximum recursion level to 1 000 000 but my python shell still exit after 18 000 recursion levels. I tried to increase the resources available : import resource resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1)) sys.setrecursionlimit(10**6) and I get this error : Traceback (most recent call last): File "<pyshell#58>", line 1, in <module> resource.setrlimit(resource.RLIMIT_STACK,(2**29,-1)) ValueError: not allowed to raise maximum limit I don't know why I cannot raise the maximum limit ? thanks for your suggestions .

    Read the article

  • Closing Question Rights in Stack over flow

    - by Asim Sajjad
    I have posted my Question and some one has closed that question, but i didn't get my answer from any of the viewer who have view my question or post theire answer, how can anyone close question when I don't get answer or statisfied with the answer posted against my question??? Why people close the question without permission of the question owner ???

    Read the article

  • Wallet Underflow? [closed]

    - by David T. McKee
    I am a software engineer who would love to "disconnect" from the "company store" so-to-speak. This concept of Stack-Overflow is great...so, because I know that software engineers need coffee and food, how do you monetize this? Just wondering.

    Read the article

  • Stack Overflow problem transforming with a custom xslt

    - by Flynn1179
    I've got a system that allows the user the option of providing their own XSLT to apply to some data that's been retrieved, as a means of specifying how that data should be presented. However, if the user includes code in the XSLT equivalent to: <xsl:template match="/"> <xsl:element name="data"> <xsl:apply-templates select="." /> </xsl:element> </xsl:template> this causes .NET to infinitely recurse trying to process it, and produces a stack overflow error. I need to be able to trap this before it crashes the app, as the data that's been retrieved is occasionally quite time-consuming to obtain, and the data is lost when this happens. Is there any way of doing this? I know it's theoretically possible to identify any occurrences of xsl:apply-templates with "." in the select attribute, but this isn't the only way an infinite recursion could happen, I need a way of generically trapping it.

    Read the article

  • XDocument change all attribute names

    - by Dested
    I have an XDocument that looks similar to <root> <a> <b foo="1" bar="2" /> <b foo="3" bar="4" /> <b foo="5" bar="6" /> <b foo="7" bar="8" /> <b foo="9" bar="10" /> </a> </root> I wish to change the attribute foo to something else, and the attribute bar to something else. How can I easily do this? My current version (below) stack overflows with large documents, and has an awful smell to it. string dd=LoadedXDocument.ToString(); foreach (var s in AttributeReplacements) dd = dd.Replace(s.Old+"=", s.New+"=");

    Read the article

  • why is my reputation deducted? [closed]

    - by benjamin button
    hi, yesterday i had a reputation more than 2600. today when i opened the site it suddenly reduced to 1574!!!!. but i am not able to figure out how and why did it get reduced? this question is probably concerned to the administrators or any regular user can present their opinion!. could anybody please tell?

    Read the article

  • Why does my array initialization code cause a StackOverflowException to be thrown?

    - by MCS
    The following line of code in my class constructor is throwing a StackOverflowException: myList = new string[]{}; // myList is a property of type string[] Why is that happening? And what's the proper way to initialize an empty array? UPDATE: The cause was in the set method, in which I was attempting to trim all values. What's wrong with this code: set { for (int i = 0; i < myList.Length; i++) { if (myList[i] != null) myList[i] = myList[i].Trim(); } }

    Read the article

  • How do I login to this site? [closed]

    - by Kevin Monk
    This site drives me crazy! I'm a web developer. I understand technology, I understand OpenID, but I don't have a clue how to login to this site with the username I created whilst asking another question unless I ask yet another question? Sure, this is a techie site but if I can't work out how to log in then what hope is OpenID to the rest of the non technical world?

    Read the article

  • The implicit function __strcpy_chk() call

    - by Summer_More_More_Tea
    Hi everyone: I'm now performing a stack buffer overflow attack test on my own PC( Ubuntu 9.10, gcc-4.4.1 ) based on the article http://www.tenouk.com/Bufferoverflowc/Bufferoverflow4.html. Yet I haven't achieved the goal. Each time a segfault is thrown accompanied with some error informaiton. I compile the source code, and wanna get further information using objdump. Function __strcpy_chk is invoked in the assembly code dumped out, and it's said that "The __strcpy_chk() function is not in the source standard; it is only in the binary standard." Does this the mechanism a compiler employed to protect runtime stack? To finish my test, how can I bypass the protection? Regards.

    Read the article

  • printf not passing correct Hex Address to stack

    - by kriss
    I have a hickup in using printf . I am on ubuntu 10.04. Basically i have a C program asking for some input and then prints it back. It is OK for printing something after inputing. I tried to insert some Hex Address to Stack by following format:- printf "hello world!\x12\x23\x34" | ./input1 But i don't know what is the problem. If i give only string beyond 12 bytes it overwrites BUT If I give hex address(through printf), it doesn't overwrite on return address. Instead it stores some other thing. Could anyone help??? I can't proceed further becoz of this. Thanks in advance

    Read the article

< Previous Page | 66 67 68 69 70 71 72 73 74 75 76 77  | Next Page >