Steve De Costa

Ranch Hand
+ Follow
since Jun 04, 2007
Merit badge: grant badges
For More
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 Steve De Costa

Henry Wong wrote:

Steve De Costa wrote:Why the hell would it be looking somewhere else in the first place.



That is how it supposed to work. If you set a class path, either via environment variable or command line, it will use that for the roots of the classes. And if the current directory isn't in the class path, then it won't search your current directory.

Anyway, care to tell us... (1) if you have a CLASSPATH environ set? (2) how you are compiling (3) you directory structure and (4) where the java and class files are located, and maybe we can see something.

Henry



Hey Henry,

Thanks for taking a stab at this. I am a noob at Java Programming, and I'm just coding something for a project. SO I'll try answering your questions to the best of my knowledge.

(1) I'm not sure if I ever did it. I know I added some external jar's into my project. I'm coding this all in eclipse.
(2) In eclipse I just press "Ctrl+F11" to compile. I've even tried right clicking on the new main file to run it as a java application but I don't think it had any effect.
(3) In the Source package, I created a sub package called StatsCode. So basically, the structure is give below.
Main project -> src package -> StatsCode Package -> NewMain.java
(4) Java is essentially an eclipse folder that I have placed in my c:\Program Files. The Files are stored on an external USB drive (H:). Not sure if giving the exact location will help in this case....


Did I get you the answer you were expecting?
13 years ago

Henry Wong wrote:
This actually confirms that the new compiled code isn't the code that is running -- and that you are running some old class files somewhere.

Anyway, I recommend that you traverse all the directories in your classpath, to see if you can find the old code. You also need to add the location that you are using to compile with in your class path too, as it doesn't seem to be able to find your new stuff, when you renamed it.

Henry



I actually tried that. I try debugging line by line. But a Point comes when its trying to go somewhere and ends up giving a null pointer exception. Why the hell would it be looking somewhere else in the first place.

13 years ago

Bear Bibeault wrote:Nope, the compiler doesn't keep anything in its "memory". Somehow you are either not compiling and running the file that you think you are, or your class file is not being updated with the new code like you think it is.



Well, there's only one main file in the package that I'm compiling. And every time I open the file, I see the same updated code. This is the strangest thing I've ever come across. Any suggestion on how do I fix it?


I tried and copying and pasting the code into a a new file called NewMain.Java within the same Package.

It just brings a window titled "Java Virtual Machine Launcher" with the following error message.

"Could not find the main class. SasCode.NewMain. Program will exit now."

Any suggestions on how do I fix this?
13 years ago
Hello,

