JavaScript is not enabled on your browser and in order to properly use Coder Profile JavaScript is required.
To view instructions on how to enable JavaScript on your browser click here .
I'm creating a system for creating, managing and getting data aswell as drawing tables in a CLI using Java. So now I have experienced a problem, my sources are:
CODE: Table.java
Copy / Restore :: Remove Scroll Bars
package drawtable ;
public class Table {
private int rows = 1 , columns = 1 ;
boolean borders = true ;
public Table( int row, int col)
{
this .rows = row;
this .columns = col;
this .createArray ( ) ;
}
public Table( int row, int col, boolean border) {
this .rows = row;
this .columns = col;
this .borders = border;
this .createArray ( ) ;
}
public void createArray( ) {
data
= new String [ this .
rows + 1 ] [ this .
columns + 1 ] ; }
public void insertDataAt
( int row,
int col,
String value
) { data[ row] [ col] = value;
}
public String getDataFrom
( int row,
int col
)
{ return data[ row] [ col] ;
}
public int getRows( ) {
return rows;
}
public int getColumns( ) {
return columns;
}
public boolean getBorders( ) {
return borders;
}
public void setBorders( boolean visible) {
borders = visible;
}
public void clearCell( int row, int col) {
data[ row] [ col] = null ;
}
public void clearAllCells( ) {
}
public int [ ] findCellContaining
( String text
) { int i =
0 , j = 0 ;
int pos[ ] = new int [ 1 ] ;
for ( i = 1 ; i <
this .getRows ( ) ; i++ ) {
for ( j = 1 ; j <
this .getColumns ( ) ; j++ ) {
temp = data[ i] [ j] ;
if ( temp.contains ( text) ) {
pos[ 0 ] = i;
pos[ 1 ] = j;
}
}
}
if ( int_str == null ) {
pos[ 0 ] = -1 ;
pos[ 1 ] = -1 ;
}
return pos;
}
public void printTable( ) {
int i;
for ( i = 1 ; i <
this .getRows ( ) + 1 ; i++ ) {
int j;
for ( j = 1 ; j <
this .getColumns ( ) + 1 ; j++ ) {
if ( borders) {
}
System .
out .
print ( data
[ i
] [ j
] + "\t " ) ; }
if ( borders) {
int k;
for ( k = 0 ; k <
this .getColumns ( ) + 1 ; k++ ) {
System .
out .
print ( "-----------" ) ; }
}
}
}
public int getLenghtOfLongestString( ) {
int i;
int longestString = 0 ;
for ( i = 1 ; i <
this .getRows ( ) + 1 ; i++ ) {
int j;
for ( j = 1 ; j <
this .getColumns ( ) + 1 ; j++ ) {
if ( ( data[ i] [ j] .length ( ) ) > longestString) {
longestString = data[ i] [ j] .length ( ) ;
}
}
}
return longestString;
}
}
Select what you want to copy and in doing so you will keep the formatting when pasting it.
CODE: main method for testing
Copy / Restore :: Remove Scroll Bars
package drawtable ;
public class Main {
public static void
main
( String [ ] args
) { Table table= new Table( 8 ,7 ,true ) ;
table.insertDataAt ( 8 , 7 , "Hello World!" ) ;
table.insertDataAt ( 3 , 4 , "joke" ) ;
table.insertDataAt ( 1 , 2 , "This is some additional
data" ) ;
System .
out .
println ( table.
getDataFrom ( 1 ,
1 ) ) ; table.printTable ( ) ;
System .
out .
println ( table.
getLenghtOfLongestString ( ) ) ; int [ ] position= table.findCellContaining ( "joke" ) ;
int i;
for ( i= 0 ; i< 1 ; i++ ) {
System .
out .
println ( position
[ i
] ) ; }
}
}
Select what you want to copy and in doing so you will keep the formatting when pasting it.
Both table.getLenghtOfLongestString() and table.findCellContaining() seem to cause NullPointerExceptions. Running the debugger on findCellContaining suggests that the String known as temp disappears (this extra variable was added for debugging). I'm really confused, but I believe there is a Java genious on these boards able to help me..? Very appreciated.
Forgot to say, the NullPointerException occurs at the if() sentances at both problematic methods
You do not have permission to post replies to topics in this board. If you want to join in with discussions and create new topics please register. If you want to register your own free account with us, please click here .
Latest News About Coder Profile
Coder Profile Poll
If you made money from keeping your profile up to date, say $30 and up, per month. What extra time would you spend on your profile?
No extra time A few hours at weekends A whole day each week Every minute i can get freeplease login to cast your vote and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.49 Years Ago