JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"Date" != "Data" - check your method signatures vs class name

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

} on line 39 matches the { on line 4 and closes the definition of the class. Then there are more methods - but you can't have a method outside a class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ya working...small size file ok...but how can send larger movie file 700mb
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

That's exactly what I expected. See my previous post for the solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I see you are reading the whole file into a buffer array before writing it. (Your use of a int for the file length limits you to 2GB anyway). It's more normal to have a sensible sized buffer and use copy blocks from the file to the output stream until the file is consumed, eg

byte[] data = new byte[4096]; // 4k buffer, could be much larger
int count;
while ((count = file.read(data)) != -1) {
	outbound.write(data, 0, count);
}

Plus its a bad idea to hide exceptions - better to put your code in a try block, catch any/every exception, and call its printStackTrace() method. That way you can be sure of seeing all the details for any exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The basic mechanism is the same for any size file. Is the data arriving too fast for the client? In that case use the same socket connection to send ready/not ready messages from the client to the server to keep things synchronised.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Adding to that, it might also be worthwhile using System.getProperty("file.separator") to ensure compatibility on as many systems as possible.

Very good advice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You said you were writing the strings to a file, and that's the file name we are talking about. It's never a good idea to hard-code a file name because it may or may not be appropriate for whatever machine the app is finally run on. So let's suppose the class is called TranslationsStore (a place where translations are stored). In outline it could look like this:

public class TranslationsStore {
   public TranslationsStore (String fileName) } // file where info is written
     ...
   }
   public void writeTranslation(String word1, String word2, String comment) {
     // write this info to the file
   }
   // method(s) for reading the info back from the file
}

So then in your GUI you could have code like:

// initialisation...
   TranslationsStore store = new TranslationsStore("data.txt");

