Calendar c = Calendar.getInstance();
long diff = c.getTimeInMillis() - DateSaved.getTimeInMillis(); //result in millis
long daysDiff = (diff / (24 * 60 * 60 * 1000));
Run Code Online (Sandbox Code Playgroud)
一切正常,当我打印差异(整数天)...
问题从这里开始:
int daysDiffINT = (int) daysDiff;
int daysRemaining = (sumaINT/dailyINT) - daysDiffINT;
Run Code Online (Sandbox Code Playgroud)
我需要使用一些int值继续我的long diff.
上面这个不起作用.控制台给我一个错误:"无效的int"我搜索了一下,有成千上万的转换字符串到Int等.
但是我怎么能从长时间获得int?或长串?
这让我疯狂 :(
//大感谢大家 - 你已经学会了我如何制作自己的应用:)
我正在尝试使用这些方法在屏幕的矩形区域中查找颜色。但是有时屏幕上有数百万个像素,而我现在仅每秒实现约35次getColor迭代。我的代码中一定有某些东西导致它运行非常缓慢。
我怎么能比这更快地扫描屏幕?理想情况下,我想在不到一秒钟的时间内扫描整个屏幕以获取一种颜色,而不是现在的8个小时:P
这是我的两种方法。
public static int getColor(int x, int y){
try{
return(robot.getPixelColor(x, y).getRGB() * -1);
}catch(Exception e){
System.out.println("getColor ERROR");
return 0;
}
}
//returns first instance of color,
//Begins top left, works way down to bottom right
public static Point findColor(Box searchArea, int color){
System.out.println("Test");
if(searchArea.x1 > searchArea.x2){
int temp = searchArea.x1;
searchArea.x1 = searchArea.x2;
searchArea.x2 = temp;
}
if(searchArea.y1 > searchArea.y2){
int temp = searchArea.y1;
searchArea.y1 = searchArea.y2;
searchArea.y2 = temp;
}
for(int i = searchArea.x1;i <=searchArea.x2; i++){
for(int …Run Code Online (Sandbox Code Playgroud) 我正在研究一个用java自动输入内容的系统.这是我写它的方式:
public void typeMessage(String message) {
for (char c : message.toCharArray()) {
int code = c;
if (code > 96 && code < 123)
code = code - 32;
if (c == '@') {
robot.keyPress(VK_SHIFT);
robot.keyPress(VK_AT);
robot.keyRelease(VK_SHIFT);
robot.keyRelease(VK_AT);
} else {
type(code);
}
}
type(VK_ENTER);
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
Exception in thread "Thread-2" java.lang.IllegalArgumentException: Invalid key code
Run Code Online (Sandbox Code Playgroud)
上
robot.keyPress(VK_AT);
Run Code Online (Sandbox Code Playgroud) 这是我的代码的样子:
double test = (21757952*100)/63290718;
Log.i("TAH", "test = " +test);
Run Code Online (Sandbox Code Playgroud)
它显示"test = -33"
为什么价值错了?它溢出了吗?