哪个是更好的选择:
HashMap初始大小:HashMap hm = new HashMap(10);或HashMap没有初始大小:HashMap hm = new HashMap()?为什么?
还什么是loadfactor和modcount在HashMap的财产?
当我在eclipse中调试我的代码并查看HashMap它的值时,它显示了一个名为loadfactor0.75的属性和一个名为modcount3 的属性.
我在代码中使用hashmap的地方: -
我正在开发一个通信应用程序,你可以说一个聊天应用程序.其中我将所有发送/接收的消息存储在HashMap中.现在因为我无法假设用户将发送/接收多少消息我声明没有初始容量的hashmap.我写的是
Map<String, Map<String, List<String>>> usersMessagesMap = new HashMap<String, Map<String,List<String>>>();
Run Code Online (Sandbox Code Playgroud)
如果我使用它的初始容量为100或更高,它会影响代码吗?
=image_tag('/images/public_stream_page/overlay_image.png',
:onload=>"document.getElementById('dd_mid_right_box_public').style.background='url(#{stream.asset.url(:normal)})';")
Run Code Online (Sandbox Code Playgroud)
这是我的haml代码来显示图像
所以我得到了这个错误
The line was indented 2 levels deeper than the previous line.
Run Code Online (Sandbox Code Playgroud)
怎么解决?
我似乎做的一切都是正确的.我只需要实现一个简单JMenuBar但似乎无法正常工作.有人可以帮我解决这个问题吗?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class swing {
public static void main (String[] args) {
JFrame frame = new JFrame ("menu");
frame.setVisible (true);
frame.setSize (400, 400);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar bar = new JMenuBar ();
frame.setJMenuBar (bar);
bar.setVisible (true);
JMenu file = new JMenu ("File");
bar.add (file);
JMenuItem open = new JMenuItem ("open");
file.add(open);
}
}
Run Code Online (Sandbox Code Playgroud) 使用hibernate添加新记录时,我有以下异常.我也在使用Hibernate搜索来创建索引.
这是我的例外.
Jun 11, 2009 1:01:23 PM org.hibernate.LazyInitializationException <init>
SEVERE: could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.unproxy(DocumentBuilderIndexedEntity.java:505)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:397)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:456)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:456)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:386)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:334)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.addWorkToQueue(DocumentBuilderIndexedEntity.java:302)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.addWorkToBuilderQueue(BatchedQueueingProcessor.java:153)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.processWorkByLayer(BatchedQueueingProcessor.java:140)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:128)
at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:40)
at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsBeforeTransactionCompletion(JDBCTransaction.java:274)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:140)
at com.tis.purchasedetails.dao.PurchaseDetailsDAO.savePurchaseDetails(PurchaseDetailsDAO.java:422)
at com.tis.purchasedetails.presentation.PurchaseItemsAction.execute(PurchaseItemsAction.java:56)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at …Run Code Online (Sandbox Code Playgroud) 如何在RoR中为外键命名?
我使用以下命令给出外键:
rails generate scaffold Table2 id:integer Table1:references
Run Code Online (Sandbox Code Playgroud)
此命令adds foreign key of Table1 in Table2但具有默认名称Table1_id.那么我怎么能给它自定义名称,my_table_f_key而不是Table1_id.
我正在使用Ruby 1.9.2和Rails 3.0.3.
编辑:-
在我的project.rb模型中:
belongs_to :own, :class_name => User
Run Code Online (Sandbox Code Playgroud)
在我的user.rb模型中:
has_many :owned_projects, :class_name => Project, :foreign_key => :owner
Run Code Online (Sandbox Code Playgroud)
我是如何创建项目模型的
rails generate scaffold Project name:string owner:integer
Run Code Online (Sandbox Code Playgroud)
现在,当我从Project访问user_id时
project.owner.userid会抛出异常.
我是Java的新手(实际花了三天),但我必须编写一个自定义的跨平台编辑器应用程序作为我的数据库的接口.实际上一切都运行顺利,但我有一个奇怪的包错误.inb4 3年的Python和AS3编程.
我正在尝试扩展java.util.ArrayList并加入add方法覆盖.代码看起来像这样:
package myxmleditor;
public class BarsList<EditorXMLObject> extends
java.util.ArrayList<EditorXMLObject> {
@Override
public boolean add(EditorXMLObject element) {
editorGUI.addEditorPane(element); // error here
return super.add(element);
}
public EditorGUIInterface editorGUI = null;
}
Run Code Online (Sandbox Code Playgroud)
BarsList,EditorGUIInterface和EditorXMLObject都在myxmleditor包中.addEditorPane方法是
EditorGUIInterface.addEditorPane(EditorXMLObject element)
Run Code Online (Sandbox Code Playgroud)
NetBeans向我显示错误:
method addEditorPane in class myxmleditor.TsukasaXMLEditGUI cannot be applied to given types;
required: **myxmleditor.EditorXMLObject**
found: **EditorXMLObject**
reason: actual argument EditorXMLObject cannot be converted to myxmleditor.EditorXMLObject by method invocation conversion
Run Code Online (Sandbox Code Playgroud) 我正在使用jFreechart创建一个饼图,并在iText中创建的pdf中添加图表.问题是图表始终添加在页面底部而不是最后一行之后.
重新生成错误的示例代码是:
Document document = new Document();
PdfWriter writer;
File file = new File("c:/myPdf.pdf");
writer = PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
try {
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("OPT 1", 10);
pieDataset.setValue("OPT 2", 0);
pieDataset.setValue("OPT 3", 17);
pieDataset.setValue("OPT 4", 11);
JFreeChart chart = ChartFactory.createPieChart3D("Option click count",
pieDataset, true, false, false);
final PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setNoDataMessage("No data to display");
chart.setTitle(new TextTitle("Option Click Count", new Font("Times New Roman", Font.PLAIN, 14)));
PdfContentByte pdfContentByte = writer.getDirectContent();
PdfTemplate pdfTemplateChartHolder = pdfContentByte.createTemplate(225,225);
Graphics2D graphicsChart = …Run Code Online (Sandbox Code Playgroud) 我的程序编译并运行,但这是我的问题.我为每个项目设置了一个复选框,但我只需要它来检查已检查的项目而不是所有项目.相反,它总计所有项目,无论它们是否被检查.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.GridLayout;
import java.text.*;
public class StudentShopping extends JFrame
{
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(550, 400); //Sets size of the window
frame.setTitle("Student Shopping");//Adds title to the GUI
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JCheckBox ClothingCheckBox = new JCheckBox();
JLabel Clothinglbl = new JLabel("Clothing");
final JTextField ClothingField = new JTextField(3);
ClothingField.setText("0");
JCheckBox BooksCheckBox = new JCheckBox();
JLabel Bookslbl = new JLabel("Books");
final …Run Code Online (Sandbox Code Playgroud) 我是rails的初学者,我有这么多次:
["08:30","09:00","09:30","10:00","10:30","11:00","11:30","12:00"," 12:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16: 30","17:00","17:30","18:00","18:30","19:00","19:30","20:00","20:30" ,"21:00","21:30"]
如何使用它将其转换为下拉列表options_from_collection_for_select.我试过用
<%= select_tag "start_time", options_from_collection_for_select(@start_time,:id, :name ) %>
但它回来了"undefined method 'name' for "08:30":String".
我想在java swing应用程序中显示标题分隔符.就像是
- - - -文本 - - - -
我找到了一些提供此功能的第三方库:
但我对不使用任何第三方API的方式感兴趣.我们可以通过扩展JSeparator来做到这一点吗?我们还能怎么做?