我有一个GUI应用程序.在我的主类中,我有一个方法(称为createAndShow())来初始化我的所有GUI类.在每个GUI类中,我必须static initializer读取属性文件(资源包或配置文件).如果文件或条目丢失或值错误,我会捕获异常,然后MissingResourceException故意将a抛出到上一级.在我createAndShow()的主类方法中,我放了一个try-catch来捕获Exception.但不知何故,JVM拒绝到达那里.每当文件丢失时,MissingResourceException抛出该文件然后应用程序就会挂起.我希望该createAndShow()方法将捕获该异常并优雅地退出.静态初始化程序的异常抛出有什么特殊之处吗?
我正在使用XP和java 1.6.
使用LiveHttpHeadersfor Firefox 6我试图看看我的css,JS文件是否使用htaccess从Apache使用Headers Module进行缓存.但我很困惑,"Cache-Control"数据中有2个值:
GET /proz/css/global.css HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Accept: text/css,*/*;q=0.1 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Connection: keep-alive Referer: http://localhost/proz/ Cookie: PHPSESSID=el34de37pe3bnp4rdtbst1kd43 If-Modified-Since: Fri, 16 Sep 2011 21:15:32 GMT If-None-Match: "400000000b06a-2999-4ad157e5b4583" Cache-Control: max-age=0 HTTP/1.1 304 Not Modified Date: Sat, 17 Sep 2011 03:04:50 GMT Server: Apache/2.2.17 (Win32) PHP/5.2.8 Connection: Keep-Alive Keep-Alive: timeout=5, max=99 Etag: "400000000b06a-2999-4ad157e5b4583" Cache-Control: max-age=604800, public Vary: Accept-Encoding
哪一个是真实数据,第一个Cache-Control数据(max-age = 0)或后者.
我还想知道在htaccess中使用deflate模块之后如何确保我的JS,CSS,HTML文件被压缩.是的,标题和deflate模块都打开了.
我想识别Java套接字中的数据流结束.当我运行下面的代码时,它只是卡住并继续运行(它停留在值10).
我也希望程序下载二进制文件,但最后一个字节总是不同的,所以我不知道如何停止while(实用).
String host = "example.com";
String path = "/";
Socket connection = new Socket(host, 80);
PrintWriter out = new PrintWriter(connection.getOutputStream());
out.write("GET "+ path +" HTTP/1.1\r\nHost: "+ host +"\r\n\r\n");
out.flush();
int dataBuffer;
while ((dataBuffer = connection.getInputStream().read()) != -1)
System.out.println(dataBuffer);
out.close();
Run Code Online (Sandbox Code Playgroud)
谢谢你的任何提示.
我有这样的代码:
interface Employee
{
string getLastname();
};
#include "Employee.idl"
interface Work
{
Employee getEmployee(in short id);
};
Run Code Online (Sandbox Code Playgroud)
服务器文件:
#include "Employee.hh"
class EmployeeImpl : public POA_Employee
{
private:
char* lastname;
int id;
public:
EmployeeImpl(const char* lastname, int id);
char* getLastname();
};
#include "EmployeeImpl.h"
EmployeeImpl::EmployeeImpl(const char* lastname, int id)
{
this->lastname = const_cast<char*>(lastname);
this->id = id;
}
char* EmployeeImpl::getLastname()
{
return this->lastname;
}
#include "Work.hh"
#include <vector>
#include "EmployeeImpl.h"
using namespace std;
class WorkImpl : public POA_Work
{
private:
vector<EmployeeImpl> employees;
public: …Run Code Online (Sandbox Code Playgroud) 我正在开发一款简单的游戏.我希望for在按钮单击时执行的循环的每次交互中都有小的等待.
我尝试过使用Thread.sleep(2000),但无济于事.
这是按钮点击的代码:
public void playClick(View v) {
String item;
try{
final Handler handler = new Handler();
for (int i = 0; i < stringList.size(); i++) {
Thread.sleep(2000);
item = stringList.get(i);
if(item.equals("left")){
leftclick();
}else if(item.equals("right")){
rightClick();
}else if(item.equals("up")){
upClick();
}else if(item.equals("down")){
downClick();
}
}
}catch(Exception e){
Toast.makeText(this, ""+e.toString(), Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
我想在每次执行for循环时等待.
我正在使用 Eclipse Juno IDE 用 Java 制作数学反应游戏。根据我已经完成的研究,IDE 在保存时将所有内容编译成.class文件字节码!现在的问题是,我尝试从 Windows 机器中将所有内容提取到 JAR中,并将 JAR 提供给一些 beta 测试人员。Beta 测试人员在尝试从 Linux/Mac 访问它时报告了问题。我还知道,我将所有内容提取到的可运行 JAR基本上是一个美化的 ZIP压缩文件,其中包含 JVM 理解和执行的字节码。鉴于我的游戏有多个.java文件,我想知道是否:
将字节码打包到 JAR 中是与机器相关的
我的选择是确保所有用户都能够玩我的游戏并从中受益;还值得指出的是,我的电脑没有 javac.exe;Sun Microsystems 报告该程序已过时
System.out.println("Thanks for your patience in advance!");
Run Code Online (Sandbox Code Playgroud)您好我想尝试运行一些java但是我一直收到错误信息这里是消息:
unreported exception IOException; must be caught or declared to be thrown myName = in.readLine();
import java.io.*;
public class While{
public static void main(String []args){
int num = 0;
while (num != 999){
System.out.println("Enter a number:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
num = Integer.parseInt(in.readLine());
System.out.println("You typed: " + num);
}
System.out.println("999 entered, so the loop has ended.");
}
}
Run Code Online (Sandbox Code Playgroud)
刚刚出去,我没有使用java,这是我第一次使用它,我的老板问我是否可以看看它到目前为止我能做的一切但我无法解决此错误消息,欢迎任何和所有帮助.
我试图从linkedhashset中检索随机元素.下面是我的代码,但它每次都给我例外.
private static void generateRandomUserId(Set<String> userIdsSet) {
Random rand = new Random(System.currentTimeMillis());
String[] setArray = (String[]) userIdsSet.toArray();
for (int i = 0; i < 10; ++i) {
System.out.println(setArray[rand.nextInt(userIdsSet.size())]);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我得到的例外 -
java.lang.ClassCastException: [Ljava.lang.Object; incompatible with [Ljava.lang.String;
谁可以帮我这个事?还有更好的方法吗?
我想知道我想要实现的是否实际上是可能的,我不知道我正在做什么的确切名称因此为什么我不能正确地谷歌搜索结果以及为什么这个主题标题也有点模糊.
我的课程:
AccountConstraint.java:
package dao.constraint;
public class AccountConstraint {
private Range<Integer> accountId;
private String username;
private String password;
private String email;
public AccountConstraint(final Range<Integer> accountId, final String username, final String password, final String email) {
this.accountId = accountId;
this.username = username;
this.password = password;
this.email = email;
}
public Range<Integer> getAccountId() {
return accountId;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getEmail() {
return email;
}
}
Run Code Online (Sandbox Code Playgroud)
Range.java:
package dao.constraint; …Run Code Online (Sandbox Code Playgroud) 我已经看到这个问题了很多,但我仍然无法找到解决方案.那么一个适合我的解决方案.我有一个使用Apache POI的项目,我确保包含所有外部JAR.该项目在eclipse中编译并运行良好,但是当我用" java -jar Test.jar" 运行jar时,我收到此错误:
线程"main"中的异常java.lang.NoClassDefFoundError:org/apache/poi/ss/usermodel/Sheet
我不确定这是否是有用的信息,但我为我的项目创建了一个lib文件夹并将poi库放在那里.这意味着当我创建它时,依赖性在JAR文件中,我想我应该提到这一点,因为我看到了一些关于只在你的可执行jar旁边放置外部jar的解决方案.我也尝试将classpath设置为项目目录.
我似乎做错了什么?