riahc3 50 Â Team Colleague

No, having it in one place would be fine. Let's suppose that you have the `Global' class in the library project (called for e.g. jlib). To then use it in your other project (called jAwesome), you'd:
* Import the Global class in any class of the jAwesome project
* Make sure your dependencies are set right. If you are using an IDE (e.g. Eclipse), you can make a project depend on another project
* If you are compiling from command line, make sure you use the -cp switch of `javac` command to specify the jar file of the library project.

Yeah, messing around with the code earlier I thought if I used those public variables in the library, I could use them as globals all around the program.

Thanks for all the help.

riahc3 50 Â Team Colleague

The main function was a mistake and showing a string is simply a example. Please understand that :)

Yes you must keep that package structure in both and no the Global.var is only when referencing to the variable in the library and yes it should only be done in the main... use get and set methods to return variables etc from the library. a library should also not use other classes global variables. instead they should be sent by the main class as arguments to a method in the library, its a much safer option

From what you have posted and in my situation, then I think I would only need it in the main project: One package with one class with variables. Then with the libary I can access those variables.

If there is a misunderstand, Ill post more code samples to see if I can express correctly the idea.

riahc3 50 Â Team Colleague

if everything's imported, I don't see the problem.
do you have trouble with it?

What I ment was that in each project (both the lib and the main program) do I have to have that com.stuct package and that Global class with var?

I believe that I should only have it in the main program (project) and not in the library project at all.

riahc3 50 Â Team Colleague

I get stuck when install the ADT Plugin for Eclipse. I download manually the zip with the plugin, add the site, add it from archive and when it tries to install:


Software being installed: MyEclipse for Spring 9 (Profile) 2.0.0.0000000004 (com.poweredbypulse.profile-2304017-rmb-2862750 2.0.0.0000000004)
Only one of the following can be installed at once:
Eclipse UI 3.6.1.M20100826-1330 (org.eclipse.ui 3.6.1.M20100826-1330)
Eclipse UI 3.6.2.M20110203-1100 (org.eclipse.ui 3.6.2.M20110203-1100)
Eclipse UI 3.6.0.I20100603-1100 (org.eclipse.ui 3.6.0.I20100603-1100)
Cannot satisfy dependency:
From: Android Development Tools 16.0.1.v201112150204-238534 (com.android.ide.eclipse.adt.feature.group 16.0.1.v201112150204-238534)
To: org.eclipse.ui 3.6.2
Cannot satisfy dependency:
From: MyEclipse for Spring 9 (Profile) 2.0.0.0000000004 (com.poweredbypulse.profile-2304017-rmb-2862750 2.0.0.0000000004)
To: com.android.ide.eclipse.adt.feature.group 0.0.0
Cannot satisfy dependency:
From: MyEclipse for Spring 9 (Profile) 2.0.0.0000000004 (com.poweredbypulse.profile-2304017-rmb-2862750 2.0.0.0000000004)
To: org.eclipse.rcp.feature.group [3.6.1.r361_v20100827-9OArFLdFjY-ThSQXmKvKz0_T]
Cannot satisfy dependency:
From: Eclipse RCP 3.6.1.r361_v20100827-9OArFLdFjY-ThSQXmKvKz0_T (org.eclipse.rcp.feature.group 3.6.1.r361_v20100827-9OArFLdFjY-ThSQXmKvKz0_T)
To: org.eclipse.ui [3.6.1.M20100826-1330]

riahc3 50 Â Team Colleague

Hello

The instructions for installing the Android SDK on Eclipse are different than on MyEclipse (following Google). Any step by step?

Thank you

riahc3 50 Â Team Colleague

what do you need two main methods for?
I don't know what your vision about a "library" is, but AFAIK, a class library has no use for a main method.

It was a example out of my head quickly......
Here is what I ment:

//This is the library
//This is a different project than the other
//Inside com.something:
//Things.java 
package com.something; 
public class Things
{   
   public void printastring()
 	{             //HERE IS MY MAIN QUESTION. CAN I DO THIS
                             System.out.println(Global.var);        
  } 
}
riahc3 50 Â Team Colleague

Hey

Lets see if I can explain myself correctly......

