尝试运行我的程序时,我不断收到此错误.
Exception in thread "main" java.lang.StackOverflowError
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:244)
at javax.swing.UIDefaults.getUI(UIDefaults.java:752)
at javax.swing.UIManager.getUI(UIManager.java:1001)
at javax.swing.JPanel.updateUI(JPanel.java:109)
at javax.swing.JPanel.<init>(JPanel.java:69)
at javax.swing.JPanel.<init>(JPanel.java:92)
at javax.swing.JPanel.<init>(JPanel.java:100)
at serverProperties.<init>(serverProperties.java:164)
at exportProperties.<init>(exportProperties.java:8)
at serverProperties.<init>(serverProperties.java:162)
Run Code Online (Sandbox Code Playgroud)
它只在尝试从某个类访问方法后发生.
这是主要类:
public class serverProperties extends JPanel
{
//Add classes
exportProperties writeProperties = new exportProperties();
//Assume I created the array sent to the exportProperties class
public serverProperties()
{
CheckBoxListener checkListener = new CheckBoxListener();
//Assume I created the check box and added the listener for it
}
private …Run Code Online (Sandbox Code Playgroud) 我有一个int,"count"在每次递归后添加一个,但我也有一个if语句,一旦int等于或大于另一个整数就停止递归.不知何故if语句被忽略了.
public static boolean wildcard(String x, String y, int substring, int count) {
if (count >= y.length()){
System.out.println("asdf");
return true;
}
if (x.charAt(count) == y.charAt(count)){
System.out.println("ALSKDFJKL");
return wildcard(x, y, substring, count++);
}
if (y.charAt(count) == '*'){
return wildcard(x.substring(substring), y, substring++, count);
System.out.println("wildcard end");
return false;
}
Run Code Online (Sandbox Code Playgroud) 参考答案:https://stackoverflow.com/a/4047607/347172
基本上,既然编译器正在创建一个使用递归的状态机,那么具有" 太多 " await的类是否可能导致编译器生成会引发异常的代码?
我在pastebin上看到了一个长轮询技术的例子,我想知道设计的递归性质是否会导致堆栈溢出?对不起,如果这是一个菜鸟问题,但我不熟悉长轮询,我对objective-c不太熟悉.
//long polling in objective-C
- (void) longPoll {
//create an autorelease pool for the thread
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
//compose the request
NSError* error = nil;
NSURLResponse* response = nil;
NSURL* requestUrl = [NSURL URLWithString:@"http://www.mysite.com/pollUrl"];
NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl];
//send the request (will block until a response comes back)
NSData* responseData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
//pass the response on to the handler
//(can also check for errors here, if you want)
[self performSelectorOnMainThread:@selector(dataReceived:)
withObject:responseData waitUntilDone:YES]; …Run Code Online (Sandbox Code Playgroud) 我制作了自定义用户控件,但在设置自定义属性时遇到问题.这是我遇到问题的代码,我不知道为什么我会收到堆栈溢出异常.任何帮助将非常感激.
displayList = new List<ItemDisplay>();
foreach (var item in InventoryData2.Items)
{
ItemDisplay id = new ItemDisplay();
id.Item = item;
id.Name = item.Item.ItemNumber;
id.Location = new System.Drawing.Point(0, displayList.Count * id.Height);
displayList.Add(id);
}
public InventoryItem Item
{
get { return Item; }
set {
Item = value;
lblItemNumber.Text = Item.Item.ItemNumber;
lblTitle.Text = Item.Item.Title;
lblModel.Text = Item.Item.Model;
lblPrice.Text = Item.Item.Price.ToString();
}
}
Run Code Online (Sandbox Code Playgroud) 应用程序意外崩溃,堆栈溢出错误.经过研究,我发现崩溃的原因是遵循以下代码:
foreach (var item in items)
{
result = result.Concat(item.Data);
}
Run Code Online (Sandbox Code Playgroud)
这是多个IEnumerables的连接.应用程序在items包含10,000个元素时崩溃.
SelectMany解决了这个问题.但还是......
为什么Concat扩展导致堆栈溢出?
我的Quicksort代码适用于N的某些值(列表大小),但对于较大的值(例如,N = 82031),OCaml返回的错误是:
致命错误:异常Stack_overflow.
我究竟做错了什么?
我是否应该创建一个迭代版本,因为OCaml不支持大值的递归函数?
let rec append l1 l2 =
match l1 with
| [] -> l2
| x::xs -> x::(append xs l2)
let rec partition p l =
match l with
| [] -> ([],[])
| x::xs ->
let (cs,bs) = partition p xs in
if p < x then
(cs,x::bs)
else
(x::cs,bs)
let rec quicksort l =
match l with
| [] -> []
| x::xs ->
let (ys, zs) = partition x xs in
append …Run Code Online (Sandbox Code Playgroud) 我正在研究一个用 c 编写的模拟问题,我的程序的主要部分是一个递归函数。当递归深度达到大约 500000 时,似乎发生堆栈溢出。
Q1 : 我想知道这正常吗?
Q2:一般有多少递归函数调用会导致堆栈溢出?
Q3:在下面的代码中,删除局部变量neighbor可以防止堆栈溢出吗?
我的代码:
/*
* recursive function to form Wolff Cluster(= WC)
*/
void grow_Wolff_cluster(lattic* l, Wolff* wolff, site *seed){
/*a neighbor of site seed*/
site* neighbor;
/*go through all neighbors of seed*/
for (int i = 0 ; i < neighbors ; ++i) {
neighbor = seed->neighbors[i];
/*add to WC according to the Wolff Algorithm*/
if(neighbor->spin == seed->spin && neighbor->WC == -1 && ((double)rand() / RAND_MAX) < …Run Code Online (Sandbox Code Playgroud) 我正在研究一个 3 项目解决方案,其细分如下:
Common :包含所有公共类,如 Service 和 Dao 类,实体以及项目使用的所有公共库,如 Spring、Hibernate、Log4J2 等。
Web 客户端:用户看到并与之交互的 Web 应用程序。在其 POM.XML 中具有公共项目的依赖项。
服务:处理消息通信、多个套接字连接、数据库维护、自动执行某些任务等。也依赖于公共库。
在今天之前,只有服务项目有 spring boot 作为它的父项,因为我之前没有探索过在 web 应用程序中使用 spring boot。现在我有了,两个项目现在都使用 spring boot 作为父级,所以我现在将父级部分移到了公共项目中。由于执行此操作并从两个子项目中删除父声明,因此只有服务项目才能正确构建和运行。
我知道 Web 客户端的代码很好,因为它在我进行 POM 更改之前运行良好(在切换到 Spring Boot 样式后也进行了测试)。在尝试清理和构建 Web 客户端时,我收到了这个奇怪的堆栈溢出错误:
Exception in thread "main" java.lang.StackOverflowError
at java.io.FileOutputStream.write(FileOutputStream.java:326)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at java.io.PrintStream.write(PrintStream.java:482)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:104)
at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:185)
at java.io.PrintStream.write(PrintStream.java:527)
at java.io.PrintStream.print(PrintStream.java:669)
at org.apache.maven.cli.PrintStreamLogger.info(PrintStreamLogger.java:110)
at org.codehaus.plexus.logging.AbstractLogger.info(AbstractLogger.java:51)
at org.codehaus.plexus.archiver.AbstractArchiver$1.hasNext(AbstractArchiver.java:464)
at org.codehaus.plexus.archiver.AbstractArchiver$1.hasNext(AbstractArchiver.java:467)
at org.codehaus.plexus.archiver.AbstractArchiver$1.hasNext(AbstractArchiver.java:467)
at org.codehaus.plexus.archiver.AbstractArchiver$1.hasNext(AbstractArchiver.java:467)
at org.codehaus.plexus.archiver.AbstractArchiver$1.hasNext(AbstractArchiver.java:467)
at org.codehaus.plexus.archiver.AbstractArchiver$1.hasNext(AbstractArchiver.java:467) …Run Code Online (Sandbox Code Playgroud) 我的第一个代码块是我的Item Object文件; 第二个是主类.在运行代码没有任何问题之前,但在我添加了读写文件后,我的代码开始收到堆栈流错误.只是调用错误的片段.
public class Item implements java.io.Serializable {
public static String name;
public static double price;
public static double amount;
public int max = 1;
SlayerProgram sp = new SlayerProgram();
ReadFile rf = new ReadFile();
public Item(String name, double price,double amount )
{
this.name = name;
this.price = price;
this.amount = amount;
}
public void ItemSet(String name, double price,double amount)
{
this.name = name;
this.price = price;
this.amount = amount
}
Run Code Online (Sandbox Code Playgroud)
我的主要课程:
public class SlayerProgram {
//import file txts, …Run Code Online (Sandbox Code Playgroud) stack-overflow ×10
java ×4
c# ×3
recursion ×2
.net ×1
async-await ×1
build ×1
c ×1
c#-5.0 ×1
class ×1
exception ×1
fatal-error ×1
http ×1
ios ×1
linq ×1
long-polling ×1
maven ×1
objective-c ×1
ocaml ×1
spring-boot ×1