所以,我对这段代码感到困惑:
import java.util.InputMismatchException;
import java.util.Scanner;
public class ConsoleReader {
Scanner reader;
public ConsoleReader() {
reader = new Scanner(System.in);
//reader.useDelimiter(System.getProperty("line.separator"));
}
public int readInt(String msg) {
int num = 0;
boolean loop = true;
while (loop) {
try {
System.out.println(msg);
num = reader.nextInt();
loop = false;
} catch (InputMismatchException e) {
System.out.println("Invalid value!");
}
}
return num;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的输出:
插入整数:
无效的值!
插入整数:
无效的值!
...
是否可以在运行时更改密钥库?目前我在设置server.start()之前设置SSL
sslContextFactory.setTrustStore(ks);
sslContextFactory.setTrustStorePassword(TRUSTSTORE_PASS);
sslContextFactory.setKeyStorePassword(KEYSTORE_PASS);
ServerConnector https = new ServerConnector(server, sslContextFactory);
server.start()
Run Code Online (Sandbox Code Playgroud)
我想要做的是在运行时创建一个证书并使用它.基本上我正在创建一个像Fiddler这样的工具,可以动态创建证书.
我正在使用用C编写的Windows启动程序启动我的Java软件.它基本上加载了jvm.dll并使用它来初始化JVM而不使用javaw.
现在,我尝试在64位上编译它,并从64位Java安装加载正确的jvm.dll.
现在,Java程序启动了,但是与hs_err_pid文件崩溃了.好像AWT正在崩溃.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (os_windows_x86.cpp:149), pid=8812, tid=10816
# guarantee(result == EXCEPTION_CONTINUE_EXECUTION) failed: Unexpected result from topLevelExceptionFilter
#
# JRE version: 7.0_10-b18
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.6-b04 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please …Run Code Online (Sandbox Code Playgroud) 我想知道,-->--运营商在Java中做了什么?
例如,如果我有以下代码:
int x = 3;
int y = 3;
if (x -->-- y) {
return true;
}
Run Code Online (Sandbox Code Playgroud)
这总是返回true.
谢谢!
出现错误 - case 表达式必须是常量表达式当我尝试在 switch case 语句中使用 enum 类时,:
我的枚举类是,
public enum TestEnumClass {
TEST1("TEST1"),
TEST2("TEST2"),
TEST3("TEST3");
private String enumConstant;
private TestEnumClass(String algoConstant) {
this.enumConstant = algoConstant;
}
public String getEnumConstant() {
return enumConstant;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图在另一个类文件中使用 enum TestEnumClass 如下,
public class TestIndexOf {
public static void main(String[] args) {
String str = args[0];
switch(str){
case TestEnumClass.Test1.getEnumConstant() : System.out.println("test1"); break;
case TestEnumClass.Test2.getEnumConstant() : System.out.println("test2"); break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它给了我编译时错误:
case 表达式必须是常量表达式
请建议我,我哪里出错了。
每次启动Visual Studio 2012时,大约有6个文件会自动打开,即使它们在上一个会话中已经关闭了.我怎样才能使这些文件在每次启动时不再自动打开,所以我不再需要手动关闭它们?
我正在使用Method.invoke()来调用第三方jar中的函数.有时我会抛出java.lang.reflect.InvocationTargetException.你怎么能弄清楚真正的例外是什么呢?
我正在尝试启动位于http://gparyani.com/beatbox.jnlp的JNLP ,但是当我尝试这样做时,我在内部类中得到NullPointerException:
java.lang.NullPointerException
at com.sun.deploy.security.SandboxSecurity.showSandboxDialog(Unknown Source)
at com.sun.deploy.security.SandboxSecurity.checkSignedSandboxSecurity(Unknown Source)
at com.sun.deploy.security.SandboxSecurity.isPermissionGranted(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResourcesHelper(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResources(Unknown Source)
at com.sun.javaws.Launcher.prepareResources(Unknown Source)
at com.sun.javaws.Launcher.prepareAllResources(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main.access$000(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
这是JNLP:
<jnlp spec="1.0+" codebase="http://gparyani.com/">
<information>
<title>BeatBox</title>
<vendor>Gaurav Paryani, Nick Hoang, and Harrison Qi</vendor>
<offline-allowed/>
</information>
<update check="background" policy="prompt-run"/>
<resources>
<j2se version="1.7+"/>
<jar href="beatbox.jar" main="true"/>
</resources>
<application-desc main-class="com.gparyani.beatbox.GUIMaker"/>
</jnlp>
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?
在查看java.lang.System类的实现时,我发现:
public final static PrintStream out = null;
Run Code Online (Sandbox Code Playgroud)
仅从这个定义,我可以说,价值System.out永远是null.但是,它在程序启动时初始化(使用System.initializeSystemClass()JVM自动调用的方法),并且我可以使用System.setOut执行安全检查的值来更改其值,然后将调用委托给setOut0方法,该native方法是更改值的方法的System.out.为什么我可以改变它的值,System.out即使它被声明了final?
我想知道:MD5编码数据吗?因为当它对哈希进行编码时,即使你对数PB的数据进行编码,它也只是32位.
MD5是对数据进行编码还是只是将哈希键拉出来进行比较?
或者我只是误解了"编码"一词?
我有以下API代码,为简洁起见缩短了:
public class Vec
{
Vec(int x, int y, int z) {/*implementation*/}
//other fields and methods irrelevant to question and not shown
}
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试在与上面的类不同的包中编写代码,该类使用反射来调用该类的构造函数并创建它的新实例.这是我尝试过的(下面的代码在我的应用程序的main方法中):
Constructor<Vec> c = Vec.class.getConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE);
c.setAccessible(true);
Vec newVec = c.newInstance(1, 2, 3);
Run Code Online (Sandbox Code Playgroud)
但是,运行上面的代码时,后一代码的第一行会出现异常:
Exception in thread "main" java.lang.NoSuchMethodException: somePackages.Vec.<init>(int, int, int)
Run Code Online (Sandbox Code Playgroud)
为什么它仍然提供该异常,即使该构造函数仍然存在?我正在使用oracle-java8-jdk我的Raspberry Pi 运行此代码,如果这有帮助的话.
java ×10
c# ×1
certificate ×1
constants ×1
constructor ×1
cryptography ×1
encoding ×1
enums ×1
int ×1
integer ×1
java-7 ×1
java-opts ×1
jetty ×1
jvm ×1
jvm-crash ×1
nosuchmethod ×1
operators ×1
reflection ×1
security ×1
ssl ×1
system.out ×1
windows ×1