I have 2 projects, one a program and another a library.

First project is basically this, more or less (obviously it is more complicated)

//This is the main project

//Inside com.stuct:
//Global.java
package com.stuct;



public class Global
{
    public static int var=4;
}


//Main program
//Inside com.program:
//main.java

package com.program;

public class main 
{
       public static void main(String[] args) 
 	{
          //In order to access that I currently use something like:
           System.out.println(Global.var);

         }

}

Thats currently my main program. Now here is the library:

//This is the library
//This is a different project than the other
//Inside com.something:
//Things.java

package com.something;

public class Things
{
   public static void main(String[] args) 
	{
             //HERE IS MY MAIN QUESTION. CAN I DO THIS:
             System.out.println(Global.var); 
         }

}

In the section "CAN I DO THIS",is where lies my problem. Could I add that library to my main project in its build path and would the instruction I try to use in my library work? Or do I have to create the same structure with Global in my library (which to me doesnt make sense as I would be using 2 different variables even if named the same).

Thanks!

riahc3 50 Â Team Colleague

Perfect.

Worked perfectly. Thanks. I imagine this is what I need.

riahc3 50 Â Team Colleague

Hey

I want to create a JAR library but not sure how to in MyEclipse. Im currently doing it manually using jar command but I cant seem to get it correctly

The library code is:

public class LibAdd
{
	public static int addtwonumbers (int a,int b)
	{
		return a+b;
	}
	
}

From this, I generate the .JAR (using what command in case Im doing it wrong). Named (for example) LibAdd.jar

Then in another project, in the build path, I include the LibAdd.jar and I want to do this:

public class AnotherClass
{
   public static void main(String[] args) 
     {
		LibAdd l=new LibAdd(); //Can I do this,having no main???
                  int x=l.addtwonumbers(2,3);
                  System.println.out(x);
               //OR
                  System.println.out(l.addtwonumbers(8,5);


	}
}

Thanks for the help :)

riahc3 50 Â Team Colleague

Can you explain and show the error messages?
What is "BinaryOut"?

Part of stdlib library.....Wasnt sure so I did not post that detail.

Figured it out..........I actually had to uncomply it and recomply the library to work. Damn Java....

riahc3 50 Â Team Colleague

Hello

I'm tring to declare a BinaryOut type of object in a Java web project but it doesn't seem to work. I've imported the same libraries I used in a standard Java project so I don't know what's wrong.

Any tips????

riahc3 50 Â Team Colleague

Sloppy is more suited to the design that was chosen for this. Sorry, but above is just absolutely messed up approach either of attempting to fix some bug or beginner not knowing what he is supposed to do. I may sound rude, but seriously till this minute I have no clear idea what you trying to do beside localized element/issue/idea on some supposedly Java web based project that for some reason wants to heavily relay on some JavaScript

OK, then lets start small and once I get one thing working, we can continue and get more complex.

Here is a example of something related. Lets get this working and then we can move on.


Im going to try a AJAX route as from reading this seems to be the most logical form to do it. I have the following:

/index.html
/js/Adding.js

Index contains:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title></title>
	<script type="text/javascript" src="js/Adding.js"></script>
</head>

<body>
<select name="num1">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
</select>
<select name="num2">
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
</select>  
<form method="get" name="adding">
<a href="javascript:add();" id="add">Do</a>
<span id="res"></span>

</form>

</body>
</html>

Adding.js contains

var Adding = Class.create({
x: null,
y: null,

add: function()
{
	var xmlHttp = new XMLHttpRequest();
	var value1 = document.getElementById("num1").value;
    var value2 = document.getElementById("num2").value;
	xmlHttp.open("GET", "index.html", false);
	xmlHttp.send(value1 + value2);
	var result = document.getElementById("res");
	result.innerHTML = xmlHttp.responseText;
}

});

This simple example shows …

riahc3 50 Â Team Colleague

Then you should have this script populate some field of form that you can submit and in doing so you will retrieve these values. Shopping basket is good example, you have price, you know number of items and based on that you will calculate sum for all of them

Kind of sloppy to make (for example) a hidden list box with all the values and submit it using a form element no?

