我试图在Java中创建一个类,它构建一个类型的对象,Action它包含三个int并将它返回到我在数组中的另一个类history,其中history是一个类型的数组Action.当它被调用时,我立刻得到一个无限循环; 因此堆栈溢出.
错误 - 我打印了1行,它继续...
Exception in thread "main" java.lang.StackOverflowError
at sudokugame.Action.<init>(Action.java:7)
Run Code Online (Sandbox Code Playgroud)
类:
public class Action {
Action a;
public Action(int i, int o, int p){
a = new Action(i,o,p);
}
public void setAction(int n, int b, int c){
}
public Action getAction(){
return a;
}
}
Run Code Online (Sandbox Code Playgroud) 我已经编写了下面的代码.但它会打印出这个异常,我真的不知道它的问题是什么,请帮助我谢谢
码:
private void fillMinAverageTime() { //T(n) = O(n^3)
for (int i = list.size() - 2; i >= 0; i--) {
for (int j = i + 1; j < list.size(); j++) {
for (k = i; k <= j; k++) {
minOne = fillMinAverageTimeArray(i, j);
if (min == 0.0) {
min = minOne;
} else if (minOne < min) {
min = minOne;
}
}
min = 0.0;
minOne = 0.0;
minAverageTimeArray[i][j] = min + probability[i][j];
}
}
} …Run Code Online (Sandbox Code Playgroud) 所以,我开始研究这个庞大的项目.这是一个巨大的类,有数百个变量和方法以及许多部分类.
interface IBusinessReturn
{
string variableOne { get; set; }
string variableTwo { get; set; }
string variableHundred { get; set; }
//a lot more...
}
public partial class BusinessTransaction : IBusinessReturn
{
private string _variableOne;
public string variableOne
{
get { return variableOne; }
set { _variableOne= value; }
}
private string _variableTwo;
public string variableTwo
{
get { return variableTwo; }
set { _variableTwo = value; }
}
private string _variableHundred;
public string variableHundred
{
get { return …Run Code Online (Sandbox Code Playgroud) 我使用valgrind来找出堆栈方向的混乱问题.
看下面的代码,我想知道为什么运算符"p1 + = 0x80;*p1 = 1"有效且运算符"p2 - = 0x80;*p2 = 1"根据valgrind无效写入?
我认为所有的变量都根据操作系统在堆栈中分配,并且它正在增长到较低的地址,所以我认为" - ="是有效的,而"+ ="是无效的,因为它可能比较大到堆栈顶部可能不在堆栈限制中.
#include <stdlib.h>
int main()
{
int a;
int *p1 = &a;
p1 += 0x80;
int *p2 = &a;
*p1 = 1;
p2 -= 0x80;
*p2 = 1;
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud) 我需要处理大数字的浮点数(> 200,000个数字)并对这些数组执行一些数学运算.
您建议如何处理这些数组,以免出现任何堆栈溢出问题?
更新:我想做简单和复杂的数学运算(sums,products,sin,cos,arctan).
通过介绍,我正在为个人学习目的创建一个基本的Quadtree引擎.我希望这个引擎能够处理许多不同类型的形状(目前我正在使用圆形和方形),这些形状将在窗口中移动并在发生碰撞时执行某种操作.
在先前询问关于通用列表主题的问题后,我决定使用多态性接口.最好的界面是一个界面利用,Vector2因为我的四叉树中出现的每个对象都有一个x,y位置,Vector2并且很好地覆盖了它.这是我目前的代码:
public interface ISpatialNode {
Vector2 position { get; set; }
}
public class QShape {
public string colour { get; set; }
}
public class QCircle : QShape, ISpatialNode {
public int radius;
public Vector2 position {
get { return position; }
set { position = value; }
}
public QCircle(int theRadius, float theX, float theY, string theColour) {
this.radius = theRadius;
this.position = new Vector2(theX, theY);
this.colour = theColour;
}
}
public class …Run Code Online (Sandbox Code Playgroud) 我在构建课程时遇到问题,
以下代码抛出异常
public class Agent extends Board{
private static boolean arrow;
private static boolean backmove;
private static boolean gotGold;
private static int atlocationX;
private static int atlocationY;
private static int faceposition;
private static int pathcounter;
public boolean temporaryGold;
public boolean temporaryWumpus;
public boolean temporaryStench;
public boolean temporaryBreeze;
public boolean temporaryPit;
int agentgui = 0;
int label = 0;
Block blockstorage[][] = new Block[4][4];
KnowledgeBase kb = new KnowledgeBase();
public Agent() {
super();
}
public void Agent(){
Agent.arrow = true;
Agent.faceposition …Run Code Online (Sandbox Code Playgroud) double我想,可以代表的最高数字是非常高的.虽然以下代码抛出异常.这实际上是我的完整代码.
public class Summe {
public static void main(String[] args) {
System.out.println(summe(20000));
}
public static double summe(double s) {
return s == 0 ? s : s + summe(s-1);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你到目前为止的答案.我的问题是:我如何使我的代码工作?
我不知道为什么我无法处理由该代码引起的此异常:
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
int id = int.Parse(((DataRowView)checkedListBox1.Items[i])[0].ToString());
bool check = checkedListBox1.GetItemChecked(i);
DataRow[] dr = dt.Select("id = " + id.ToString());
dr[0][2] = check;
}
}
catch (StackOverflowException) { }
}
Run Code Online (Sandbox Code Playgroud)
注释部分所在的位置说有StackOverflowError- null。我试图使它成为随机数以匹配输入的值。此代码的目标是执行以下操作:
码:
import java.util.*;
public class ArrNumGuess
{
public static Integer top, input, guess, count;
public static ArrayList <Integer> nums;
public static void main ()
{
System.out.println("Please enter the top number");
top = (new Scanner(System.in)).nextInt();
System.out.println("Please enter the number to guess (1 - " + top + ")");
input = Integer.parseInt(((new Scanner(System.in)).nextLine()).trim());
nums = new ArrayList<Integer>(); //use nums.contains(guess);
guess = (new Random()).nextInt(top) + 1;
nums.add(guess);
System.out.println("My first …Run Code Online (Sandbox Code Playgroud)