// when the user clicks the OK button...
   store.writeTranslation(word1TextField.getText(), //etc

Finally, a simple file name like "data.txt" can be a big problem because the directory is not specified, and will depend on exactly how the java program is started. Java has a method that gives you the user's home directory, so that is a good place to put any files in the absence of a better idea. You use it like this:

String defaultStoreFileName = System.getProperty("user.home") + "/data.txt"
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sounds reasonable so far. Maybe you would want to pass the file name to a constructor for this class so that it's not hard coded? If you are writing this info to a file then presumably you will read it back at some point? If so all the code associated with writing and reading the file should be in the same class so that there's only one class to loom at for anything related to the file record formats etc.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The idea would be to subclass FilterInputStream and implement your own read method. That should read from the underlying stream (super.read), checking it for "</WEATHERDATA>". If it doesn't see that it just passes the data on to the caller, but if it does see it it passes just to the end of that string, then pass an end-of file (return -1) on the next call. That should terminate the parser normally, so then you can loop starting another parser, which will continue to read the input via the FilterInputStream subclass, starting where the previous parser finished. When your subclass reaches the real end of file it can terminate the whole process.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know what you mean by "works" if you can't test it, but anyway...
The normal way to use main in a single class situation like yours goes like this:

public class XXX {
   XXX() { // constructor(s)
   ...
   // lots of method definitions
   ...
   public static void main(String[] args) {
      XXX x = new XXX();
      // call lots of methods on x with test data
      // print lots of results from x
   }
}

basically your lines 15-28 need to be in the main method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I assume you have some way of knowing where one file and and the next begins?
If so, maybe you can wrap your input stream in a FilterInputStream that recognises the end of file and returns -1 from its read method(s) before consuming the EOF marker (whatever that may be). Your parsers can then use the filtered stream and will only see one file each time they are called.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Would you guys be able to provide me an example on how this is implemented? or even point me in the right direction?

Somewhere in your class, but outside any method, declare an int variable with the static keyword - this means there is only one value for this variable which is shared between all the instances of the class.
In your turn() method just add 1 to the variable, so that will count how many times it's been called.
I can't say any more without just giving you the complete answer (cheating). This isn't hard stuff, just try and see how it goes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, you got very close, but

("babybox2.height=",+babybox2.height) // two parameters

isn't the same as

("babybox2.height=" +babybox2.height) // one parameter
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

initialize a counter variable with 0 in the method from which turn() is been invoked and increment this variable from method turn().

This will work in some cases, but not if:
turn() is called from multiple methods, or
there are multiple instances of the class and the methods are not static.

Making the counter static outside any method avoids both problems.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The println method takes just ONE parameter, a String expression. You are trying to pass a String and and int as two parameters (separated by a ,) so you get an error saying it can't find a println method that takes a String and an int as parameters.
You can concatenate stuff together to make a single String by using the + operator, eg
String eg = "This is the year " + 2011;
(When you + a String and a number it converts the number to String and concatenates it.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just create a static int variable outside the method, and increment inside the method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do provide evidence of having done some work yourself if posting questions from school or work assignments

Source: DaniWeb rules - which you should know by now.
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Compiler & runtime - download the official Sun/Oracle JDK (Java development kit)
http://www.oracle.com/technetwork/java/javase/downloads/index.html

Have you read the thread for beginners at the top of the Java page?
http://www.daniweb.com/software-development/java/threads/99132

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you are complete beginner then forget about IDEs for now. You will learn more by working with an editor & compiler. IDEs will generate code and fix problems for you, but if you don't fully understand what they are doing and why, you will get into trouble. When, eventually, you are ready for an IDE there are only 2 that are widely used in commercial environments, NetBeans and Eclipse. They are both equally good, but the Java tutorials use NetBeans, and if you plan to work for IBM you will be using Eclipse.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Could be a firewall blocking the port for you?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, glad to help. Mark this "solved" now?
I'm going to dinner now. Bye.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I use Eclipse and don't know DrJava - presumably there's some kind of project setup where you identify the main class?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The error message says "inner class" - that means a class that's declared inside another class. I don't think you intended that. That happens because you have the { and } matched up wrong. Your class Customer looks like its missing a closing }, so everything after that is still inside the Customer class rather than being at the same level as it.
To avoid this problem indent your code properly - then you can see how your {} are matched up.

ps: Hi @115harman. Please feel free to contribute here, but don't forget that we have to help maroom learn to fix his own problems, and not just tell him the answer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No way. This is your program. I'll advise you, but you have to do the work.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Your variables are all instance variables, but main is (must be) a static method, so it doesn't have an instance to hold the values of those variables (Google that if it's not clear).
A good solution is (1) to create a new instance of Lib and (2) take all that code out of main and put it in an ordinary method called, eg, runUserInterface().
So now you structure for Lib looks like this:

class Lib...
   public static void main...
      Lib myLibrary = new Lib();
      myLibrary.runUserInterface();
   }

   void runUserInterface() {
      // all the code that's currently in main
   }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You haven't defined a variable called cid, so that's why it can't be found. Fix that first.
You'll have fewer errors like this if you use good descriptive names for everything, and have a consitent sty;e for capitalisation etc. A parameter list like
(int id2,int bid2)
tells you nothing - but maybe one of these is a customer ID???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You declare

ArrayList<Customer> cl=new ArrayList<Customer>();
ArrayList<Book> bl=new ArrayList<Book>();

inside the main method, so they are local to that method. If you want to access them from all the methods of the class they need to be declared outside any one method - like the variables in your Customer and Book classes.
ps Please write your posts in normal English, especially for the benefit of the majority of DaniWeb users for whom English is a foreign language.
pps: having variables called c1 and cl, b1 and bl is probably the most ingenious stupid idea I have seen in a long time!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Src.zip has a zillion files, not just java source either. If you want the javadoc for the API classes you can download it from Oracle's Java site.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great!. Mark this "solved" so no-one else worries about it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"M...n", avstand, vektTre

the two commas separate three parameters.

You can use the + operator to concatenate strings, and, even better, if you use it with a string and an int it will convert the int to a string automatically. So you can use something like
"Med %d meter mellom søylene bør gulvet bygges i tre og kan bære %d kg.%n" + avstand + " " + vektTre
to put all that together into a single String that you can print.
(I put an extra blank between the two ints so you can see where one ends and the other starts)

OR

Looking at the first string, although it means nothing to me, I'm suspicious about the % signs. Did you maybe mean printf, not print (in which case your 3 params would be perfectly OK)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 25 you call print and pass three parameters. There is no print method in the PrintStream class that takes 3 parameters. You can concatenate those 3 params together into one String parameter, and that will print OK.

ps: your method also promises a return type of int, but returns nothing - that's wrong too.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

all the matrices are coming empty

They are supposed to be loaded from a list created in textselector, right?
Put lots of print statements between lines 55 and 68 to confirm that it is finding the expected files, and finding the expected words within those files.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would help if you described EXACTLY what your problem is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First: the getName method is incorrectly defined as static. That's wrong - it doesn't apply to the whole class, but to each individual instance. Ditto the variables - they must not be static - each instance of Staff has its own name and ID.

for( int i = 0; i < array.length; i++) {
    System.out.println(array[i].getName());
}

Each element of the array is an instance of Staff, so you can call Staff's methods directly on the array elements.
You don't need to convert to an array - the for-each loop wprks well with your arraylist

for (Staff person : staff) {
   system.out.println(person.getName));
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, setBounds is useless when you are using a layout manager. You can use setPreferredSize, setMinimumSize, setMaximumSize and, depending on your layout manager and how all the components are defined, the layout manager will do its best to comply

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can simplify this to two cases as follows:

NB: keep track of how much space is remaining on the current line at all time
split input into array of words
print the first word
for every remaining word:
  if it fits print " " + the word
  else print "\n" + the word

where "it fits" is a function of the length of the word vs the space remaining
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could do stuff based on the file system - eg a utility to calculate the total sizes of all the directories in a tree and sort them by size or somesuch. Java 7 has a new IO package called NIO that gives you all you need in a cross-platform implementation.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That seems like strange advice. Java was designed to be multi-platform, which is great, but the downside is that it doesn't tie strongly into the system of any one environment. You'll find that all kinds of system calls that you would use in C* are not available in Java unless they are portable across Windows, Mac and Linux.
ps: I notice you have posted a few questions recently - nothing wrong with that, but when you have got your answers please mark them "solved" to save wasted effort from helpful DaniWeb members.

ps: Just to clarify - Java has features like JNI to allow you call DLLs etc with C-style interfaces,, so anything is possible, but this takes you outside normal Java programming and gets really tacky as you start to mix Java concepts with C concepts.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To control the loop like that you just need an ordinary local variable within the method (which cannot, by definition, be static). If you need a single value that is shared between all instances of the class and all methods of the class then declare it static, but outside any method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry purijatin but that's not right, although it is a common mistake.
All calls in Java are calls by value. There is no such thing as a call by reference in Java.

@hackit: I have no idea what kind of problem you have in mind, but all calls in Java are calls by value. There is no equivalent to C's call by reference. People sometimes get confused about this because some values in Java are primitives (int, boolean etc) and others are references (all objects, arrays etc). In both cases the call is by value (ie a copy).
So, to explain purijatin's example more fully:
void foo()

{
     Object a = new Object();
     foo2(a);
}
void foo2(Object b)
{
      //So here, be definition b will point to the same Object as to what a did.
}

a is a reference variable that can hold a reference to any Object. It's initial value is null. new Object() creates an Object and returns a reference to it. That reference is then assigned to a. When foo2(a); is executed a new reference variable is created for the parameter (referred to as b in the method), and the value of a is copied into b. The parameter b is not, and cannot be, a reference to the argument a; it is a copy of its value.

To quote the Java Language Reference section 8.4.1 Formal Parameters

When the method or constructor is invoked (§15.12), the values of the …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

(Norm: am I going bonkers here? Why no NPE's?)

TVShow[] myShowArray = new TVShow[TV_MAX];
..
for(d = 0; d < TV_MAX; ++d)
..
  myShowArray[d].setShowName(tvInput);

This shouldn't work. Have you been ignoring null pointer error messages?
Line 1 creates an array of TVShow pointers, initially all null
Line 3 tries to call a method on an array element BUT the array still just contains null pointers. This should throw an Exception.
You need to add a new TVShow to each array elements before using it, as in

TVShow[] myShowArray = new TVShow[TV_MAX];
...
for(d = 0; d < TV_MAX; ++d)
   tvInput = JOptionPane.showInputDialog(null, "Please enter a television show: ");
   myShowArray[d] = new TVShow(...);  
   myShowArray[d].setShowName(tvInput);
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where did you get this algorithm?

I told you to re-read the previous posts. I already answered that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, just for fun - I haven't checked this for typos, but...
This has the algorithm as previously defined - starts at the top end and works down
swaps with elements lower than the current one.
I also pass in the array as a parameter to make this generally useful, rather than being tied to one app. Finally it's static because it doesn't depend on any particular instance (because the array is a parameter)

public static void Shuffle(float[] data) {

		Random rand = new Random();

		for (int i = data.length; i >= 1; i--) {
			int r= rand.nextInt(i+1);
			double temp = amounts[i];
			amounts[i] = amounts[r];
			amounts[r] = temp;
		}
	}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's not exactly the algorithm that I discussed before, but my guess is that it will work OK anyway. On the other hand, my opinion is not important; either it gives the right result or it doesn't. Certainly it's clean code without any obvious flaws. So run some tests. Shuffle your array a few times and print them all out and see if it looks randomised enough for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Getting closer and closer... although I have no idea why you changed the for loop to go in the wrong direction when you had that right the first time.
line 5 - the upper bound for the random number isn't what I said in the pseudocode

Just take a minute to put the pseudocode and your code side by side and compare every detail. Computer programming requires that every tiny detail is right.

ps I'm not saying that your code won't work. Your own testing will tell you that. It looks like a less efficient version of the algorithm I showed you, and looks like it will work, but I don't have time now to validate that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Getting close... you need the version of nextInt that lets you specify an upper bound for the random number. Maybe that's what you thought the 26 on line 3 does? - sorry it doesn't do that.
and
amounts = amounts[r];
doesn't exactly swap the two values, although it is part of it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

what does get random int r = 0? how do I do that?

that was "r = 0 to i" - a random int >=0 and <= i

Have a look the java.util.Random class and its nextInt(int n) method. (clue - it does exactly what you need).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The reference to fseek leads me to suspect a scenario where objects are written as fixed-length records, so it would be possible to use the java.io.RandomAccessFile seek(pos) method to seek directly to (record number)*(record length). Although I wouldn't recommend that kind of low-level approach unless the file size is humongous.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Excellent! Please mark this thread "solved"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yeah! Come on chiiqui - you can do this. Re-read the advice you've been given and use stevanity's pencil & paper route to work through anything that's not clear.
Everyone struggles at first, but it gets easier...