|
rjmccall posted:All I mean by generic typing is that if you always use appropriate type parameters on your collections (e.g. ArrayList<String>), and you never work around the type system by letting their types decay (e.g. to a naked ArrayList), it will not be possible to ever accidentally put the wrong kinds of object in the collection (e.g. lists of strings instead of strings). Right, and I went back and added in the types, as I figure it's probably best practice to do so. @SuppressWarnings fixed it all, but that's kind of a cop out. Thanks to yatagan also for possible solutions.
|
# ? Oct 10, 2009 22:01 |
|
|
# ? Apr 23, 2024 08:49 |
|
I'm trying to make a copy method, and here is what I have so farcode:
"Cannot find symbol- Method moveTo(int,int)" I'm trying to make it move the picture to a certain place, and then print it out, and am not sure why moveTo isn't working. Does anyone know?
|
# ? Oct 12, 2009 15:59 |
|
Vandorin posted:I'm trying to make a copy method, and here is what I have so far The line this.moveTo(x,y); Tries to call a method in the class you're currently in. Does the Picture class have a moveTo method?
|
# ? Oct 12, 2009 16:17 |
|
Shavnir posted:The line I thought the picture class had a moveTo method. I remember using it to move little turtles around, but now I don't know.
|
# ? Oct 12, 2009 16:26 |
|
Vandorin posted:I thought the picture class had a moveTo method. I remember using it to move little turtles around, but now I don't know. Is your method in the Picture class?
|
# ? Oct 12, 2009 16:29 |
|
Shavnir posted:Is your method in the Picture class? Yes. I just added it after the last method.
|
# ? Oct 12, 2009 16:31 |
|
Vandorin posted:Yes. I just added it after the last method. Huh. Yea, I'd go double check that you've got a moveTo method taking two ints, because your compiler sure as hell thinks you don't.
|
# ? Oct 12, 2009 16:39 |
|
Shavnir posted:Huh. Yea, I'd go double check that you've got a moveTo method taking two ints, because your compiler sure as hell thinks you don't. Yeah, now that I've looked a little closer, I don't see it anywhere. Also, is it possible to paste a picture, on top of another picture, without it opening a new window? Because I sure as hell can't figure it out.
|
# ? Oct 12, 2009 16:57 |
|
Parantumaton posted:Being interested in dynamic clustering, how does Terracotta scale in practice, do I have to bring the whole cluster down to add more nodes or can I dynamically pour more resources into it, what are the limits/caveats you've hit at with it etc?
|
# ? Oct 12, 2009 17:03 |
|
Vandorin posted:Yeah, now that I've looked a little closer, I don't see it anywhere. Also, is it possible to paste a picture, on top of another picture, without it opening a new window? Because I sure as hell can't figure it out. That's certainly something that is possible with Java. To tell you if it's possible from within the Picture class, though, we'd have to see the code for the whole class.
|
# ? Oct 13, 2009 03:18 |
|
Parantumaton posted:POI is designed to be one of those API:s which build everything in memory and then dump the final result into wherever you direct it to dump so no, any POI API -inluding HSSF - will most likely never allow you to use it for massive spreadsheets etc.
|
# ? Oct 14, 2009 16:31 |
|
I am trying to populate an array with random numbers in parallel. When I build it using Eclipse I get the error: "There is an error in the required project - Threads" Not very helpful! I'm at a loss as to what is wrong, any help would be appreciated. code:
|
# ? Oct 15, 2009 21:04 |
|
I keep getting an array out of bounds error, and I can't figure out why.code:
|
# ? Oct 15, 2009 21:11 |
|
Vandorin posted:I keep getting an array out of bounds error, and I can't figure out why. X is width, Y is height?
|
# ? Oct 15, 2009 21:20 |
|
tef posted:X is width, Y is height? Yes, shouldn't it be?
|
# ? Oct 15, 2009 21:29 |
|
Vandorin posted:Yes, shouldn't it be? I think he was hinting at what was wrong
|
# ? Oct 15, 2009 21:30 |
|
karuna posted:I am trying to populate an array with random numbers in parallel. I got it to compile just fine. The one thing that could be wrong is that both of those classes are in same file. You need separate .java file for each public class. Just move PopulateArray into ShuffleResult and declare it as public static class. I compiled it using javac on my machine without any errors.
|
# ? Oct 15, 2009 21:50 |
|
RussianManiac posted:I got it to compile just fine. The one thing that could be wrong is that both of those classes are in same file. You need separate .java file for each public class. Just move PopulateArray into ShuffleResult and declare it as public static class. I compiled it using javac on my machine without any errors. I had them in separate files within a package, I just created a new package and is compiling fine now. My threads don't seem to be running though, the list[] output is 100 zeros. Shouldn't the run method in PopulateArray be executed for each thread and apply to the list[]? So why isn't the list been populated with random numbers?
|
# ? Oct 15, 2009 22:23 |
|
karuna posted:I had them in separate files within a package, I just created a new package and is compiling fine now. take a look at the java order of precedence
|
# ? Oct 15, 2009 22:31 |
|
osama vin diesel posted:take a look at the java order of precedence Ok I think I'm understanding you, is there an issue with casting the Math.random()? When I change code:
code:
|
# ? Oct 15, 2009 22:54 |
|
karuna posted:Ok I think I'm understanding you, is there an issue with casting the Math.random()?
|
# ? Oct 15, 2009 23:50 |
|
Are you getting compile time error or run-time? Because there are no compile time errors in your code on javac 1.6
|
# ? Oct 16, 2009 07:17 |
|
karuna posted:The output of the whole thread is 2 but it is only meant to apply to the first 50 elements? code:
|
# ? Oct 16, 2009 11:21 |
|
oval office.exe posted:
why? that is fine, it is printing out the same number 50 times because he is passing an int as x and only gets set once per thread
|
# ? Oct 16, 2009 14:56 |
|
I've solved this now, can see now why it was only generating 0's or printing the same number when directly defined. I am using the random class now and works fine calling get nextInt() within the loop in the run method. Thanks for the help, I'm sure I'll be back
|
# ? Oct 16, 2009 16:04 |
I've never done anything concurrently with threads and such in java. What's a good small project I can do to learn about them?
|
|
# ? Oct 17, 2009 01:56 |
|
In one of my classes they had us make a multi threaded expression solver. It was really neat because it entailed finding all the parts of the expression that could be solved independently, then solving them, and then putting it all back together again.
|
# ? Oct 17, 2009 02:46 |
|
fletcher posted:I've never done anything concurrently with threads and such in java. What's a good small project I can do to learn about them? Make a simple GUI where the user write a file name in a text box and then presses a button, and in the background you load the file and then display it in a text box. Now make it work even if the user changes his mind while you're still loading the file. Very simple, but still a good introduction to threads.
|
# ? Oct 17, 2009 02:52 |
|
osama bin diesel posted:why? that is fine, it is printing out the same number 50 times because he is passing an int as x and only gets set once per thread He's gotten his loops confused. He probably wants either: code:
code:
the onion wizard fucked around with this message at 11:30 on Oct 17, 2009 |
# ? Oct 17, 2009 05:20 |
|
I'm writing a simple http proxy to learn socket programming (it currently only implements GET), but all the output it sends has a null byte (0x00) before each byte of the expected output. I am using DataOutputStream.writeChars(String) to send http headers and DataOutputStream.write(byte[],int offset, int length) to send the body of an http response. Anyone know what's causing this? e: switching from writeChars to writeUTF almost fixes it, except for 2 extraneous bytes at the start of the body that make no sense and aren't in the original string. No clue what's going on with the byte array output, though. dis astranagant fucked around with this message at 19:38 on Oct 19, 2009 |
# ? Oct 19, 2009 19:03 |
|
Short answer: when getting a byte representation of a String for transmission, you want to specify the encoding to use, in this case ASCII or UTF-8. Longer answer: Java Strings are stored in memory as a 2-byte Unicode variant codepoints, and the deal with data stream classes is that they closely mimic the memory storage. So those zeros are what's in memory. e: also, DataOutputStream writes the lengths of Strings so that a DataInputStream could read them back in, so you probably shouldn't use it unless there's a corresponding class reading it back in. Max Facetime fucked around with this message at 19:58 on Oct 19, 2009 |
# ? Oct 19, 2009 19:51 |
|
tkinnun0 posted:Short answer: when getting a byte representation of a String for transmission, you want to specify the encoding to use, in this case ASCII or UTF-8. That doesn't explain the behavior I'm getting just trying to send a byte array down the pipe (they seem to get converted to shorts or something), nor the random 2 bytes (0x248) at the start of the header when I send using writeUTF() (which is supposed to be UTF8). tkinnun0 posted:e: also, DataOutputStream writes the lengths of Strings so that a DataInputStream could read them back in, so you probably shouldn't use it unless there's a corresponding class reading it back in. Ugh, and I was told that DataOutputStream was the only way to send text and binaries over the same socket. JAVA dis astranagant fucked around with this message at 20:09 on Oct 19, 2009 |
# ? Oct 19, 2009 19:57 |
|
dis astranagant posted:Ugh, and I was told that DataOutputStream was the only way to send text and binaries over the same socket. JAVA It's a good way if you're transmitting between Java programs and don't mind using your own protocol. But interfacing with the rest of the world, it's better to use a dedicated library or low-level calls like String.getBytes(String charsetName) and OutputStream.write(byte[] bytes, int off, int len)
|
# ? Oct 19, 2009 20:27 |
|
tkinnun0 posted:String.getBytes(String charsetName) and Worked beautifully. I could even browse the forms with it if I turned up the max object size.
|
# ? Oct 19, 2009 20:50 |
|
It's incredibly unlikely to actually happen, but if you start caring about performance and this section shows up as a hot spot, consider switching to the ByteBuffer and CharsetEncoder APIs; they're pretty clean to work with, and you can avoid a lot of unnecessary buffer allocations and copies.
|
# ? Oct 19, 2009 22:01 |
|
dis astranagant posted:e: switching from writeChars to writeUTF almost fixes it, except for 2 extraneous bytes at the start of the body that make no sense and aren't in the original string. No clue what's going on with the byte array output, though.
|
# ? Oct 20, 2009 17:02 |
|
Fly posted:Could that be a byte-order mark (BOM)? http://unicode.org/faq/utf_bom.html#BOM It's the length of the encoded string in bytes. The actual string encoding isn't exactly UTF-8, but instead a modified version which preserves surrogate pairs and null characters without leaving any embedded nulls in the encoded bytes. That method is more for quick and efficient byte-for-byte precision in the deserialized data than it is for byte-for-byte precision in the serialized form.
|
# ? Oct 21, 2009 00:47 |
|
1337JiveTurkey posted:It's the length of the encoded string in bytes.
|
# ? Oct 21, 2009 17:55 |
|
This isn't exactly elegant or the best solution. I have 1000s of XML files that reference each other. Each xml file has a "story_id" and may contain a "related_story_id". The related_story_id matches the file's name story_[related_story_id].xml Then it reads the related file and adds the primary_uri element value to a String[]. This is all output of Bricolage (an archaic and terrible CMS) via SOAP; unfortunately there's no time to go through and traverse the DB schema, but after spending the past few hours on this, I'm starting to wonder if it would be quicker. in "parseRelatedStory" I'm getting a NullPointerException and no values are being added to String[] relatedLinks and the line after which should output to the log file does not work. Should String[] relatedLinks actually be a HashMap? This nearly same block of code (except for a different subset of elements in the same XML file) works. I'm not sure why it may be failing here. code:
php:<? private String[] relatedLinks; public String[] execute() { Iterator<Element> childs = null; Element child = null; // field is private, but set here by a setter childs = field.getChildren().iterator(); while (childs.hasNext()) { child = (Element) childs.next(); if ("linkbar".equals(kid.getAttributeValue("element_type"))) { parseStoryXml(child); } } return relatedLinks; } private void parseStoryXml(Element elements) { Iterator<Element> containers = elements.getChildren().iterator(); Element container = null; int i = 0; while (containers.hasNext()) { container = (Element) containers.next(); if ("bricolage_link".equals(container.getAttributeValue("element_type"))) { if (!"".equals(container.getAttributeValue("related_story_id"))) { String story_id = "story_" + container.getAttributeValue("related_story_id"); parseRelatedStory(story_id, i); i++; } } else if ("non_cms_link".equals(container.getAttributeValue(element_type))) { parseExternalLink(container, i); i++; } } } private void parseRelatedStory(String story_id, int i) { try { Document doc = null; String fileName = getRelatedUri(story_id); boolean isPrimaryUri = false; SAXBuilder sax = new SAXBuilder(); doc = sax.build(fileName); Element assets = doc.getRootElement(); Element story = null; Element field = null; Iterator<Element> fields = null; Iterator<Element> stories = assets.getChildren().iterator(); while (stories.hasNext()) { story = (Element) stories.next(); fields = story.getChildren().iterator(); while (fields.hasNext()) { field = (Element) fields.next(); if ("primary_uri".equalsIgnoreCase(field.getName())) { if (!"".equals(field.getValue())) { isPrimaryUri = true; log.info("main story: " + storyId); log.info("FileName: " + fileName); log.info("Primary URI: " + i + " : " + field.getValue()); // All of these logs show up when the script is running. // nothiing is added to relatedLinks relatedLinks[i] = field.getValue(); // this does not output to the error.log file! log.info("relatedLinks length: " + relatedLinks.length); } // no need to continue parsing the XML file break; } } if (isPrimaryUri) { // no need to continue parsing the XML file break; } } else { log.error("fileName is NULL"); } } catch (JDOMException e) { // TODO Auto-generated catch block log.error("parseRelatedStory:JDOM: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.error("parseRelatedStory:IOException - Most likely FileNotFound " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { // also tried this with NullPointerException - catch works, no message // e.getMessage doesn't show anything log.error("parseRelatedStory:Exception " + story_id + " " + e.getMessage()); } } ?> Log file output this repeats for each main story_id code:
|
# ? Oct 21, 2009 18:42 |
|
|
# ? Apr 23, 2024 08:49 |
|
geeves posted:Any thoughts? Am I blatantly missing something? I don't see relatedLinks being initialized, so it's probably null. Another thing is that arrays in Java do not expand after creation. Taken together, relatedLinks should be List<String> relatedLinks = new ArrayList<String>();
|
# ? Oct 21, 2009 19:15 |