Swing/AWT/SWT :: JFileChooser Is Throwing NullPointerException

Nov 20, 2014

I have a swing application that is using JFileChooser. When I click the Open menu item from File menu it should show the File dialog box where user can select the file.This application is running in my machine but encounters problem in another machine. File dialog box is not showing and stack trace shows that NullPointerException is thrown by JFileChooser..My machine is a 64 bit Windows 7 while the other machine is Windows 7 32 bit. Both machine are using java 1.6..To verify if its because of the 32-bit, I tried in another Windows 7 32-bit and the same application is working.

I came across this article [URL] .... which identified it as bug but already fix in 1.4.2_04. Though I am using 1.6, just to make sure I also tried the suggested work around.I put System.setProperty("swing.disableFileChooserSpeedFix", "true"); in my code but still not working...I also tried to add java -Dswing.disableFileChooserSpeedFix=true to the batch file that is launching the application and still not working

Code Sample:

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
public class FileChooserTester{
public Boolean loadMDBFile() {
System.setProperty("swing.disableFileChooserSpeedFix", "true");
JFileChooser fc = new JFileChooser();

[code]...

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Stronger Filtering On JFileChooser

Feb 3, 2015

I'm using a JFileChooser. I'm using a FileNameExtensionFilter which is fantastic, and will let me only show files that are of type .db or whatever. However, I don't want to show the user files that have a type of lock.db or *_trace.db for example, and I can't figure out a way to do that.

View Replies View Related

Swing/AWT/SWT :: How To Save File Using JFileChooser

Oct 22, 2014

I insert a link to a file, that you need to download. After I click the download button and that's performed this action. And how me save the file, where i chose?

private void actionAdd() {
JFrame parentFrame = new JFrame();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Specify a file to save");
URL verifiedUrl = verifyUrl(addTextField.getText());

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Trying To Use JFileChooser In Eclipse In Linux

Apr 9, 2014

I'm trying to JFileChooser to open up a window. I'm just trying to learn how to use it for a school assignment this week. The problem is I can't get anything to show up. I can create a new window and print to the console without errors, but JFileChooser doesn't do anything. No errors either.

import java.awt.*;
import javax.swing.*;
public class TestingStuff extends JFrame {
public TestingStuff() {
setTitle("This is a new window!");
setVisible(true);

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Setting File Name For JFileChooser Save Dialog

Aug 9, 2001

I am wondering how to do the following:when a user clicks on a save menu item, a save JFileChooser pops up. I would like to have a default file name set in the FileName box on the chooser, similar to what applications like Microsft word has. Right now, no file name will appear until the user has selected a file.I also need to know how to get the text from this box in the case that the user enters a new file name (the getSelection function is not useful here because the user will not have selected an existing file.)

View Replies View Related

Swing/AWT/SWT :: Change Content Pane Color Of JFilechooser

Mar 25, 2015

I'm dealing with, change the content pane color of jFilechooser. Color has been changed but the problem is when I open the subdirectory leads errors; Note : It also trigger error when I set default directory; like chooser.setCurrentDirectory(file);

The following error is the result:

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(MetalFileChooserUI.java:912)
at javax.swing.SwingUtilities.layoutCompoundLabelImpl(SwingUtilities.java:961)
at javax.swing.SwingUtilities.layoutCompoundLabel(SwingUtilities.java:888)
at javax.swing.plaf.basic.BasicLabelUI.layoutCL(BasicLabelUI.java:94)
at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:239)

[Code]...

Following is the code base

import javax.swing.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;

[Code]...

View Replies View Related

Swing/AWT/SWT :: Select Different Blocks Of Code When File Selected In JFileChooser?

Nov 12, 2014

I have a program where I have to open a file and then run a piece of code to do something with it. However since there are different files I want to run different pieces of code depending on the file. I have a JFileChooser setup and it works but I would like to have a something like an if else depending on the file extension.

View Replies View Related

Swing/AWT/SWT :: Destroy Memory Of JFilechooser When Open For Second Time JFrame

Feb 2, 2014

In one jframe i have insert one jfilechooser but when i open in second time jfilechooser when i want close...don't close.

When I close jframe i want destroy memory of jfilechooser... How to do???

For to close jframe i write:

jframe.dispose();

but don't to do nothing....

View Replies View Related

Swing/AWT/SWT :: Changing Canvas Returns With NullPointerException

Jun 22, 2014

I'm currently having trouble with a Breakout clone that I'm working on when I want to change the scenes of the game. When I start out with the main menu and I hit play, the main menu calls for the StateManager to remove the MainMenu and then to add the GameState to start playing through the levels. But, whenever this is done it just gives a NullPointerException and freezes the game. I know the code for initially starting a State is fine because that is the same way the MainMenu is loaded but there seems to be an issue with changing from one to another...

This is the StateManager class that adds and removes the States/Canvases to and from the JFrame/Main class:
package com.pathtocreating.Breakout_V2.state;

import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.JFrame;
public class StateManager {
private ArrayList<State> states;

[Code] ....

The code that calls the change of state in MainMenuState is called in the update method:

if(inputController.isMouseClicked("LeftClick")) {
if(playHover) {
soundManager.playSound("ButtonClick");
BreakoutMain.sm.changeStates("GameState");

[Code] ....

Here is the full stack trace when clicking the area to change states:

Exception in thread "Thread-2" java.lang.NullPointerException
at sun.java2d.SunGraphics2D.validateColor(Unknown Source)
at sun.java2d.SunGraphics2D.<init>(Unknown Source)
at sun.awt.image.SunVolatileImage.createGraphics(Unknown Source)

[Code] ...

It gives that same value both before and after clicking on the region.

Printing out b after the State is changed to GameState gives the following:

java.awt.Component$BltSubRegionBufferStrategy@66116674

I've tried messing around with the order of which things are added/loading from the StateManager but am just failing to see what I did wrong.

View Replies View Related

Overloaded Methods Throwing Exception

Apr 2, 2014

Overloaded methods CAN declare new or broader checked exceptions. We know that FileNotFoundException is a subclass of IOException and according to the above statement an overloaded method cannot throw a narrower exception. But the below code does not throw a compiler error. How?

Animal.java

Java Code:

package pack1;

import java.io.FileNotFoundException;
import java.io.IOException;
public class Animal{
public void drink(int s) throws IOException
{

}
} mh_sh_highlight_all('java');

[code]....

View Replies View Related

Grasping Concept Of Throwing Own Exceptions

Dec 3, 2014

I am having some difficulties grasping the concept of throwing your own exceptions. How do I get this to repeatedly ask the user to enter a valid value for hours. Also i am having difficulties in the method with using the throw new InvalidHrExcep("That value is invalid"); i cannot get this to work.

public class exceptionProgram {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) throws InvalidHrExcep
{
int day=0;
int month = 0;
int year=0;
int hours=0;
int minutes=0;
int seconds=0;

[code]...

View Replies View Related

Throwing Exception From Catch And Finally Block

Jul 16, 2014

I came across a code where the exceptions can be thrown from catch and finally block too. I never gave a thought on what scenarios that can be required. Some practical examples when/where it can be required to throw the exception from catch and finally blocks.

View Replies View Related

JfileChooser Save Without Dialog Box Popping Up

Jul 6, 2012

I have an application that has a text field I want to use Jfilechooser to save or save As the data.

If the file already exisits i want the end user to be able to hit save without the dialog box popping up asking for a file name folder etc, like it would in MS Word etc..

Is this possible?

View Replies View Related

Enum Class Throwing Illegal Argument Exception?

Mar 4, 2015

I have a enum class which contains some string which i am comparing to a string i get from a user

Java Code:

public enum Compare {
a, b, c, d, e, f
} class SomeClass {
String method(String letter){
Compare word= Compare.valueOf(letter);
}
} mh_sh_highlight_all('java');

Everything works fine but when I added a new word to it like "g" it throws the IllegalArgumentException ?

View Replies View Related

Drag N Drop MP3 File Using JFilechooser To JTable

Jan 21, 2014

including Drag n Drop a mp3 file using jFilechooser to jTable

View Replies View Related

Highlighted Text In Try / Catch Block Is Throwing NullPointer Exception

Sep 15, 2014

If I put the highlighted text in try/catch block it is throwing NullPointerException , if I am using command line arguments then also it is showing the same exception.

public static void main(String []args)
args = null;
args[0] = "test";
System.out.println(args[0]);

View Replies View Related

Overriding In Java - Foo Method Of Class X Is Not Throwing Compile Error

Jul 29, 2013

class SubB{
public void foo(){
System.out.println(" x");
}
}
public class X extends SubB {
public void foo() throws RuntimeException{
super.foo();
if(true) throw new RuntimeException();
System.out.println(" B");
}
public static void main(String [] args){
new X().foo();
}
}

Why the foo method of class X is not throwing a compile error because according to the override rule, if the superclass method has not declared exception, the subclass method can't declare a new exception...

View Replies View Related

Averaging Grades Program Throwing Exception With Negative Numbers

Nov 17, 2014

So I have re-written the code but it is still not running correctly. Any number i type in it throws an exception, also i need the program to add the totals that i type in and then once i type -1 into the prompt button list all the number i typed in and give me the average.

import java.awt.*;
import java.awt.event.*;
import javax.swing .*;
import javax.swing.text.*;
public class Averages extends JFrame
{
//construct components
JLabel sortPrompt = new JLabel("Sort By:");

[Code] .....

View Replies View Related

Can't Make JfileChooser Save Text File Instead Of Opening Files

Nov 13, 2014

i can't make the [JfileChooser] save text file instead of opening files.that [ComboBox] always don't show me the items that i have inserted in eclipse.

View Replies View Related

Custom Jtable Cell Editor Throwing Illegal Component State Exception

Jul 10, 2014

I've come across an interesting problem when using a Jcombobox as a custom cell editor(and renderer) in a jtable. I was hoping to add a keybinding in order to display the dropdown of the combobox instead of having to click on it however, when I make a call to showPopup() I get:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location Which is strange as my jtable is visible and the editor/renderer seems to be working fine.

Here's the cell editor + renderer I'm using:

class MyComboBoxRenderer extends JComboBox implements TableCellRenderer {
public MyComboBoxRenderer(String[] items) {
super(items);
} public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());

[code]....

View Replies View Related

Why Is There A NullPointerException

Apr 21, 2015

I am doing a project for my Java class but I ran into a snag with my code.

package lesson13;
import java.io.FileNotFoundException;
import java.util.LinkedHashSet;
import java.util.Set;

public class CharCountingStudy {
public static void main(String[] args) throws FileNotFoundException{
Set<FileExaminer> examiners = new LinkedHashSet<>();
examiners.add(new FileExaminer("raven.txt"));
examiners.add(new FileExaminer("jabberwocky.txt"));

[Code] ....

I keep getting a NullPointerException at the "examiners.add(new FileExaminer("raven.txt"));", the "calculateCharCountAlpha();", and the "if (charCountAlpha.containsKey(w)){"and I don't know why it is doing that.

View Replies View Related

Getting A NullPointerException Error?

Oct 23, 2014

I am getting a NullPointerException Error and I cannot seem to figure out what is causing it. I am reading in a grades1.dat text file and putting the values into a 2D array. The error is occuring in my addGrade method, but I am not sure what the error is. Here are the values for my grades1.dat that I am running in through Run Arguments in JGRASP.

Student1
5
a Activities 0.05
q Quizzes 0.10
p Projects 0.25
e Exams 0.30
f Final 0.30
a100 a95 a100 a100 a100
q90 q80 q100 q80 q80 r90
p100 p95 p100 p85 p100
e77.5 e88
f92

Here are the errors that I am getting.

Exception in thread "main" java.lang.NullPointerException
at GradeBook.addGrade(GradeBook.java:114)
at GradeBookApp.main(GradeBookApp.java:55)
import java.util.Arrays;
/**
* Stores students name, a char array of category codes, a String array of categories, a double array of category weights, and a two dimensional double array of grades where each row contains all the grades in a particular category.

[code]....

View Replies View Related

How To Avoid NullPointerException

May 3, 2014

I have been playing around with my code, but how to avoid NullPointerexception.. So my program's point is simple, use Jsoup to scrape html of certain webpage, then i search the things i want and print them out. Problem is, when scraped html doesnt contain even 1 thing on my search list, i get NullPointerException... i understand why, Heres part of my code:

Java Code:

//Things i need to search from html
String[] MySearchArray = new String[]{"138","146","474"};
//Search things contained in MySearchArray and print them out
for (String Ml : MySearchArray) {
Element flights = doc.select(String.format("tr:contains(%s)", Ml)).first();
Elements flights2 = flights.select("td");
System.out.println(flights2.get(4).text() + " " + flights2.get(0).text()+ " " + flights2.get(3).text());
} mh_sh_highlight_all('java');

View Replies View Related

NullPointerException Under IF Statement Which Should Be Skipped

Feb 10, 2015

/**
* This method displays all winner names for a given year.
* @param year is the integer parameter asked of the user.
*/
public void displayAllWinnersForYear (int year) {
if (year >= 1993 || year <= 2009) {
String[] winnersForTheYear = nobelPrizeWinners.get(year);
for (int i = 0; i < winnersForTheYear.length; i++) {

[Code] ....

When year is outside the 1993-2009 range, I get a NullPointerException from line 10. Shouldn't it be skipped entirely since the conditions of its parent IF statement (line 7) is not met?

View Replies View Related

Programme Producing NullPointerException

Mar 18, 2014

Am new to programming and am trying to create a system that is similar to a train timetable system.I want the user to be able to enter the stops between two stations ( from a preset list of 5 stations ) and this be saved as an array list, and this array list be saved accordingly within a 2D array so if they were to look in [1][2] there would be an arraylist of stops between station 1 and 2.I used this to initialise the array of arraylists (in a class i created called stops)

ArrayList<String>[][] stopsArray= (ArrayList<String>[][])new ArrayList[5][5];
 
public void stops(){
for (int i = 0; i<5; i++){
for (int j=0; j<5; j++){
stopsArray[i][j]= new ArrayList<String>();
}
}
}

Then I use this code to set the stops

public void setNoStops(int stopsNo){
noOfStops = stopsNo;
}
 
[code]...

The bottom written line of code is mentioned in the null pointer error I recieve. Then.Then in my main programme I declare the new object and use these methods the method options displays the list of five stations with a number reference

System.out.println("Please choose a start station :");
options();
place1 = scanner.nextInt();
System.out.println();
 
System.out.println("Please choose an end station :");
options();
place2 = scanner.nextInt();
System.out.println();

[code]...

mystops is the object I created to store the information.

when compiling I recieve no errors.when I run the program it runs smoothly, asks for the number of stops, allows the user to enter a number, then says enter stop 1, I enter a word and the program crashes giving the error java.lang.NullPointerException

View Replies View Related

NullPointerException With Hashtable Object

Mar 1, 2014

I am having some problems with some code and I need an extra set of eyes. It appears I've missed something. I am getting a NullPointerException with a Hashtable object, which I can clearly see I've created. So I'm not quite sure why it is happening. I am pretty sure it is do with the code I've posted because I've tested everything else involved.Here is the code where it happens,

Java Code:

public void siteGen(String user, String site)
throws ExcGenDatabad, ExcSiteNodomain, Exception {
System.out.println("calling siteGen, user: " + user + ", site: " + site);
String nginx_template;
String fpm_template;

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved