Looking for a way to pass back multiple data types from a method. I want to be able to pass back an array that the method fill out, and also the length of that array (I need that because the calling code will pass the byte array to the serial port, and the length must be specified). I looked into Vectors, but each element in the Vector must be an object (can't just be an integer).

Any idea on how to do this? I'm a java noob. In VB it was easy to just create a structure. Not sure what to do in Java


6 Years
Discussion Span
Last Post by rciprogrammer

Ok. Here is what I have tried.

public class dataClass{
	byte[] bytChunk; // = new byte[100];
	int numBytes;

    dataClass() {}

    public static dataClass createByteArray() {
        dataClass dc = null;

        dc.numBytes = 15;
        dc.bytChunk = new byte[dc.numBytes];

        //loop and assign bytes to bytChunk array

        return dc;
    } //createByteArray

When I call this from another class, I don't seem to get anything back (at least I can't seem to access the members/variables from my new class).

Calling code:

dataClass myDC = dataClass.createByteArray();

Status.show("Back from call to dataClass");
Status.show("numBytes: " + Integer.toString(myDC.numBytes) );

I get the first message, but the second does not pop up.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.