出于某种原因,当我在Random类中不使用种子时,此代码工作正常,但如果我尝试使用DateTime.Now获取更随机的数字,我会得到StackOverflowException!我的课非常简单.有人能告诉我这里我做错了什么吗?请参见MakeUniqueFileName.
public class TempUtil
{
private int strcmp(string s1, string s2)
{
try
{
for (int i = 0; i < s1.Length; i++)
if (s1[i] != s2[i]) return 0;
return 1;
}
catch (IndexOutOfRangeException)
{
return 0;
}
}
private int Uniqueness(object randomObj)
{
switch (randomObj.ToString())
{
case "System.Object":
case "System.String":
return randomObj.ToString()[0];
case "System.Int32":
return int.Parse(randomObj.ToString());
case "System.Boolean":
return strcmp(randomObj.ToString(), "True");
default:
return Uniqueness(randomObj.ToString());
}
}
public string MakeUniqueFileName()
{
return "C:\\windows\\temp\\" + new Random(Uniqueness(DateTime.Now)).NextDouble() + ".tmp";
}
}
Run Code Online (Sandbox Code Playgroud) 我已经实现了可以在此链接下找到的递归算法.当3d数组为10x10x10时,它工作得很好.
我试图让它运行200x200x200阵列然而,Visual Studio说我可能正在进行无限的恢复(我很确定我的编程没问题).有办法处理吗?我已经尝试[DebuggerNonUserCode]
在递归方法之前放右,但它没有奏效.
忘了提,它是Visual Studio 2010.
这是我的程序的递归函数.我正在为每个单元格运行,标记为Unvisited.
public static int tmp_lowest_floor = 0;
public static int tmp_maks_size = 0;
static void function1(Point[, ,] array, int pos_y, int pos_z, int pos_x) // recursive function
{
Point cell = array[pos_y, pos_z, pos_x];
if (cell.Visited == false && cell.IsCave)
{
cell.Visited = true; // changing to visited so we do not count anything for this cell anymore
tmp_maks_size++; // increasing for each cell in this cave (in this run) …
Run Code Online (Sandbox Code Playgroud) 我有一些枚举声明,因为我不明原因导致StackOverflowException.
我有以下内容:
public enum PrimaryAttribute
{
Strength,
Agility,
Intelligence
}
public enum Class
{
Tank,
Fighter,
Sorcerer
}
public class Hero
{
public PrimaryAttribute PrimaryAttribute { get; private set; }
public Class Class
{
get
{
return Class;
}
set
{
if (Class == Class.Tank)
{
PrimaryAttribute = PrimaryAttribute.Strength;
IsBlocking = true;
}
else if (Class == Class.Fighter)
{
PrimaryAttribute = PrimaryAttribute.Agility;
IsBlocking = false;
IsDodging = true;
}
else if (Class == Class.Sorcerer)
{
PrimaryAttribute = PrimaryAttribute.Intelligence;
IsBlocking = …
Run Code Online (Sandbox Code Playgroud) 我的导航器菜单有一个非常有趣的问题。我不知道为什么...但我可以点击菜单中的任何项目,我不想说我点击后什么也没发生。我真的想说我不能点击任何项目,我所有的菜单就像一个大图像。我已经尝试创建一个新项目女巫已经有导航抽屉活动,当然它可以工作..但是当我尝试复制该代码并穿上我的..我有同样的问题,反之亦然,我已经尝试将我的代码放入带有导航抽屉活动的新项目中,但同样......我无法点击任何项目。
图片 -这个麻烦
图片 -无法点击
这是我的代码:
菜单栏.java
package com.database.m.lyburan;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonArrayRequest;
import com.database.m.lyburan.adapter.EventAdapter;
import com.database.m.lyburan.app.AppController;
import …
Run Code Online (Sandbox Code Playgroud) 我有以下用c#编写的幂函数:
public static double pow2(double x, double n)
{
if (n == 0)
return 1;
else
{
stepAccumulator++;
return pow2 (x, Math.Floor (n / 2.0)) * pow2 (x, Math.Ceiling (n / 2));
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,我只是说result=pow2(1,1000);
,然后使用Stopwatch
对象计时,然后在结尾打印结果.不幸的是,当我运行此程序时,我收到以下错误:由于StackOverflowException,进程终止.为什么会这样,我怎么能阻止它呢?
请帮助我,谁在下面看到这个错误:
**04-24 23:24:21.012: I/dalvikvm(327): threadid=1: stack overflow on call to Ljava/lang/Class;.isPrimitive:Z**
04-24 23:24:21.012: I/dalvikvm(327): method requires 4+20+0=24 bytes, fp is 0x430c9314 (20 left)
04-24 23:24:21.012: I/dalvikvm(327): expanding stack end (0x430c9300 to 0x430c9000)
04-24 23:24:21.073: I/dalvikvm(327): Shrank stack (to 0x430c9300, curFrame is 0x430cbeb8)
04-24 23:24:21.073: D/AndroidRuntime(327): Shutting down VM
04-24 23:24:21.073: W/dalvikvm(327): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-24 23:24:21.512: D/dalvikvm(327): GC_FOR_MALLOC freed 4475 objects / 369040 bytes in 192ms
04-24 23:24:21.512: E/AndroidRuntime(327): FATAL EXCEPTION: main
04-24 23:24:21.512: E/AndroidRuntime(327): java.lang.StackOverflowError …
Run Code Online (Sandbox Code Playgroud) 我的代码有问题.我终于得到它所以没有错误,但现在我必须处理stackoverflow ...
谁能告诉我我的代码有什么问题?
public Matrix Projection
{
get { return Projection; }
protected set
{
Projection = value;
generateFrustum();
}
}
Run Code Online (Sandbox Code Playgroud)
如果你可以帮忙的话会很好!
谢谢
在我的应用程序中,我通过IP地址通信从另一个系统数据库访问数据.
所以为此,如果数据库系统当时处于脱机状态,则在连接期间发生异常,因此在catch块中我再次调用run()方法,当它到达联机正常的应用程序执行流程时.但在这个过程中我得到"线程中的异常"Thread-1"java.lang.StackOverflowError"这个异常如何在我的场景中解决这个异常.
这是我的代码:
MAIN CLASS :-
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LsduJFrame().setVisible(true);
}
});
new Thread(new DisplayPlazaNameLocation()).start();// i am calling here
}
DisplayPlazaNameLocation:-
public class DisplayPlazaNameLocation implements Runnable{
static String plazaNameLocation;
static Connection con;
int i =0;
public void getPlazaNameLocation(){
try {
System.out.println("in getPlazaNameLocation()==============================================");
PreparedStatement pst=con.prepareStatement("SELECT DISTINCT Plaza_Loc FROM lsdu_live");
ResultSet rs = pst.executeQuery();
while(rs.next()){
plazaNameLocation = rs.getString("Plaza_Loc");
//System.out.println(plazaNameLocation);
}
String ar[] = plazaNameLocation.split(",");
jLabel199.setText("<html>"+ar[0]+"<br>"+ar[1]+"</html>");
rs.close();
pst.close();
con.close();
} catch (SQLException …
Run Code Online (Sandbox Code Playgroud) 我不能使用Obfuscator.io来uglify我的JS脚本,因为它包含一个setTimeout
调用自身的函数.
MCVE:
function repeater() {
// DO SOME STUFF...
setTimeout(repeater, 100);
}
repeater();
Run Code Online (Sandbox Code Playgroud)
重现所需的自定义模糊处理设置:
- 标识符名称生成器:Mangled
- 保留名称:$- jQuery
Obfuscator.io的错误消息:
错误:类t中的@postConstruct错误:类t中的@postConstruct错误:超出了最大调用堆栈大小
我已经阅读了其他一些Stack Overflow问题.据我所知,调用setTimeout(func)
里面func
是不实际的递归.
但是,Obfuscator.io的算法仍然无法处理自我调用的setTimeout
延迟.
如何在setTimeout
不在函数本身中调用它的情况下使用重复执行的函数?我不想使用,setInterval
因为我想在函数代码运行后每次都开始延迟. setInterval
忽略了这一点.
c# ×5
android ×2
java ×2
enums ×1
javascript ×1
jquery ×1
obfuscation ×1
random ×1
settimeout ×1
unhandled ×1
xna ×1