This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to set a pointer to staic array? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to set a pointer to staic array?" Watch "How to set a pointer to staic array?" New topic
Author

How to set a pointer to staic array?

Seema Shetty
Greenhorn

Joined: Jan 23, 2001
Posts: 9
Hi,
I need the code sample showing how to set the pointer to the static array.
I have the string array intialized to some strings.
Ex :
static final String[] DB_ERROR = {"dberror1",
"dberror2",
"dberror3",
"dberror4",
"dberror5",
"dberror6",
"dberror7",
"dberror8"};
How can I set the pointer to this?
Thanks in advance
Seema
Andy Ceponis
Ranch Hand

Joined: Dec 20, 2000
Posts: 782
Pointer? I could tell you how in C, but dunno bout Java.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
What do you mean "set the pointer". I can see that you have created and initialized an array of strings, but what do you actually want to do with it?


A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
DB_ERROR[0] "points" to the first error, DB_ERROR[1] is the second error, etc.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Arrays are reference types. That means you can assign DB_ERROR to any type-compatible reference variable. I.e., you can assign it to a reference variable of type String[]. (Or of type Object[] or of type Object. If you store it in a more general type you'll have to use type-casting to get to the array or its elements.)
// If DB_ERROR is declared in class YourClass, you can save
// the reference in a variable you declare and use it as
// needed.
String[] myStringArrayReference = YourClass.DB_ERROR;
...
System.out.println(myStringArrayReference[0]);
Seema Shetty
Greenhorn

Joined: Jan 23, 2001
Posts: 9
Hi Max,
Now if I want to set this pointer to the DB_ERROR in a method called setDB_Error().Whwt input parameters should I pass, so that I will have the access to this DB_ERROR array from anywhere within the project.What I mean is
if I have an interface called EnglishError which has the initialization for DB_ERROR[].Then I have a method called as setDB_Error() in a class called ErrorHandler.
What all the input parameters I need to pass to this setDB_Error() , so that I can get access to the DB_ERROR[] of EnglishError interface when I instantiate this with the use bean with the application scope?.Can I have the code for setDB_Error.
I tried to do this way.I do not think,this is right.
public static void setDB_Error()
{

myDBErrArrRef = EnglishError.DB_ERROR;
}
public static String[] myDBErrArrRef = null;
What should be the input parameter, to the above method, so that I can instantiate this method use the code below.
instantiate the ErrorHandler and get access to DB_ERROR[].
<jsp:useBean id="myErrorHandler" scope="application" <br /> class="ErrorHandler">
myErrorHandler.setDB_Error();
</jsp:useBean>
After doing this ,I should also be able to access any of the methods of ErrorHandler.
Thanks
Seema
[This message has been edited by Seema Shetty (edited March 22, 2001).]
Seema Shetty
Greenhorn

Joined: Jan 23, 2001
Posts: 9
Thanks Max,
I tried that and it worked.
Seema.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to set a pointer to staic array?
 
Similar Threads
Empty Array as opposed to Null Array
how to implement array of objects???
pointers in java
int[] = null; help
dynamic array