OutOfBoundsException with char array
in the catch part how can i delete the last char in the array so it doesnt keep giving me the exception? Thanks for any help.
try
passWord[counter] = e.getKeyChar();
counter++;
System.out.print("*");
catch(ArrayIndexOutOfBoundsException b)
System.out.println("Your passwords is too long, use back space to go back");
//need statement to remove last char in the array
}
i'll try it, thanks. But out of curiosity how would
you delete using backspace?If you had to do it, it'd be quite a bit of work:
1) is the input empty? if so ignore
2) remove last char from input field and erase its view
3) position the cursor at the correct position
but lucky for you, you don't have to do that yourself, the JPasswordField
does it all for you ;-)
kind regards,
Jos
Similar Messages
-
Here is the go folks this is a pice of code which I was helped with by a member of this forum, THANX HEAPS DUDE. What has happened now is the criteria is changed, previously it would search for a string in the vector. But now I have to have searches with wildcards, so it needs to utilize a char array methinks. So it will go through change the parameter to a char array, then go through the getDirector() method to return a director string, then it needs to loop through the char array and check if the letters are the same. then exit on the wild card. Now all this needs to be happening while this contruct down the bottom is looping through all the different elements in the moviesVector :s if anyone could give me a hand it is verry welcome. I must say also that this forum is very well run. 5 stars
public void searchMovies(java.lang.String searchTerm) {
Iterator i = moviesVector.iterator();
while (i.hasNext()) {
Movie thisMovie = (Movie)i.next();
//Now do what you want with thisMovie. for instanse:
if (thisMovie.getDirector().equals(searchTerm))
foundMovies.add(thisMovie);
//assumes foundMovies is some collection that we will
//return later... or if you just want one movie, you can:
//return thisMovie; right here.
}Sorry, I clicked submit, but i didnt enable to wtch it, so i stoped it before it had sent fully. Evidently that didnt work.
-
Convert jstring to char array or int array
Hi all, please help with the following code. I've tested this code with hard coded char array and it works. Now I have to get the char array from parameter "param1" which is passed from Java.
The following code compiled with error message:
error C2223: left of '->GetStringUTFChars' must point to struct/union
JNIEXPORT void JNICALL Java_DongleSet_DongleWrite(JNIEnv *env,jobject obj,jstring param1){
char HaspBuffer[500]=(char)env->GetStringUTFChars(param1,NULL);
int Service=MEMOHASP_WRITEBLOCK;
int SeedCode=300;
int LptNum=0;
int Pass1=pass1;
int Pass2=pass2;
int p1=0;
int p2=12;
int p3=0;
int p4=(int)HaspBuffer;
hasp(Service,SeedCode,LptNum,Pass1,Pass2,&p1,&p2,&p3,&p4);
I've tried this:char HaspBuffer[500]=env->GetStringUTFChars(param1,NULL);
And this:char HaspBuffer[500]=(*env)->GetStringUTFChars(param1,NULL);
All give me errors.
Please help.char * HaspBuffer=(*env)->GetStringUTFChars(param1,NULL); When writing pure C, you have to supply the JNIEnv as first arg to every JNIEnv function pointer.char * HaspBuffer=(*env)->GetStringUTFChars(env, param1, NULL);Look here: http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jnistring.html
-
Importing text file into 2D char array
Hey folks. I've aged a few years trying to figure this project out. Im trying to make a crossword puzzle and am having problems importing the answer letters into a 2D array of 15*15. The text file would look something like this:
LAPSE TAP RAH
AVAIL OLE ODE
BARGE PARADOX
etc
I have JTextFields that the user will answer and a button the user can press to see if the answers are right by comparing the 2D array answer with what the user inputted.-the user input would be scanned and put into a 2D array also.
How should i go about inserting each letter into an array? The spaces i would later need to make code to grey out the text field. This is what i have so far. Forgive me if its sloppy.
class gridPanel extends JPanel
//----Setting Grid variables
private static final int ROWS = 15;
private static final int COLS = 15;
String[] letters = { "A", "B", "C", "D", "E" };// To test entering strings into array
gridPanel()
this.setBackground(Color.BLUE);
//.......Making my JTextField grid for user input
JTextField[][] grid = new JTextField[ROWS][COLS];
for(int ROWS = 0; ROWS<grid.length; ROWS++)
for(int COLS = 0; COLS<grid.length; COLS++)
grid[ROWS][COLS] = new JTextField(1);
add(grid[ROWS][COLS]);
//grid[ROWS][COLS].setText("" + letters[0]);
String an = null;
StringTokenizer tokenizer = null;
Character[][] answer = new Character[ROWS][COLS];
try{
BufferedReader bufAns = new BufferedReader( new FileReader("C:\\xwordanswers.txt"));
for (int rowCurrent = 0; rowCurrent < ROWS; rowCurrent++)
an = bufAns.readLine();
tokenizer = new StringTokenizer(an);
for (int colCurrent = 0; colCurrent < COLS; colCurrent++) {
char currentValue = tokenizer.nextToken().charAt(0);//Needs to be changed to reflect each letter
answer[rowCurrent][colCurrent] = currentValue;
System.out.println(currentValue);
}catch (IOException ioex)
System.err.println(ioex);
System.exit(1);
}//xword graphics end
This obviously prints the first char of each word, it also gives me an "Exception in thread "main" java.util.NoSuchElementException" error for some reason.
Any help is greatly appreciated.
JohnIf the file format is stored as follows:
APPLE
L A
PARSE
N E
PEAR then we can parse this into a 2D char array:
char[][] readMap(String fileName) {
char[][] ret = new char[ROWS][COLS];
FileInputStream FIS = new FIleInputStream(fileName);
int i, j;
for(i = 0; i < ROWS; i++)
for(j = 0; j < COLS; j++)
ret[i][j] = FIS.read();
FIS.close();
return ret;
}Then you can use the resulting 2D char array in your answer checking mechanism.
Hope this helps~
Alex Lam S.L. -
Reading .txt file into char array, file not found error. (Basic IO)
Iv been having some trouble with reading characters from a text file into a char array. I havnt been learning io for very long but i think im getting the hang of it. Reading and writing raw bytes
and things like that. But i wanted to try using java.io.FileReader to read characters for a change and im having problems with file not found errors. here is the code.
try
File theFile = new File("Mr.DocumentReadMe.txt");
String path = theFile.getCanonicalPath();
FileReader readMe = new FileReader(path);
char buffer[] = new char[(int)theFile.length()];
int readData = 0;
while(readData != -1)
readData = readMe.read(buffer);
jEditorPane1.setText(String.valueOf(buffer));
catch(Exception e)
JOptionPane.showMessageDialog(null, e,
"Error!", JOptionPane.ERROR_MESSAGE);
The error is: java.io.FileNotFoundException: C:\Users\Kaylan\Documents\NetBeansProjects\Mr.Document\dist\Mr.DocumentReadMe.txt (The system cannot find the file specified)
The text file is saved in the projects dist folder. I have tried saving it elsewhere and get the same error with a different pathname.
I can use JFileChooser to get a file and read it into a char array with no problem, why doesnt it work when i specify the path manually in the code?Well the file clearly isn't there. Maybe it has a .txt.txt extensionthat Windows is kindly hiding from you - check its Properties.
But:
String path = theFile.getCanonicalPath();
FileReader readMe = new FileReader(path);You don't need all that. Just:
FileReader readMe = new FileReader(theFile);And:
char buffer[] = new char[(int)theFile.length()];You don't need a buffer the size of the file, this is bad practice. Use 8192 or whatever.
while(readData != -1)
readData = readMe.read(buffer);
}That doesn't make sense. Read the data into the buffer and repeat until you get EOF? and do nothing with the contents of the buffer? The canonical read loop in Java goes like this:
while ((count = in.read(buffer)) > 0)
out.write(buffer, 0, count); // or do something else with buffer[0..count-1].
jEditorPane1.setText(String.valueOf(buffer));Bzzt. That won't give you the content of 'buffer'. Use new String(buffer, 0, count) at least. -
Pass char array to c++ DLL and return same char array
Lectori Salutem,
Here is the situation:
Im learning TestStand, and to learn the basics, I want to do the following:
Call a (C++) DLL in TestStand with an array of chars.
The DLL should return the array of chars (or a pointer to the datalocation).
This is the code in my DLL:
TESTDLL3_API char* bounceString(char data[])
data = "Hello World";
cout << data;
char* pointer = data;
return pointer;
However, this function will not be recognized by TestStand
When this is working, I think I can build the rest of the functionality by myself.
Thanks in advance for any help!
Jeroen
The Netherlands
Solved!
Go to Solution.Sadly, in the example there is no return value to TestStand.
However, I did manage to return the pointer of the char array to TestStand:
int __declspec( dllexport ) bounceString2(char* argument)
void *pointer;
int i;
argument = "Hello";
pointer = argument;
i = (int) pointer;
return i;
So, right now I have to find out how to retrieve the char array from the pointer...
Jeroen
PS, I will look at the CVI code, and let you know about my process -
Help:How to get a java String value from a C char array?
Hi,everyone,could you help me?
the following is a C struct that i want to recieve a short message:
struct MO_msg{
unsigned long long msgID; //Message ID
char dest_id[21]; //Destination Mobile Phone Number
char service_id[10]; //
Now I want to put the "dest_id " value of this struct into a Java String variable.But I dont know how to implement it!
The following is a block of source code that i implement this functions.But it cant get a String value ,and throw out a Exception:
java.lang.NullPointerException
at java.lang.StringBuffer.append(StringBuffer.java:389)
JNIEXPORT jint JNICALL Java_md_EMAP_thread_RubeMOTSSX_getMO
(JNIEnv * env, jobject obj, jint connId, jobject mo){
struct MO_msg MO;
tssx_cmpp_api_debug_flag = 1;
int result = CMPP_Get_MO((int)connId,&MO);
if (result == 0){
jclass cls = (*env)->GetObjectClass(env,mo);
jfieldID msgId = (*env)->GetFieldID(env,cls,"msgId","J");
jfieldID dest_Id = (*env)->GetFieldID(env,cls,"dest_Id","Ljava/lang/String;");
jfieldID serviceId = (*env)->GetFieldID(env,cls,"serviceId","Ljava/lang/String;");
(*env)->SetLongField(env,mo,msgId,MO.msgID);
(*env)->SetCharField(env,mo,dest_Id,*destId);
(*env)->SetCharField(env,mo,serviceId,MO.service_id);
return result;
Please help me!Thanks!bschauwe:Thank you for your help!
Yes,just as you say,using NewString Or NewStringUTF can import a C char array into a Java String variable! But now I have another question,when i use these two functions ,i found that it cant deal with Chinese character!
do you have such experiences to deal with another language charset?if you have ,can you tell me how to deal with it. -
Char array conversion from String: toCharArray()
Greetings,
Can anyone tell me why this code:
import com.wuw.debug.Trace;
public
class charTest
public static void
main( String[] args )
String strIn = new String( "strIn" );
Trace.DTRACE( "strIn: "+strIn );
Trace.DTRACE( "strOut: "+strIn.toCharArray() );
}produces this output:
[DTRACE]: strIn: strIn
[DTRACE]: strOut: [C@1fef6f
and not:
[DTRACE]: strIn: strIn
[DTRACE]: strOut: strInBecause:
String.toCharArray returns an array of chars.
An array is basically an object in java.
Objects are converted to strings with the method toString - if it's not implemented in your class the string that method returns will be of the form classname@hashcode.
In the case of a char array, the name of the class is "[C". The hashcode of you object seems to be "1fef6f" (in hex).
You'll just have to remember that an array of chars is [i]not a string in java. -
Hello,
I would like to query the Oracle community about an item
that is giving me some trouble.
I am developping a real time data base for a utility and I
have situation where I receive messages from the SCADA of which
not all are included in the database (for example, the firmware
of some SCADA components has not been programmed correctly and
gives the wrong ID number); I have to update the data base and
then resend to other process the messages I have received.
Naturally I do not want to resend the messages that contain the
wrong information, and as this is a real time data base, I try
to use the fastest techniques available (to the best of my
knowledge), in this case, host arrays.
The trouble is, when updating with host arrays, if no data
is found for a particular ID ( Error ORA-1403), oracle continues
and follows on with the next item in the host array, which is
great, but it does warn you (as far as I know), that that
particulat member of the host array is not included in the data
base.
Is there any method with which I can find out which member
(s) failed in the update? or which members succeded?
Thanks!!!!
nullI found after testing that your response is correct.
The database does not consider '0 rows updated' a true error condition, therefore sqlerrd[2] reports the number of rows that WERE updated,NOT the array offset of the row that did not get updated.
Furthermore, through extensive testing, I have found that the behavior I was told to expect by Oracle is NOT how Oracle behaves. Specially, if I have 5 array items, and item 3 does not result in an update, sqlerrd[2] reports 4 - meaning 4 rows updated, not 2, meaning that the third array item failed to result in an update.
If the first item does not result in an update, the second item results in an update, and the 3rd item results in an oracle error (field too large for instance),sqlerrd[2] does not return 2 as expected (indicating the error occured in array item 3) but instead returns a 1, indicating one row was updated before the error occurred.
Test scenario as follows:
for some table, col1 CHAR[10], col2 CHAR[3] with the following rows:
200010, ABC
200020, ABC
200030, ABC
200040, ABC
200050, ABC
The statement in the ProC code:
UPDATE tablename SET col2 = :v1 where col1 = :v2;
col1 array holds:
200011
200020
200030
200040
200050
col2 array holds:
XYZ
XYZ
XYZZ <<< note field too long forcing Oracle error
XYZ
XYZ
I would expect based on the documentation that sqlerrd[2] returns 2 (3rd array element results in Oracle error), but what happens instead is sqlerrd[2]
returns 1 (indicating that one row was updated, col1=200020, before an error was encountered in 3rd element of array.
If col2 array holds:
XYZ
XYZ
XYZ
XYZ
XYZ
I would expect based on the feedback in the TAR that sqlerrd[2] would return 0 indicating that the first array resulted in a 1403 - what I get is 4,
indicating 4 rows were updated as a result of this array. -
Char arrays is it the right soultion for this problem
I've got enumerated types with each enum constant a different behavior for some method. (+, - , /, *)
I take a string i.e "(5 + 4) * (4 - 2)"
and place each string char into this array
String expression = "(5 + 4) * (4 - 2)" ;
char[] c = express.toCharArray();
I've been trying figure out how inow apply my enums method to the char array. Taking boldBODMAS*bold* in account.
enum Operation {
PLUS { double eval(double x, double y) { return x + y; } }
What fristly was spliting the string at brackets
String[] temp = express.split("[()]");
This trunt out not to work weel for nested mathematical
expressions ie. (4 + (2 * (2 - 1))) * 1.2
I'm quite new to java programming, any ideas/direction on what i should do would be great guys, thanks.Anthony42 wrote:
A while back I had to write an excel-type spreadsheet application, and we had to evaluate expressions and functions.
The easiest way we found to do it was to use a binary tree created from reverse polish notation.
http://en.wikipedia.org/wiki/Reverse_Polish_notation
It should be fairly easy to do with a stack as well.Reverse Polish is a stack implementation. But first he will need to translate the infix operator precedence based notation into a postfix notation.
If this wasn't homework the OP would be able to choose something other than the traditional grade school arithmetic model he describes as BODMAS. -
How Do You Populate A Spark List Control With An Array?
Hello, all,
Sorry to come accross so frustrated, but how in the name of God do you populate a Spark list control with the data in an array? You used to be able to do this with the mx:List control, but the guys developing Flex just had to make things more difficult than they need to be! I am more of a code purist and prefer doing things the way they have been done for decades, but apparently nothing can ever stay simple!
I simply want to populate a list control with an array and this shouldn't be rocket science! I found out that I must use a "collection" element, so I decided that an arrayCollection would be best. However, after searching Adobe's documentation about arrayCollections, I am lost in a black hole of data binding, extra lines of code just to add a new element, the need to sort it, etc...!
Here is my code:
var pendingArray:ArrayCollection = new ArrayCollection();
for ( var i:int = 0 ; i < queue.length ; i++ )
var item:UserQueueItem = queue[i] as UserQueueItem ;
if ( item.status == UserQueueItem.STATUS_PENDING )
pendingArray.addItem({label:item.descriptor.displayName,descriptor:item.descriptor});
Here is the relevant MXML:
<s:VGroup>
<s:List id="knockingList" width="110" height="100"/>
</s:VGroup>
I'm not getting any errors, but the list is not populating.
I have seen several examples where the arrayCollection is declared and populated in MXML:
<mx:ArrayCollection id="myAC">
<!-- Use an fx:Array tag to associate an id with the array. -->
<fx:Array id="myArray">
<fx:Object label="MI" data="Lansing"/>
<fx:Object label="MO" data="Jefferson City"/>
<fx:Object label="MA" data="Boston"/>
etc...
</fx:Array>
</mx:ArrayCollection>
That may be fine for an example, but I think this is a rare situation. Most of the time I would image that the arrayCollection would be created and populated on the fly in ActionScript! How can I do this?
Thanks in advance for any help or advice anyone can give!
MattIn your post it seemed like you were trying to take care of many considerations at once: optimization, design, architecture. I would suggest you get something up and running and then worry about everything else.
If I use data binding, then I will probably have to declare the arrayCollection as a global variable and then I'll have to write 100 or so extra lines of code to addItem(), removeItem(), sort(), etc... It just seems like too much overhead.
I believe you may have some misconceptions about databinding in general. You won't have to make it a global variable and you certainly won't need an extra 100 lines of code. If you did this forum would be a very , very quiet place.
I don't want to use data binding because the original array is refreshed often and there is one function called by an event that re-declares the arrayCollection each time, populates it with the array, and then sets it as the list's dataprovider.
That is the beauty of the ArrayCollection, it can handle the updates to its source Array. I don't know if you need to redeclare the ArrayCollection, resetting the source to the new Array allows everyone involved to keep their references so you don't have to worry about any "spooky" stuff going on. -
Help with parallel arrays of different data types
Hello all, I am having an issue with parallel arrays. My program requires me to read information from a text file into 4 parallel arrays (2 String and 2 double). My text file needs to look something like this:
John Johnson
0000004738294961
502.67
1000.000
Jane Smith
0000005296847913
284.51
1000.000
...and so on
Where the first thing is the name (obviously), an account number, the balance in the account, and the credit limit. I just cant figure out how to read everything into the arrays. We havent learned anything too heavy, and this seems a little too advanced for my class, but I guess we will manage. Any help will be appreciated. Thanks guys.
CaseyMan this is a dumb homework assignment. The requirements scream out for a class along the lines of
public class Account{
private String name, number;
private double balance,creditlimit;
// more code here
}and then to use a List of Account objects.
Anyway what's your actual problem. There's nothing very hard about it. A loop. So....
You should consider posting (formatted) code showing what you have done and where exactly you are stuck. -
Performance Problems with intrinsic array multiplikation in Fortran with Su
Hello,
I found a serious performance problem in my application with intrinsic array multiplikation. Therefore I wrote a small test program to check if this a general problem or only exists in my code.
The test program (as seen below) was compiled with Sunstudio12 und Solaris 5.10 on an 64 bit Amd Opteron Machine. First with high optimization (f95 -fast -g), and the second time with out optimization (f95 -O0 -g). In both cases the intrinsic array mupltiplication had a lot of tlb and L2 cache misses (I made some test with the performance analyzer) which caused a huge increase in computation time compared to the explicit loop. In the ideal case the compiler should create the nested loops from the intrinsic statement and both functions should use exactly the same computing time.
I also tried compiling with Studio11, the problem also occurs there. Maybe its a compiler bug but I'm not sure.
Greetings
Michael Kroeger
program test
!Test zur Ausfuehrung einer einfachen array Multiplikation
implicit none
real,dimension(:,:,:),pointer::check1,check2
integer i,j,k,ni,nj,nk,status
ni=1000
nj=1000
nk=100
allocate(check1(0:ni,0:nj,0:nk),STAT=status)
write(*,*)status
allocate(check2(0:ni,0:nj,0:nk),STAT=status)
write(*,*)status
check1(i,j,k)=25
check2(i,j,k)=25
call intrinsic_f(check1)
call withloop(check2,i,j,k)
deallocate(check1,check2)
contains
subroutine intrinsic_f(check1)
real, dimension(:,:,:),pointer::check1
check1=check1*5
end subroutine intrinsic_f
subroutine withloop(check2,ni,nj,nk)
real, dimension(:,:,:),pointer::check2
integer i,j,k,nk,nj,ni
do k=0,nk
do j=0,nj
do i=0,ni
check2(i,j,k)=check2(i,j,k)*5
enddo
enddo
enddo
end subroutine withloop
end programI will try the large pages, but what me puzzles is, that the intrinsic function has cache misses, but the loop function has not. All documentation says, that the compiler would expand the intrinsic function into 3 nested loops, so that both functions should be essential the same (and the compiler says it has created 3 loops from the intrinsic). Since they are not the same, this is a severe problem.
I have a fairly large code for high performance simulations, and this intrinsic functions are a significant bottle neck. If it is not a compiler bug, I would have to rewrite all intrinsic functions into loops. -
Trouble with primitive arrays and casting, lesson 521
hi everyone!
there is a problem i discovered right now - after years with java where was no necessity to do this.....
and i'm shure this must have been the topic already, but i couldn't find any helpful resource :-/
right here we go:
1. an array is a (special) kind of object.
2. there are "primitive" arrays and such containing references to objects. of course - and i imagine why - they are treated differently by the VM.
3. then both are - somehow - subclasses of Object. whereas primitive types are not really, primitive-arrays are. this is hidden to the programmer....
4. any array can be "pointed" at via local Object variable, like this:
Object xyz = new int[6];
5. arrays of Objects (with different dimensions) can be casted, like this:
Object pointer = null;
Object[] o = new SomeClass[42] ;
Object[][] oo = new OtherClass[23] [2] ;
Object[][][] ooo = new OtherClass[23] [2] [9] ;
o = oo = ooo; // this is save to do,
//because "n-dimensional" object-arrays
// are just arrays of other arrays, down to simple array
pointer = o; // ok, we are referencing o via Object "pointer"6. but, you cannot do this with primitive types:
int[] i1 = new int [99] ;
int[][] i2 = new int [1] [3] ;
i1 = i2 // terror: impossible. this is awful, if you ask me.
// ok, one could talk about "special cases" and
// "the way the VM works", but this is not of interest to me as
// a programmer. i'm not happy with that array-mess!
pointer = i2; // now this is completely legal. i2, i1 etc is an object!7. after the preparation, let's get into my main trouble (you have the answer, i know!) :
suppose i have a class, with methods that should process ANY kind of object given. and - i don't know which. i only get it at runtime from an unknown source.
let's say: public void BlackBox( Object x );
inside, i know that there might be regular objects or arrays, and for this case i have some special hidden method, just for arrays... now try to find it out:
public void BlackBox( Object x )
if ( x == null)
return;
Class c = x.getClass();
if ( c.isArray() )
// call the array method if it's an array.........
BlackBoxes( (Object [] ) x ); // wait: this is a cast! and it WILL throw an exception, eventually!
return;
else
DoSpecialStuffWith( x );
}ok ? now, to process any kind of array, the special method you cannot reach from outside:
private void BlackBoxes( Object[] xs )
if ( xs != null )
for ( Object x : xs )
BlackBox( x );
// this will end up in some kind of recursion with more than one array-dimension, or when an Object[] has any other array as element!this approach is perfectly save when processing any (real) Object, array or "multi-dimensional" arrays of Objects.
but, you cannot use this with primitive type arrays.
using generics wouldn't help, because internally it is all downcasted to Object.
BlackBox( new Integer(3) ) ---- does work, using a wrapper class
BlackBox( new Integer[3] ) ----- yep!
BlackBox( 3 ) ---- even this!
BlackBox( new int[42] ) ---- bang! ClassCastException, Object[] != int[]
i'm stuck. i see no way to do this smoothly. i could write thousands of methods for each primitive array - BlackBox( int[] is ) etc. - but this wouldn't help. because i can't cast an int[][] to int[], i would also have to write countless methods for each dimension. and guess, how much there are?
suppose, i ultimately wrote thousands of possible primitive-type methods. it would be easy to undergo any of it, writing this:
BlackBox( (Object) new int[9] [9] );
the method-signature would again only fit to my first method, so the whole work is useless. i CAN cast an int[] to Object, but there seems no convenient way to get the real array out of Object - in a generic way.
i wonder, how do you write a serialisation-engine? and NO, i can't rely on "right usage" of my classes, i must assume the worst case...
any help appreciated!thanks, brigand!
your code looks weird to me g and i think there's at least one false assumption: .length of a multidimensional array returns only the number of "top-level" subarrays. that means, every length of every subarray may vary. ;)
well i guess i figured it out, in some way:
an int is no Object;
int[ ] is an Object
the ComponentType of int [ ] is int
so, the ComponentType of an Object int[ ] is no Object, thus it cannot be casted to Object.
but the ComponentType of int [ ] [ ] IS Object, because it is int [ ] !
so every method which expects Object[], will work fine with int[ ] [ ] !!
now, you only need special treatment for 1-dimensional primitive arrays:
i wrote some code, which prints me everything of everything:
//this method generates tabs for indentation
static String Pre( int depth)
StringBuilder pre = new StringBuilder();
for ( int i = 0; i < depth; i++)
pre.append( "\t" );
return pre.toString();
//top-level acces for any Object
static void Print( Object t)
Print ( t, 0);
//the same, but with indentation depth
static void Print( Object t, int depth)
if ( t != null )
//be shure it is treated exactly as the class it represents, not any downcast
t = t.getClass().cast( t );
if ( t.getClass().isArray() )
//special treatment for int[]
if ( t instanceof int[])
Print( (int[]) t, depth);
// everything else can be Object[] !
else
Print( (Object[]) t, depth );
return;
else
System.out.println( Pre(depth) + " [ single object:] " + t.toString() );
else
System.out.println( Pre(depth) + "[null!]");
// now top-level print for any array of Objects
static void Print( Object [] o)
Print( o, 0 );
// the same with indentation
static void Print( Object [] o, int depth)
System.out.println( Pre(depth) + "array object " + o.toString() );
for ( Object so : o )
Print( so, depth + 1 );
//the last 2 methods are only for int[] !
static void Print( int[] is)
Print( is, 0 );
static void Print( int[] is, int depth)
System.out.println( Pre(depth) + "primitive array object " + is.toString() );
// use the same one-Object method as every other Object!
for ( int i : is)
Print ( i, depth + 1 );
System.out.println( "-----------------------------" );
}now, calling it with
Print ( (int) 4 );
Print ( new int[] {1,2,3} );
Print( new int[][] {{1,2,3}, {4,5,6}} );
Print( new int[][][] {{{1,2,3}, {4,5,6}} , {{7,8,9}, {10,11,12}}, {{13,14,15}, {16,17,18}} } );
Print( (Object) (new int[][][][] {{{{99}}}} ) );
produces this fine array-tree:
[ single object:] 4
primitive array object [I@9cab16
[ single object:] 1
[ single object:] 2
[ single object:] 3
array object [[I@1a46e30
primitive array object [I@3e25a5
[ single object:] 1
[ single object:] 2
[ single object:] 3
primitive array object [I@19821f
[ single object:] 4
[ single object:] 5
[ single object:] 6
array object [[[I@addbf1
array object [[I@42e816
primitive array object [I@9304b1
[ single object:] 1
[ single object:] 2
[ single object:] 3
primitive array object [I@190d11
[ single object:] 4
[ single object:] 5
[ single object:] 6
array object [[I@a90653
primitive array object [I@de6ced
[ single object:] 7
[ single object:] 8
[ single object:] 9
primitive array object [I@c17164
[ single object:] 10
[ single object:] 11
[ single object:] 12
array object [[I@1fb8ee3
primitive array object [I@61de33
[ single object:] 13
[ single object:] 14
[ single object:] 15
primitive array object [I@14318bb
[ single object:] 16
[ single object:] 17
[ single object:] 18
array object [[[[I@ca0b6
array object [[[I@10b30a7
array object [[I@1a758cb
primitive array object [I@1b67f74
[ single object:] 99
-----------------------------and i'll have to write 8 methods or so for every primitive[ ] type !
sounds like a manageable effort... ;-) -
Change properties of a cluster element withing an array of clusters
Hello all,
I have an array of cluster that is shaped as a line with different display elements.
A list or a tree wouldn't have made it, so I had to use a cluster and make a table.
The problem is that I want to change not only the text but also the text color.
Individually.
I found this :
http://www.ni.com/example/30904/en/
But it change the property in all the clusters in the array, not just the one I need.
Some people have the same problem :
http://forums.ni.com/t5/LabVIEW/Reference-to-Array-of-Clusters-with-an-array-element/td-p/1006427
http://forums.ni.com/t5/LabVIEW/Different-set-of-values-for-two-rings-in-an-array-of-clusters/m-p/10...
http://forums.ni.com/t5/LabVIEW/array-of-clusters-get-references-to-all-the-clusters/td-p/1079456
http://forums.ni.com/t5/LabVIEW/How-can-I-reference-the-properties-of-a-control-in-a-cluster-in/m-p/...
http://forums.ni.com/t5/LabVIEW/Writing-only-to-certain-cluster-elements-in-an-array-by/m-p/2200728
http://forums.ni.com/t5/LabVIEW/Update-Properties-Of-One-Control-In-An-Array/m-p/3015501
http://forums.ni.com/t5/LabVIEW/Array-of-clusters-and-in-the-cluster-is-a-bar-meter-how-can-I/m-p/15...
http://forums.ni.com/t5/LabVIEW/Property-node-of-a-control-inside-of-cluster-inside-an-array/m-p/946...
Obviously, while in a list/table or tree you can change the property of an individual
cell (font, color) you cannot do it within an array of cluster, by some sort of magic,
the property of a cluster element (font, color) are all linked together, hence rendering
the use of an array worthless.
A possible hack is proprosed by using control masking, setting one visible and the
other invisble, swapping their position, whatever. It's a hack you have to perform,
hence add another code to maintain.
Is that still the case or is there now a more official way to handle individual cluster
properties, not just its data ? After all that's a common real-life example that should
be handled by Labview. In my opinion.
David Koch
Solved!
Go to Solution.altenbach wrote:
One of the elements could be a 2D picture indicator of about the same size. You can write text in any color using picture functions.
Here's what I had in mind. Seems to work just fine (I would fine-tune the font, picture border, etc. but this should get you started).
LabVIEW Champion . Do more with less code and in less time .
Attachments:
ColorText.png 13 KB
ColorText.vi 9 KB
Maybe you are looking for
-
TS1702 I need some help the apps were downloading slowly
The apps downloaded but it didn't cause it's stuck in downloading mode what should I do? The iOS 6 update didn't work. Please I need some help. The apps didn't download. Talking Angela and Ginger didn't download. Talking Santa didn't update.
-
In Forms 10g Where does SQLs execute?
In Oracle Forms 10g there is Java Applet on top of which our Application runs. Now suppose we have a button and in that we execute a SQL to get a column value. Now where does the SQL fire? Does it fire in the Applet (i.e in client) or does it go to t
-
Laptop unable to 'communicate' with hp 3050a printer wirelessly
laptop unable to 'communicate' with hp 3050a printer wirelessly, could it be the virgin superhub? (been on the phone to Virgin for an hour they said not their problem) i can eprint and print using a usb cable. Printer displays 'connected' message. O
-
Loading and viewing XML when a class object is created..Help Please
Hello, I have writing a simple class which has a method that gets invoke when the object of the class is created. I am able to view the loaded XML content when I trace it with in my class method, but cannot assign the content to a instance variable u
-
Re: servicegen classpath
HI Kevin, Please make sure your webservice.jar is the same version as weblogic.jar. If you still can't get it work, could please send me your EJB? and a full stack trace can also be very helpful. Thanks -Neal Can you post or send me personally follow