I'm having a very weird problem and I wasn't sure what to call it so pardon the vagueness of the Subject title. Also, I apologize if this question was asked here before but my search was unsuccessful (not to mention, I wans't sure what to search for in the first place)

I have a main class in which I have written some code. However, some of the lines were causing problems so I took them out. After saving when I try to recompile, the compiler is still compiling the old file in its memory. i.e. it tries to compile code that is not even in the new main file, now that I have changed it.
Thus, I get a null pointer exception.

The output is shown below and I'm not sure if it would be of any help to put in the code from main file. Currently my Main.java class has less than 70 lines of code. But the error is suggesting something in line 81. Has anyone else faced this before? How do I solve this?





Thanks in advance for your help.





13 years ago
Not sure if this is a beginner question or not but I'm guessing it will be a very basic one for any CS Grad.

I need a data structure that maps every one integer to a String and a Double;

for example

Key ---> [String, Double]
=== === ====
1 -------> [ "AB" , new Double(2)]
2 -------> [ "BC" , new Double(3)]


I thought of HashMap but I don't think it will work. Can anyone please recommend what kind of structure should I be using to store something like this?
13 years ago
I know this question has been answered before but I tried applying those methods and it didn't work for me. I have one Project and I tried importing the Jgrapht Library in it. When I try to compile any of the files in the imported packages, I get the "Editor Does not contain a main type".


I have no idea how to fix it. In the "default.src" package of my project, I tried to include import the package such as




However, it doesn't recognize the files are there? Any suggesstions please?

Thanks in advance for your help.

13 years ago
Thanks for your response David.

Well, I wasn't sure how else I could do it. I'll explain the problem below. I really like the idea of Maps<> and I'm looking into it. Thanks Garrett.

=======================================================================================

I am given a specified set of nodes. Lets call them {A, B, C, D}. I have to make a graph from this. <-- the name of the nodes is all that will be specified to me.

I have a bunch of data that I need to read in. I plan to store it in separate double array variables such as AB[], AC[], BA[], BB[], etc. (these are just example names and not the actual names).
I read in data into it from file "AB.txt", "AC.txt", etc. (assume that files will always exist)

Then when I make a graph, to assign/update cost of each edge, if the edge is AB, then I use the array AB[index].

========================================================================================

Since all I'm given initially is the names of the nodes, I was planning on making a string to make the variable names and then execute the string commands. Does that explain the problem better? I know its a lousy way to do it but I wasn't sure how else I could do this.




13 years ago

Garrett Rowe wrote:The short answer is that it is possible to do what you want using reflection (google java reflection).

The longer answer is this is almost always the wrong way to go about doing anything. Exactly what problem are you trying to solve here? Maybe we can help you find a more idiomatic way.



Hi Garrett,

I'm actually working with graph data structures. The thing is that every head and tail node has a name attached to it.

So suppose I have an edge with nodes named "A" and "B", then there will be a double array variable called "AB" that will contain the weight of the edge at a certain index.

Now for a large graph, I can't do switch or if statements to see what the name will be as there are numerous possible combinations.

However, I can make a string such as below




That is why I'm trying to run the command stored in the string variable executeCommand.

Does that clarify the problem a bit?

Again, thanks a lot for your help.
13 years ago
I'm not sure if this is a basic question or advanced. I apologize if I'm on the wrong forum.

In my code execution, I end up having some syntax that gets stored in a string variable such as





My question is how do I execute the code stored in the variable strName. I've been googling it for a while but didn't really find any fix for this.

Any help/guidance is appreciated.

Thanks in advance.
13 years ago
I've written some code/algorithm and I'm trying to check its run-time.

Any idea if there is an effective way of doing it?

The only thing I could think of was putting my algorithm between the following two lines


System.out.println(System.currentTimeMillis());
//...then the piece of code goes here...
System.out.println(System.currentTimeMillis());
16 years ago
When you say

"String sentence = buffer.readLine();"

Whatever context is in the current line of the file, is stored in the string variable 'sentence' as a string. Thus, you could have numbers or any characters in that line.



In Sandeep's case, if there are 4 lines the doing

buffer.readline() 4 times will read the entire file. NOte that readLine() please the cursor for the buffer to read at the beginning of the next line.

Try checking the Reader Class here
16 years ago
Please search the forums for previous posts.

Such questions have been answered enormous times.
16 years ago
I don't have any experience java com bridges and I'm not sure how to work with them. I am trying to interact with another Java APi and I was told that it is a com server so I will need to use bridge2java.

I downloaded the ibm bridge2java.dll and installed it

When I try to run my program, I get the following error


=====================================================================
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x10001da6, pid=4560, tid=4584
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
# Problematic frame:
# C [bridge2java.dll+0x1da6]
#
# An error report file with more information is saved as hs_err_pid4560.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
=====================================================================

Can anyone please help me with why am I getting this error. am I missing a plug in or something. Would it help if I posted the details from my error log?

Thanks everyone for your help.

Regards
16 years ago
I made a simple menu for console output for java where the user inputs 1, 2, .... or whatever choice from displayed menu and then the desired output is displayed. I wanted to know how can I write the output to a file at the same time as I read and write to console.......

(HOpefully the questions is not too vague....)

Thanks for your help.
16 years ago