riahc3 50 Â Team Colleague

Lets step back and please explain what is this script doing, in what context it is used and what is the final outcome of whole operation

OK :)

There is a Javascript (with other several Javascript classes) that basically draws points and make a drawing. What I need is each points locations (x, y), the order, and the type of line. All of this is stored and calculated in Javascript.

This is loaded in a HTML page and is displayed. There is a button that says "Submit"

When I hit "Submit" I am suppose to have that information. Once I have that information, there is some other things I have to do inside the servlet.

Basically thats what I have to do :) If you need more information, ask and I will try to give it to you.

Thank you

riahc3 50 Â Team Colleague

Now that sounds as completely different thing, more of the old way to build/render site with complex

This is long abandoned practice, and even then you would just render page through print but not try to execute JavaScript

It seems I have explained it wrong :) My apoligies.

In index.html posted in the first page, there is a link that executes that add function and returns (the numbe) 9. I need to get that 9 and in my servlet (for example) insert it into a database. Thats why I NEED the servlet to get the Javascript value it produces.

Thanks for helping out as it is killing me and I just have no direction at all for this. Im completely puzzled....

riahc3 50 Â Team Colleague

This Javascript was given to me so I didnt have a chance to write it. I was given it and I have been told to get certain information from it.

riahc3 50 Â Team Colleague

If you want it to process in servlet then you shouldn't put it in JavaScript

The information I need is in a Javascript so not putting it there is kind of out of the question...

riahc3 50 Â Team Colleague

Same as this: http://www.daniweb.com/web-development/jsp/threads/400621

Lets use this thread as it has better information.

riahc3 50 Â Team Colleague

Same as this thread: http://www.daniweb.com/web-development/jsp/threads/400823

You can delete this one as it has less information.

riahc3 50 Â Team Colleague

I'm failing to understand a reason for this to be done, so not surprised that no one else replied. Why do you want to get JavaScript variables and returned value?

To process that data in a Java servlet.

riahc3 50 Â Team Colleague

Im surprised there is no reply as I often get quick and good replies on this site. Is there any information that is needed so I can try to see if I can share it and give more insite on what is happening?

riahc3 50 Â Team Colleague

Thanks for moving the thread to the correct section as I need help because I am totally lost.

riahc3 50 Â Team Colleague

Ive been trying to use FireBug to where the code is generated (and store) and I think more or less Ive tracked it down (well, I can get it from more than once place)

Just need to know how using a servlet I can get those values.

riahc3 50 Â Team Colleague

sure ...
there's no reason why you can't use JavaServlets and JavaScript in combination, but, if the Servlet is only supposed to 'load' the html page (when working with Servlets, I think .jsp files might be better, in case you want to pass information on from the servlet to the page), why use the servlet at all?

I miswrote my post gr...

I ment load the scripts with their functions and variables.

riahc3 50 Â Team Colleague

Hey

I have a program in retrieving data from a HTML page with Javascript using Java. Lets say I have the structure of

C:/index.html
C:/js/script.js

index.html contains:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="js/script.js"></script>

</head>
<body>
      <a href="javascript:void(0);" id="add"><img src="images/menunew.png" alt="plus" border="0" /></a>
  
</body>

</html>

The script.js contains:

var Script = Class.create({
a:4,
b:5,

add: function(){
        return (this.a + this.b);
    }

});

How can from a Java servlet access a and b from the script.js file (which contains a class named Script) and also access the function add which returns that value?

(Note that the code I just wrote might be incorrect as I wrote it quickly just to demostrate whats my problem)

This is driving me crazy as I have tried with Map and retrieve it thru request but nothing. There isnt any way I see right now.

Thanks.

riahc3 50 Â Team Colleague

Fixed.

The correct code is:

