Search Results

Search found 33640 results on 1346 pages for 'java generics'.

Page 169/1346 | < Previous Page | 165 166 167 168 169 170 171 172 173 174 175 176  | Next Page >

  • Converting a C++ Checksum function to Java

    - by user1897599
    I'm trying to convert this C++ checksum to Java but for the time being I've failed. What am I doing wrong? What is it supposed to do? It is supposed to return a positive checksum for a buffer in OpenGL Here's the C part. DWORD QuickChecksum(DWORD *data, int size){ if(!data) { return 0x0; } DWORD sum; DWORD tmp; sum = *data; for(int i = 1; i < (size/4); i++) { tmp = data[i]; tmp = (DWORD)(sum >> 29) + tmp; tmp = (DWORD)(sum >> 17) + tmp; sum = (DWORD)(sum << 3) ^ tmp; } return sum; } And here is what I have tried in Java. As far As I know DWORD is 32bit so I use int in a long to get a unsigned int which should be done in java with ? I've been looking at this problem so much now that I've grown blind to it. public static long getChecksum(byte[] data, int size) { long sum, tmp; sum = getInt(new byte[]{data[0], data[1], data[2], data[3]},true) & 0xFF; for(int I = 4; I < data.length; I += 4) { tmp = getInt(new byte[]{data[I],data[I+1],data[I+2],data[I+3]},true) & 0xFF; tmp = (sum >>> 29) + tmp; tmp = (sum >>> 17) + tmp; sum = (sum << 3) ^ tmp; } return sum & 0xFF; } private static int getInt(byte[] bytes, boolean big) { ByteBuffer bb = ByteBuffer.wrap(bytes); return bb.getInt(); } Thank you all for your help!

    Read the article

  • File download using Java, Struts 2 and AJAX

    - by amar4kintu
    Hello Friends, I want to give file download using java,struts2 and ajax. On my html page there is a button called "export" clicking on which ajax call will be made which will execute a query and will create .xls file using code and I want to give that file for download to user without storing it on hard drive. Does any one know how to do that using struts2 and ajax in java? Is there any example available? Let me know if you need more details from me... Thanks. amar4kintu

    Read the article

  • java nested for() loop throws ArrayIndexOutOfBoundsException

    - by Mike
    I'm working through a JPanel exercise in a Java book. I'm tasked with creating a 5x4 grid using GridLayout. When I loop through the container to add panels and buttons, the first add() throws the OOB exception. What am I doing wrong? package mineField; import java.awt.*; import javax.swing.*; @SuppressWarnings("serial") public class MineField extends JFrame { private final int WIDTH = 250; private final int HEIGHT = 120; private final int MAX_ROWS = 5; private final int MAX_COLUMNS = 4; public MineField() { super("Minefield"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container mineFieldGrid = getContentPane(); mineFieldGrid.setLayout(new GridLayout(MAX_ROWS, MAX_COLUMNS)); // loop through arrays, add panels, then add buttons to panels. for (int i = 0; i < MAX_ROWS; i++) { JPanel[] rows = new JPanel[i]; mineFieldGrid.add(rows[i], rows[i].getName()); rows[i].setBackground(Color.blue); for (int j = 0; j < MAX_COLUMNS; j++) { JButton[] buttons = new JButton[i]; rows[i].add(buttons[j], buttons[j].getName()); } } mineFieldGrid.setSize(WIDTH, HEIGHT); mineFieldGrid.setVisible(true); } public int setRandomBomb(Container con) { int bombID; bombID = (int) (Math.random() * con.getComponentCount()); return bombID; } /** * @param args */ public static void main(String[] args) { //int randomBomb; //JButton bombLocation; MineField minePanel = new MineField(); //minePanel[randomBomb] = minePanel.setRandomBomb(minePanel); } } I'm sure I'm over-engineering a simple nested for loop. Since I'm new to Java, please be kind. I'm sure I'll return the favor some day.

    Read the article

  • Storing a big xml string in a xml document in java

    - by shyam R
    Hi All, I Have a Java object which I am converting into a xml file. I am getting a big xml file here after converting java object. I am capturing that converted xml file in a string like below String ouputXML = xmlfile; Noe If I pring the ouputXML on the console of IBM RSA in the proper format only it is printing but my requirement is I need to redirect outputXML in to an XML instead of printing in IBm RSA console. I am able to do this but the problem is if I open the craetd XML file the xml structure is not proper , it is showing so many special characters . Please help me !!

    Read the article

  • Converting java language output to Joomla language output

    - by jax
    in java if I run : Locale.getDefault().toString() I get zh_tw I am sending this to a joomla site and setting the language like this: $lang = &JFactory::getLanguage(); $lang->setLanguage( $_GET['lang'] ); $lang->load(); however the site requires the following format zh-TW It appears that if it is not in that exact format the language will not change. Is there a function somewhere in java or php that will convert the format for me? I realise that I could write the method myself like this: public static String convertLanguageToJoomlaFormat(String lang) { String[] parts = lang.split("_"); if(parts.length ==2) return parts[0]+"-"+parts[1].toUpperCase(); return lang; } but am unsure if there are any cases where the format changes for particular languages.

    Read the article

  • Java - Loading dlls by a relative path and hide them inside a jar

    - by supertreta
    Hi guys, I am developing a Java application that should be release as a jar. This program depends on c++ external libraries called by JNI. To load them, I use the method System.load with an absolute path and this works fine. However, I really want to "hide" them inside the jar, so I have created a package to collect them. This forces me to load an relative path - the package path. By this approach, I let the user run the jar in any directory, without being worried about linking the dll's or bored with a previous installation process. This throws the expected exception: Exception in thread "main" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library How can I get this working? Thanks for your help!

    Read the article

  • Installing Java SDK on Linux.

    - by Negai
    Hi everyone, I'm currently trying to install Java SDK on my Debian 'Etch'. Even though the installation process has been described a number of times, but still I haven't found the information to solve the problem. Here is, what I'm getting: m@sanctuary:~/distr/java$ fakeroot make-jpkg jdk-6u20-linux-i586.bin Creating temporary directory: /tmp/make-jpkg.sqQPnaxiwl Loading plugins: blackdown-j2re.sh blackdown-j2sdk.sh common.sh ibm-j2re.sh ibm-j2sdk.sh j2re.sh j2sdk-doc.sh j2sdk.sh j2se.sh sun-j2re.sh sun-j2sdk-doc.sh sun-j2sdk.sh Detected Debian build architecture: i386 Detected Debian GNU type: i486-linux-gnu No matching plugin was found. Removing temporary directory: done Could anybody help me? Thanks in advance.

    Read the article

  • Best way to notify several java applets/applications of a change on a server

    - by Dustin
    I need to know the best (fastest) way to have a server (preferably a php based one, but a jsp/servlet one could be set up as well using google app engine) notify several java applets/applications that a change has occurred to the data. The way i am picturing this to work will be very similar to that of the way i think an online java game (like Runescape) works User 1: Changes data on server. Server: returns success to User 1, notifies connected computers of change. Connected Computer 1: processes change, returns success to server. Connected Computer 2: processes change, returns success to server. Connected Computer 3: processes change, returns success to server. Connected Computer 4: processes change, returns success to server. I am hoping to have this entire process complete in half a second, and not involve polling as there will be long durations of nothing, followed by a sudden moment where 4 events happen in succession.

    Read the article

  • What ever happened to Java and Sun?

    - by leeand00
    What happened to Java and Sun? The community surrounding them had some of my favorite tools and software to develop with. The Java platform anyway, still looked like it had some promise to it: Groovy and Grails. Why does all of this seem to be going the way of the dodo lately? (Yes, I know their stock price is dropping badly.) Is it just the economy? Or did the lack of cohesion (i.e., not settling on a framework) among the community finally lead to its demise?

    Read the article

  • java.lang.ClassNotFoundException error using enum as a key in Map

    - by LCYSoft
    <util:map id="myMap" key-type="com.myClass.Foo.myEnum" value-type="com.myClass.Foo"> <entry> <key> <value type="com.myClass.Foo.myEnum">ONE</value> </key> <ref bean="myObj"/> </entry> </util:map> package com.myClass public class Foo { public enum myEnum {ONE, TWO;} } I am trying to create a map from Spriong 2.5. Map<myEnum, Foo> myMap; I am getting nested exception is java.lang.ClassNotFoundException:com.myClass.Foo.myEnum I definitely have com.myClass.Foo.myEnumin com.myClass.Foo I don't know why I am getting java.lang.ClassNotFoundException Thanks in advance

    Read the article

  • java: communication between threads

    - by TRU7H
    I'm making a little java game in which I would have two threads (well as the FIRST step towards multithreading...), one for the logic and one for the drawing. So my question is: How can I make those two communicating which each other? Requirements: accessing variables and object from a another thread syncing them so they each complete a same number of "loops" in the same time. (the logic calculates and then the another one draws the results and the loop begins again...) So how is this achievable in java? Thanks in advance!

    Read the article

  • Instantiating Java object with a passed in method

    - by superluminary
    It's been a few years since I've been heavily into Java. Coming back to it I'm seeing this pattern all over the place: ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { // do work } }); This looks more like Functional programming to me. It's a nice pattern but how is it possible to pass a method like this? In the old days a class was a class, and once compiled there was little you could do to it. My questions are: Can anyone let me know what this pattern is called? How can I write a class that can be instantiated in this way. Are there any other useful examples of functional patterns that have made their way into Java? What do I need to Google to read more about this? Thanks.

    Read the article

  • convert flv to mp3 with Java

    - by krial
    Hi, I'm pretty new in developing programs in Java. I'm currently writing a program that converts a flv video into mp3. I have already written such a program in Visual Studio.net C#, but the Problem is, that it isn't cross platform compatible... I used the ffmpeg binary to convert the video into mp3, but I can't find ffmpeg binaries for Mac and Linux. (if so, I could start the specific binaries from java, depending on the OS) So I tried to convert the video with Xuggle, but the final mp3 has 0 bytes. My current code is the following: IMediaReader reader = ToolFactory.makeReader("video.flv"); reader.addListener(ToolFactory.makeWriter("music.mp3", reader)); while (reader.readPacket() == null) do {} while(false); Thanks in advance. p.s sorry for my bad english

    Read the article

  • Google App Engine, Java, and HTTP Performance

    - by polyclef
    A friend and I are currently working on a turn-based game with chat with both desktop browser and Android clients, with Google App Engine as the server. We're using the Java API for GAE and using HTTP for communication with the server. We've implemented simple chat functionality, and we're getting undesirable latencies 1-3 seconds from both the browser and Android clients while just posting simple one-word chat messages. My friend thought it would be best to use XMPP instead of HTTP, but we want to use a Google Accounts cookie for authentication from the Android client, and according to the GAE documentation, XMPP clients cannot use a Google Accounts cookie and must use the user's password. Does anyone have any suggestions as to where the latency might be coming from, how to troubleshoot it, and/or what to do about it? Also, is anyone aware of any opensource implementations of chat (or something similar) on GAE done in Java? Can't seem to find any.

    Read the article

  • Get location from where the Java code is executed

    - by drasto
    I have a swing Java application that preserves a lot of data (you can think of a game and its saves for example). Those data are stored in files rather then in database. I would like to keep this files near installation files(.jar file) of my application.Some users(like me) are used to delete default application folder of OS when it comes to large and I don't want them to loose their data this way. Any ideas how to do this easily ? How do I get the folder of the .jar file from program that is executing form that .jar file? Or how do I output files directly into some package? How do I create packages(folders inside jar) dynamically ? Or is there a simple way to distribute Java application in other formats then .jar and then store generated data in installation (sub)folder ? Thanks for reading

    Read the article

< Previous Page | 165 166 167 168 169 170 171 172 173 174 175 176  | Next Page >