jorge Garcia

Greenhorn
+ Follow
since Jan 09, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by jorge Garcia

Hi,

I started building an application using 'Java Desktop Application' skeleton. I built a simple test class to try it but it crashes each time I run the main app class and the problem seems to be in the IDE generated GUI class.

The compiler is telling me the null pointer exception is being thrown on this line of code which sits in the 'View' class:

int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");

Test code show the method resourceMap.getInteger() is returning null.

This code is generated by the IDE. I've looked and can't find much documentation on the ResourceMap class or FrameView which the class the IDE is using to produce the GUI class by extending it. I loaded up a sample NetBeans Desktop App and it works fine! In comparing the code I can't see a difference. I've checked properties, and tested a few other other ResourceMap methods which return something but the 'getInteger()' method just won't return anything even though I checked the resource file and the value is 5000.

I'm going to write the GUI class myself at this point but I'm really curious as to why this template won't work.

Any help getting pointed in the right direction would be very appreciated.

Thanks.
Jorge
Figured it out. With netbeans, you have to right click the project get to properties and add the library.
14 years ago
Ok, I got it to work by compiling & running the file from the command line. What's weird is in NetBeans, and JCreator, I still get the ' package doesn't exist' error at compile time. I looked around around for a solution to this but don't see anything. I have no idea why this would happen.
14 years ago
Lol,I take that back. It works in Netbeans but not in a test class written in a in textpad. Weird. Compiler can't find the class. I think it is working in Netbeans because I added the folder in maybe. Still can't figure this out.
14 years ago
Ok. The answer just tripped in my brain. It's the source file, it has to be in a directory with the hierarchy that matches the package name. It's working now.
14 years ago
It's sitting outside the class.
14 years ago
This should be basic but I can't get it the compiler to recognize a package I created.

The file is located at c:\program files\java\com\AJF\ReadAFile.class

At top of the class, 'ReadAFile', I put this - package com.AJF;

In the class I'm building, here is the import statement - import com.AJF.*;

Environment Class Path is - ;C:\Program Files\Java\jre1.6.0_03\lib;C:\Program Files\Java\com

Error Using NetBeans says -

Compiling 1 source file to C:\JavaProjects\parse\build\classes
C:\JavaProjects\parse\src\parse\Main.java:4: package com.AJF does not exist
import com.AJF.*;

Any ideas why the compiler can't see the package?

Thanks again for the help.
14 years ago
Ok. got it to work. Whew, took awhile though.
14 years ago
Campbell, Man, I'm not getting this.

I read this in Java HeadFirst pg 378:

" You can instantiate an inner instance from code running outside the outer class, but you have to use a special syntax. Chance are you'll go through your entire Java Life and never need to make an inner class from outside, but just in case you're interested....

class Foo {
public static void main (String[] args) {
MyOuter outer Obj = new MyOuter();
MyOuter.MyInner inner Obj = outerObj.new MyInner();
}
}

Isn't this saying you can instantiate an outside class inside a class so that the outside class is now just like an inner class?

Thanks again for your help.
14 years ago
I think I'm missing something fundamental here and in reading my first post I see it was kind of sloppy -sorry about that. Let see if I can ask what is confusing me a bit clearer. Thanks again for the help.


'Outer.java' sits in its own file seperate from 'Inner.java' class.

I'd like to create an instance of "Inner.java" in "Outer.java" so that it is just like a nested class inside of "Outer.Java" even though it is sitting in a separate file.

//compiler error is: cannot find symbol. class: Inner.

public class Outer {


public static void main (String[] args) {
Outer outer = new Outer();
Outer.Inner inner = outer.new Inner();
}

}

//Sit in a seperate file from Outer.java.
//Compiled before trying to compile Outer.java

public class Inner {

public void go () {
System.out.println("Inner Go");

}
}
14 years ago
Ranchers-

I'm working on program using NetBeans for the first time and I'm trying to instantiate the GUI as an inner class of the Main class where the gui code is sitting in a seperate file.

The compiler gives this error - " symbol not found....class:Gui. I wrote up a couple of small test classes to see if I could get it to work and got the same error. Reading the tutorial it seems it's right but I must be missing something. Any help would be great. Thanks.

Here's the code -

public class Outer {

int a = 100;

public static void main (String[] args) {
Outer outer = new Outer();
outer.outerMeth();

Outer.Inner inner = outer.new Inner();
}

public void useInner() {

inner.go();

}

public void outerMeth() {
System.out.println("Outer meth " + a);
}


}

public class Inner {

public void go () {
System.out.println("Inner Go");

}

public void useOuterInstance variable() {
System.out.println("a= "+a);
}
}
14 years ago
I just got through HeadFirst Java and found it very good. I am very new to programming and Java to give you some context but I think after going through the whole book, I'm off to a good start.
14 years ago
Thanks, Bill. I got it now, the object is a class.
14 years ago
I built a class to play a sound wav file and I had some trouble getting it to work from a jar file.

I found this code online and it solved my problem but I just don't get what it's doing.

This is the: in= this.getClass().getResourceAsStream("/audio/Bell.wav");

I don't see what 'this.getClass() is doing exactly? 'in' is an InputStream object so is 'this.getClass()' getting an instance of the class vs. getting an object?

Here is the full class code:

import javax.sound.sampled.*;
import java.io.*;
import java.net.*;




public class SoundTest {

//variable declaration

AudioInputStream stream;
AudioFormat format;
Clip clip;
DataLine.Info info;
InputStream in;


public static void main(String[] args) {

SoundTest soundtest = new SoundTest();
soundtest.go();

}

public void go() {

try{
in= this.getClass().getResourceAsStream("/audio/Bell.wav");
}catch(Exception e) {}

try {
stream = AudioSystem.getAudioInputStream(in);
System.out.println("stream");
} catch (Exception e) {}


format = stream.getFormat();
System.out.println("format");
info = new DataLine.Info(Clip.class,format);

try{
clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
System.out.println("Start is next");
System.out.println(Thread.currentThread());
clip.start();
System.out.println("Line after Start");
System.out.println(Thread.currentThread());
Thread.sleep(10000);
System.out.println(Thread.currentThread());
System.out.println("Line after Thread-Sleep");
} catch (Exception a) {}

}//close go

}//close class
14 years ago
Thanks for the response and the suggested tutorials. I'll check them out.
14 years ago