为什么即使抛出异常,以下代码也始终返回true?
public boolean write (ArrayList<String> inputText, String locationToSave){
try {
File fileDir = new File(locationToSave);
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(fileDir), "utf8"));
int index = 0;
int size = inputText.size();
while (index < size) {
out.append(inputText.get(index));
out.append("\n");
index++;
}
out.flush();
out.close();
return true;
} catch (UnsupportedEncodingException e) {
System.out.println("UnsupportedEncodingException is : \n" + e.getMessage());
return false;
} catch (IOException e) {
System.out.println("IOException is : \n" + e.getMessage());
return false;
} catch (Exception e) {
System.out.println("Exception is : \n" …Run Code Online (Sandbox Code Playgroud) 在方法中将自定义对象设置为null(Nothing在VB.NET中)是否有意义Dispose()?这可以防止内存泄漏或无用吗?!
让我们考虑两个例子:
public class Foo : IDisposable
{
private Bar bar; // standard custom .NET object
public Foo(Bar bar) {
this.bar = bar;
}
public void Dispose() {
bar = null; // any sense?
}
}
public class Foo : RichTextBox
{
// this could be also: GDI+, TCP socket, SQl Connection, other "heavy" object
private Bitmap backImage;
public Foo(Bitmap backImage) {
this.backImage = backImage;
}
protected override void Dispose(bool disposing) {
if (disposing) …Run Code Online (Sandbox Code Playgroud) 我有一个页面布局,其中,I必须设置一个div相对和顶部的位置:-30px的DIV相和顶部定位:-30 exactely.
但是下面的DIV然后在顶部30px距离.有没有办法解决这个问题.
我在端口8085上在Eclipse中配置了Tomcat 6.0.24并使用log成功启动,如下所示:
Feb 17, 2010 4:24:31 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;E:\oracle\product\10.2.0\client_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Common Files\Teleca Shared;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;E:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files\MySQL\MySQL Server 5.0\bin;E:\komal-gohil\tools\Subversion\bin;C:\Sun\SDK\bin;e:\instantrails\ruby\bin;c:\program files\java\jdk1.6.0_11\bin;E:\komal-gohil\tools\apache-maven-2.2.1\bin;C:\program files\java\jdk1.6.0_11\bin;E:\komal-gohil\tools\Ant\bin;E:\komal-gohil\tools\apache-tomcat-5.5.17\bin;C:\Sun\SDK\lib\j2ee.jar;E:\komal-gohil\tools\android-sdk-windows-1.6_r1\tools;E:\komal-gohil\tools\Scala\bin;E:\komal-gohil\tools\pax-construct-1.4\bin
Feb 17, 2010 4:24:31 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8085
Feb 17, 2010 4:24:31 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 705 ms
Feb 17, …Run Code Online (Sandbox Code Playgroud) 我是GWT的新手(顺便给它留下了深刻的印象)并且发现它对像我这样熟悉C++/.NET桌面技术的人非常有吸引力,他们愿意编写Web应用程序.
我根据GWT Eclipse Wizard中生成的示例启动了自己的项目.该项目产生与板和主模块的Java类(onModuleLoaded)简单的HTML页面只是简单地创建widgets和它使嵌入到页面.现在我的问题是 - 如何组织代码/项目以在那之间拥有多个html页面和导航.例如,主html页面有一个登录表单和一个登录按钮.如果提供了凭证并按下了登录按钮,则GWT服务在服务器上执行,浏览器导航到第二个html页面.是否有更复杂的样本应用程序可用于此类方案?
谢谢
我刚刚开始调试我的前三行长Android应用程序,我似乎无法像我想的那样使用调试工具.这是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int a = 1 / 0;
}
Run Code Online (Sandbox Code Playgroud)
现在我希望调试器停止该线程并向我显示除以零的语句行号.不,相反,它显示了我没有来源的系统内部的一些其他方法.更糟糕的是,也没有异常消息.
在这个应用程序之前,我创建了一个在按下按钮时会执行某项操作的应用程序.如果引发任何异常,则不会再显示有用的行号或异常消息.
截至目前,无法调试我的应用程序.有任何想法吗?
我正在使用最新的SDK以及Eclipse ADT插件并在真实设备(Nexus One)上进行调试.
我正在尝试使用javascript将日期对象转换为有效的mysql日期 - 这样做的最佳方法是什么?
所以Safari和Chrome已经开始尝试实现一些ES5的东西了.例如,Object.create就在其中.
如果有一个网站显示浏览器的进展,你们有没有人知道吗?ATM我需要使用Object.freeze,并希望看到支持哪些浏览器(如果有的话).
使用jsf 1.2,hibernate,richfaces 3.3.0GA和facelets.
我在我的支持bean中有这个代码:
public List<Rater> getFreeRaters(){
GP myGP = (GP) user;
update(myGP.getContract());
ArrayList<Rater> raters = new ArrayList<Rater>(myGP.getContract().getRaters());
ArrayList<Rater> selectedRaters = this.getSelectedRaters();
raters.removeAll(selectedRaters);
return raters;
}
Run Code Online (Sandbox Code Playgroud)
这个用户界面的代码:
<a4j:form id="gradersForm" ajaxSingle="true">
<rich:listShuttle sourceValue="#{user.gradersTab.freeRaters}" id="gradersTab_listShuttle"
targetValue="#{user.gradersTab.selectedRaters}" var="rater" listsHeight="150"
sourceListWidth="130" targetListWidth="130" sourceCaptionLabel="Available Items"
targetCaptionLabel="Currently Active Items" >
<rich:column>
<h:outputText value="#{rater.username}"></h:outputText>
</rich:column>
</rich:listShuttle>
<a4j:commandButton value="Save"></a4j:commandButton>
</a4j:form>
Run Code Online (Sandbox Code Playgroud)
这是我的会话过滤器:
public class HibernateSessionRequestFilter implements Filter {
private static Log log = LogFactory.getLog(HibernateSessionRequestFilter.class);
private SessionFactory sf;
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException, ServletException { …Run Code Online (Sandbox Code Playgroud)