ok this is just a shot in the dark but it may be the cause of most of the errors ive gotten.
when your initializing something. lets say a smal swing program. would it go like this
variables here
{
private Jlist contactList;
String [] contactArray;
ArrayList <String> contactArrayList;
ResultSet namesList
// constructor here
public whatever()
{
GridLayout aGrid = new GridLayout(2,2,10,10);
contact1 = new String();
contact2 = new String();
contact3 = new String();
contactArrayList = new ArrayList<String>();
// is something supposed too go in the () of this JList?
contactList = new JList();
contactArray = new String[5];
from1 =new JLabel ("From: " + contactArray[1]);
gridlayout.add(components)// theres too many components to write onto SO.
}
// methods here
public void fillContactsGui()
{
createConnection();
ArrayList<String> contactsArrayList = new ArrayList<String>();
while (namesList.next())
{
contactArrayList.add(namesList.getString(1));
ContactArray[1] = namesList[1];
}
}
i know this is probably a huge beginner question but this is the code ive gotten used too. im initializing thigns three and fours times without meaning too because im not sure where they gp. can anyone shed some light on this?
p.s. sorry for the messy sample code. i done my best.
ok a little clearer here then.
the general layout of code is what im asking about.
my code is formatted like this.
variables; constructor; methods;
would i be right in saying it should look like this
public class test
{
int i;
public test()
{
i = 0;
}
public void addi()
{
i = i +1;
}
}
and not like this
public class test
{
int i = 0;
public test()
{
int i = 0;
}
public void addi()
{
int i = i +1;
}
}
im trying to figure out the right way to initialize variables. because im defining them each time i use them