Ini vini=new Ini();
vini.load(new FileReader("hey.ini"));
String v =vini.get("section").get("x");
System.out.println("The variable contains before saving: " + v);
System.out.println(v.length());
vini.put("section", "x", Integer.parseInt("123"));		
//OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("hey.ini"),"ISO-8859-1");	
vini.store(new FileOutputStream("hey.ini"));
FileOutputStream file_output=new FileOutputStream("hey.ini");		 DataOutputStream data_out=new DataOutputStream(file_output);
vini.store(new OutputStreamWriter(data_out,"ISO-8859-1"));
//vini.store(new OutputStreamWriter("hey.ini","ISO-8859-1"));
vini.load(new FileReader("hey.ini"));
v =vini.get("section").get("x");
System.out.println("The variable contains after saving:: " + v);
System.out.println(v.length());
riahc3 50 Â Team Colleague

Hey

Is it possible to run a Java Servlet that loads a .html page that has a bunch of JS scripts in it? I know how to load a normal .html page (I believe it is correct) but not sure if it works if it has Javascript as well.

Thanks.

riahc3 50 Â Team Colleague

Some text and code example:

Here is the contents of the ini name hey.ini lets say:

helloñhello

[section]
x=test

now code:

Ini vini=new Ini();
vini.load(new FileReader("hey.ini"));
String v =vini.get("section").get("x");
System.out.println("The variable contains before saving: " + v);
System.out.println(v.length());
vini.put("section", "x", Integer.parseInt("123"));		
//OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("hey.ini"),"UTF-8");	
vini.store(new FileOutputStream("hey.ini"));			
FileOutputStream file_output=new FileOutputStream("hey.ini");		 
DataOutputStream data_out=new DataOutputStream(file_output);
vini.store(new OutputStreamWriter(data_out,"UTF-8"));		
//vini.store(new OutputStreamWriter("hey.ini","UTF-8"));			
vini.load(new FileReader("hey.ini"));	
v =vini.get("section").get("x");
System.out.println("The variable contains after saving:: " + v);
System.out.println(v.length());

After running this code, the hey.ini file is:

hello\u007ahello

[section]
x = 123

riahc3 50 Â Team Colleague

Anyone have any ideas or tips? I know the FileWriter doesnt support Unicode (dumb on Sun's part) but is there any alternatives? I cant seem to get DataStreamWriter to work correctly with ini4j

riahc3 50 Â Team Colleague

Android is writed in java, you can download Android SDK + Eclipse to write your programs, and btw... C# and Java have about same syntact, so if you know C# you know Java also, you just need spend few hours to learn librarys ;p

Here is an guide http://www.youtube.com/watch?v=SUOWN...07DBCDCC01493A

Yes Im aware but I just perfer C# over Java. Personal preference nothing more nothing less :)

Also have a look at this: http://www.codeproject.com/KB/androi...d-Android.aspx

MonoDroid exists but it is not free. :) I was looking for a free implementation of the same thing.

riahc3 50 Â Team Colleague

pretty difficult to say where your problem is ...
what do you mean by: seem to be having problems?
what problem? does it give an error message, if so, which one, ...

it's obviously a Java issue, since ini4j is a Java api, but whether the issue is within ini4j or in your code ...

Man I explain things wrong....

Instead of writing in the file

ñ

it puts

\u007a

which I BELIEVE is a ANSI/ASCI code right

Something like

helloñhello

is written as

hello\u007ahello

riahc3 50 Â Team Colleague

Hello

Im trying the ini4j library but I seem to be having problems writing a Unicode file (no problems reading I believe)

Is this a Java issue or ini4j?

Thank you

riahc3 50 Â Team Colleague

Thanks to everyone. With your help and the libary found at http://introcs.cs.princeton.edu/java/stdlib/ I was able to try the ints and doubles.

For ints

u.write(Integer.reverseBytes(theints));

For doubles

u.write(Long.reverseBytes(Double.doubleToRawLongBits(thedoubles)));

Now Unicode files....pfff. Check for a thread in a few minutes :P

Again thanks to all.

riahc3 50 Â Team Colleague

try this to read windows ini files in java:
http://ini4j.sourceforge.net/
Cheers,
Boaz.

Does this process Unicode text (accents and such)?

riahc3 50 Â Team Colleague

The reverseBytes(int) method works great. Thanks.

Now I just need to do the same for doubles. I find Double.toHexString and Double.toString as good alternatives but Im not sure. We'll try them out now and see how it goes.

Thanks to everyone for their help. Will give rep points but before I gotta figure out this double thing.

