java-7

Access is denied while compiling Java on Windows

喜欢而已 提交于 2019-11-28 00:27:36
问题 I created two java files: Pizza.Java and PizzaOrder.Java . I tried compiling my code using javac in the command prompt like this: javac pizzaorder.java I am getting access is denied error: C:\Users\Meutex>cd\ C:\>cd "Program Files\Java\jdk1.7.0\bin" C:\Program Files\Java\jdk1.7.0\bin>javac PizzaOrder.java PizzaOrder.java:23: error: cannot find symbol Pizza order = new Pizza (); ^ symbol: class Pizza location: class PizzaOrder PizzaOrder.java:23: error: cannot find symbol Pizza order = new

JComboBox returning values

老子叫甜甜 提交于 2019-11-28 00:23:15
What method is used to return the selection chosen by the user? JPanel ageSelection = new JPanel(); JLabel age = new JLabel("Age:"); ArrayList<Integer> ageList = new ArrayList<Integer>(); for (int i = 1; i <= 100; ++i) { ageList.add(i); } DefaultComboBoxModel<Integer> modelAge = new DefaultComboBoxModel<Integer>(); for (Integer i : ageList) { modelAge.addElement(i); } JComboBox<Integer> ageEntries = new JComboBox<Integer>(); ageEntries.setModel(modelAge); ageEntries.addActionListener(new putInTextListener()); ageSelection.add(age); ageSelection.add(ageEntries); class putInTextListener

What's the implementation of hashCode in java Object? [duplicate]

*爱你&永不变心* 提交于 2019-11-27 23:46:42
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How is hashCode() calculated in Java I found there's no implementation in hashCode() method of root class Object in Java: public native int hashCode(); If I have an Object a and an Object b , how can I know the a.hashCode() and b.hashCode() value without using System.out.println() ? Just by the hashCode implementation. I have try to new two ArrayList objects and to my big surprise the hashCode() values are the

how to fix “Failed to write core dump. Core dumps have been disabled” error while running java

陌路散爱 提交于 2019-11-27 23:39:52
i am using eclipse to develop a web application and i have encountered a problem when i am trying to run my application on server from within eclipse. # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007f41e4e610b0, pid=3463, tid=139924549404416 # # JRE version: 7.0_09-b05 # Java VM: Java HotSpot(TM) 64-Bit Server VM (23.5-b02 mixed mode linux-amd64 compressed oops) # Problematic frame: # C [libwebkitgtk-1.0.so.0+0x11670b0] void WTF::freeOwnedGPtr<_GdkEvent>(_GdkEvent*)+0x15e00 # # Failed to write core dump. Core dumps have been disabled. To

Change background color editable JComboBox

拈花ヽ惹草 提交于 2019-11-27 23:20:03
I am programming an editable combobox in a JFrame Form, but i want to change te background color. How the program works: If i click the button "press", then the combobox his background needs to become black. I tried: 1. cbo.setBackground(Color.BLACK); But it did nothing 2 cbo.getEditor().getEditorComponent().setBackground(Color.BLACK); ((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true); Does this: Code example: public class NewJFrame extends javax.swing.JFrame { private JComboBox cboCategorie; public NewJFrame() { initComponents(); cboCategorie = new JComboBox(); cboCategorie

Java ternary operator influence on generics type inference

我的梦境 提交于 2019-11-27 22:57:05
问题 public List<String> foo1() { List<String> retval = bar(); if (retval == null) return Collections.emptyList(); else return retval; } public List<String> foo2() { List<String> retval = bar(); return retval == null ? Collections.emptyList() : retval; } Why does foo1() compiles fine whereas foo2() has an error? (to be more precise "Type mismatch: cannot convert from List<capture#1-of ? extends Object> to List<String>" ) I would have thought that both functions would compile to the same bytecode,

Java 7 Watch Service ENTRY_CREATE triggered before file is written

a 夏天 提交于 2019-11-27 22:30:58
问题 I have a watch service watching a directory. Once files are created, I'm processing the directory and updating a tree view. This works fine on ENTRY_DELETE , but sometimes (not always) when a WatchEvent of ENTRY_CREATE occurs, the file has not yet been written to the disk. I've confirmed this by creating a new File() of the directory the watch service is registered to along with the path of the file and checking the exists() method, so it seems that the OS is triggering the create event

How to replace File.listFiles(FileFilter filter) with nio in Java 7?

♀尐吖头ヾ 提交于 2019-11-27 22:07:37
问题 I have some file I/0 traversal code written in Java 6, trying to move it the New I/O in Java 7 but I cannot find any replacement for this kind of stuff. File[] files = dir.listFiles(AudioFileFilter.getInstance()); Namely, no way to filter paths only files, and it returns list of files so I would then have to convert each file to path (file.toPath) if I wanted to limit the use of File in methods it calls, which seems rather laborious. I did look at FileVisitor but this does not seem to allow

Are resources closed before or after the finally?

浪子不回头ぞ 提交于 2019-11-27 21:06:39
问题 In Java 7's try-with-resources, I don't know which order the finally block and the auto-closing happens. What's the order? BaseResource b = new BaseResource(); // not auto-closeable; must be stop'ed try(AdvancedResource a = new AdvancedResource(b)) { } finally { b.stop(); // will this happen before or after a.close()? } 回答1: The resource gets closed before catch or finally blocks. See this tutorial. A try-with-resources statement can have catch and finally blocks just like an ordinary try

Strange text wrapping with styled text in JTextPane with Java 7

久未见 提交于 2019-11-27 20:42:02
I have two different editors using JTextPane with strange bugs in Java 7 that did not occur with the previous JVM versions. It happens with long lines containing styled text or components. Here is an example demonstrating this bug. In this example, the default style is applied for all the text each time a character is inserted. I tested it with the JDK 1.7.0_04. import java.awt.BorderLayout; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; public class BugWrapJava7 extends JFrame { JTextPane jtp; StyledDocument doc; public BugWrapJava7() { setDefaultCloseOperation