Solved

Strings.......

Posted on 2002-04-04
6
177 Views
Last Modified: 2010-03-31
i have an array of strings declared as so:
String[] jstrings =
{
"<html><H2><B><FONT COLOR=Black>Name</H2></HTML>", //jstring[0]
" ", //jstring[1]
};

i then retrieve a value from a database known as report name which i want to set as the text in jstring[1]. This is done using
jstring[1] = reportname;
from debugging i know that the correct result is contained in jstring[1] after this.

however i wish to display these strings in a table using:
Object [][] data = {
{jstrings[0], jstrings[1], " ", " "},
{jstrings[2], " ", " ", " "},
};

but jstring[1] contains a null value at this point!

can anyone help?
0
Comment
Question by:Codster
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 6917798
Are you saying that (String)data[0][1] is equal to null, when you expected it to contain a report name?
0
 
LVL 1

Expert Comment

by:tonejunkie
ID: 6917873
Codster,  I'd look into using collections such as Vector, instead of arrays.  There's almost no need for arrays in Java (almost).

//This way you can do:
Vector jstrings = new Vector();
jstrings.addElement(reportname);

//Then to display the string contained in
//a certain place (let's say 1):
jstrings.elementAt(1);

//You might have to cast it, because it will
//return an object and not a String.
(jstrings.elementAt(1)).toString();
0
 

Author Comment

by:Codster
ID: 6917950
yes the string should contain report name

i am using arrays because there are many elements in the array not just the three that i specified
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Expert Comment

by:tonejunkie
ID: 6917984
Why would that require arrays?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 5 total points
ID: 6918086
We'll talk about containers later. What we need to know is everything that happens between your valid string and your invalid string.

First of all, confirm that 1 and 2 below are correct propostions, then show the code in between:

1. System.out.println(jstrings[1]) gives a valid report name.
2. System.out.println((String)data[0][1]) gives 'null'
0
 
LVL 92

Expert Comment

by:objects
ID: 6920057
Need to see more code, from what you've shown there is no way that either jstrings[1] or data[0][1] could be null.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changePi Challenge 15 77
wordlen challenge 3 47
wordcount challenge 11 78
Java Loop 4 22
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now