riahc3 50 Â Team Colleague

It's an int! It's a byte! It's a string! Its an int but backwards!
My head's spinning.

I apoligize for that. Information was not given clearly.

But here's something you may find useful, based on your most recent post:

Java Syntax (Toggle Plain Text)
int abcd = 9999;
int dcba = Integer.reverseBytes(abcd);

So if you use that to reverse the bytes, then write the resulting int to your file, you should get the same output as your C++ program.
NB: 1. I haven't tried this myself. 2. Java 1.5 or later.

ps. Now I have tried it. It converts 9999 = hex 00 00 27 0F to hex 0F 27 00 00

Intresting. I thought it was going to be harder as in load the file into a byte array and reload it but in reverse.

Will try tommorow when Im at work.

Thank you

riahc3 50 Â Team Colleague

We have great news :)

It seems you are all indeed correct (and I was wrong of course) and the orders do matter....

(Lets see how I can explain this) If we have the number 9999 and it is written to a binary file using Java, we open the binary file in a hex editor and it comes out like this:

00 00 27 0F

now the SAME number generated but written using C++ to a binary file the number in a hex editor is shown as:

0F 27 00 00

What we plan to do is once we generate the binary file in Java, we will fill the data in a byte array and simply rewrite it but in reverse. This will give us the same output as C++.

Thanks again for all the help and any tips are still apriciated.

riahc3 50 Â Team Colleague

Let me restate what you want to do.

OK, perfect as a resume :)

You want to write an int to a file as a 32 character String of 0 & 1s

Yes. Several ints in a array. Example if in the array I have 10 then 11, the file would be this

00000000000000000000000000001010@00000000000000000000000000001010

(I put the @ to show the seperated numbers but the @ doesnt exist. They simply would be together)

The output file would be a text file without any line ends. It would be one long record with the value for each int taking 32 bytes/characters.
Is that it?

Yes, it is one long string of just 1s and 0s.

To do that you would Convert the it to a String using the Integer toBinaryString() method and pad the String on the left so that it is 32 characters long. The padding can easily be done with a concatenation of leading 0s and substring taking the rightmost 32 characters

We have a function that does that, written.

Please post the code that shows the class and the method you used.
There is no WriteBytes() method. Java methods all start with lowercase letters.The could be a writeBytes() method

My mistake, yes with writeBytes()

riahc3 50 Â Team Colleague

More information:

They have instructed us to write out a 32 int number in binary format as a string. For example 10 would be written to the file:

00000000000000000000000000001010

written as a string.

We did a simple "if" and "else if" class that adds 0s to the left of 1010 (in case of the decimal number 10) and nothing.

We use the WriteBytes(String s) method to write it to the file but didnt work.

Any more tips?

riahc3 50 Â Team Colleague

That's cool. Never heard of this being done before.
From not knowing anything about JNI/JNA, I would say to check that it's connecting to the C files properly, the problem isn't with the suma function, it just can't find it. So you could create a print statement in the C files on connection to them just to test that they're connectig properly. Possibly try to publicise int suma.
I can't offer much more advise sorry!

Thank you for trying anyways :)

riahc3 50 Â Team Colleague

OK! That's really helpful - this is all starting to make sense now.
So we definitely need to write a sequence of single bytes.
In that case it's definitely a DataOutputStream that you need, and you can use the writeByte(int b) method for single values or the write(byte[] b, int off, int len) to write an array of bytes.
For writeByte(int b) you need to specify b as an int in the range 0-255
For write(byte[] b, int off, int len) just be careful because bytes are expressed as values -128 to +127, not 0 to 255. So you may find it easier to use writeByte in a loop.

Well the writeByte method does look logical: It made a file that is 15 bytes in size(my array from array[0] to array[14])

On Monday Ill test it out with someone and see if thats what he wants.

riahc3 50 Â Team Colleague

you cant write C# applications that run on Android for free, I ment.

riahc3 50 Â Team Colleague

Hey

AFAIK, you have to pay for Mono for Android so you cant write C# applications that run on Android.

Is there any alternative?

riahc3 50 Â Team Colleague

OK, got that.
So, moving onwards, let's stop worrying about the C++ program. You say the data is read by the "PLC". What is that? Does it have any documentation about the data it expects? Do you have source code for the part where it reads the file?
ps: a small point, but it will help to keep things clear: please use the term "bits" when talking about the 8 things in a byte. Use "digits" when talking about the characters 0-9. Thanks.

A PLC is a programmable logic controller used in machines to give the instructions when reading certain values. The PLC (for the machine) would read in this case as a example something like 10010111 (only 1s and 0s, a binary number) in one byte and that means to stop the machine.
I have no documentation about the PLC itself except that.
Ill try to stop using the terms "bits", "bytes", "digits" as It may be confusing in a post.

Again, thanks alot for replying to the thread.

I cannot test any of this until Monday where there is someone to test this out with.

riahc3 50 Â Team Colleague

Hi riahc3
You are still missing a key point here.
"read them normally just like a C++ program" isn't an answer. There is no "normally". There are many many ways for a program to read or write binary numbers, and C++ can read all of them, depending on how the program is written. Unless you can say which of all those formats your C++ program is expecting, you can't write a file for it to read.

If, as you say, each int is written as a single byte, then you can use a DataOutputStream and its write method to write any arbitrary array of bytes. Note, however, that this cannot write the sample data that you posted earlier because that has ints >255. You cannot write arbitrary ints (in java or C++ ) to single bytes because they simply don't fit.

The C++ program (I really think we should use the term C++ program as it has nothing to do with it) doesnt accept anything. It just exports.

Each int is indeed written as a single byte as once again it is represented in 8 digits. I cant test it as it seems everyone here has taken a long vacation.

When I was entering data such as 88888888, these may be other numbers which havent been clarified (very little information is given to us) so Ill have to ask again.

Thanks again for all your help and I think I can give answers and more …

riahc3 50 Â Team Colleague

I'm talking about ONE int value.
You have not said yet how ONE int value is stored on your computer's hard drive.
Given the layout for ONE int, a java program can write millions of them.

What program is going to read the data that the java program writes?
What does it expect the bits/bytes on the hard drive to look like if it is going to read only ONE byte?

I apoligize for simply not understand what you are asking for.

A int in my java program is written in a byte represented by 8 digits with the max being 255 as you well said because of the 8 digit limitation.

The end result that is going to read what my Java writes is a machine that makes shapes, basically.
It expects to see bytes represented as "00000001" (which is one in decimal) and other 8 digit binary numbers which equal 1 byte each.

But once again simply forget the end result: I just want to write and read arrays of ints. The PLC should read them normally just like a C++ program that does the same.

riahc3 50 Â Team Colleague

When I said the "maximum bytes" could be mean the array can be any size (with limitations of memory, etc)

riahc3 50 Â Team Colleague

An eight bit value takes one byte.
The max value you can have in one unsigned byte is 255: 11111111 in binary or FF in hex

This is going nowhere. Is there someone there that understands bits and bytes and binary values when written into a file?

OK, then I would have to write 1 byte of data with those values, correct?

riahc3 50 Â Team Colleague

I was asking how int data is stored on you computer
Take the simple case of an int with the value of 1
Here are different ways it can be stored. I show hex digits, not binary.
A hex 0 is binary 0000
0001
00000001
0100
01000000

Which one is the way it is stored on your computer?

My mistake. Binary numbers. The ints are all stored in 8 digit binary numbers.

1 would be
00000001

3 would be
00000011

and so on.

riahc3 50 Â Team Colleague

How many bytes and in what order do you want the bytes of the int written to the bytes of the file? Java has 4 bytes. Some systems expect ints to be low-order byte to highest and others high-order to lowest (I think java does it this way).

What is the PLC? What does it expect when it reads an int from a file?

The maximum bytes are basically dinamic: Depending on the complex drawing (this is part of the C++ program but again, simply ignore that) it will be more or less. There isnt a "static" limit.

The order is the way I introduce them. If it array[0]=1 and array[1]=999 it should display

1
999

From what Ive seen (again cannot confirm this) It simply reads FIFO style from when I insert the ints into the binary file. Tommorrow at work, lets see if I can get more answers to some of your questions.

Thank you for all the help :)