Alternatives to binding to static variables

As has been discussed before, flex does not dispatch a binding event when a static variable changes. I was wondering if there are any alternatives to simulate this functionality.
I have a class called UserDataManager which contains static properties i use throughout my application. One of these is an array which i need to access and change on various different components throughout my application. After changing this must then change the array on all the other components.
I suspect i could manage this by 2-way binding on an instance of UserDataManager and passing this instance to all the components on creation, however this seems like a computationly and time expensive workaround.
Are there any alternatives?
Thanks

Use a singleton pattern so your statics arent static.

Similar Messages

  • Non-static variable change cannot be referenced from a static context

    My compiler says: : non-static variable change cannot be referenced from a static context
    when i try to compile this. Why is it happening?
    public class change{
      int coin[] = {1,5,10,25,50};
      int change=0;
      public static void main(){
        int val = Integer.parseInt(JOptionPane.showInputDialog(null, "Type the amount: ", "Change", JOptionPane.QUESTION_MESSAGE));
        change = backtrack();
    }

    A static field or method is not associated with any instance of the class; rather it's associated with the class itself.
    When you declared the field to be non-static (by not including the "static" keyword; non-static methods and fields are much more common so it's the default), that meant that the field was a property of an object. But the static main method, being static, didn't have an object associated with it. So there was no "change" property to refer to.
    An alternative way to get this work, would be to make your main method instantiate an object of the class "change", and put the functionality in other instance methods.
    By the way, class names are supposed to start with upper-case letters. That's the convention.

  • IS there static variables in oracle 9i??

    Hi,
    I have a requirement.
    I am establishing an orcale 9i connection from my .net application.
    Now I am calling an SP and it has a global count variable initialized to 0, and It fetches a count of * from one table and also there are other functionality that the SP does.
    Now I want to persisit this count variable's value , so that next time the SP is called ( in the same connection), I will make a check that if the count variable is not 0 then dont execute the query to populate the count variable.
    Normally in java, .net etc... we can create static variables for this purpose.
    Can the same be done in PL/SQL?
    If not what would be the alternative?
    Thanks folks.
    s

    Hi,
    Please have a look.
    SQL> create or replace package test_pkg
    2 is
    3 procedure test_1;
    4 end test_pkg;
    5 /
    Package created.
    SQL> create or replace package body test_pkg
    2 as
    3 global_cnt number(10):=0;
    4 procedure test_1
    5 is
    6 begin
    7 if global_cnt > 0
    8 then
    9 dbms_output.put_line('No RUN');
    10 else
    11 dbms_output.put_line('RUN');
    12 global_cnt := global_cnt + 1;
    13 end if;
    14 end;
    15 end test_pkg;
    16 /
    Package body created.
    SQL> set serveroutput on
    SQL> exec test_pkg.test_1
    RUN
    PL/SQL procedure successfully completed.
    SQL> exec test_pkg.test_1
    No RUN
    PL/SQL procedure successfully completed.
    SQL> exec test_pkg.test_1
    No RUN
    PL/SQL procedure successfully completed.
    SQL>
    -----------------------------------------------------------------------

  • Static variable and non-static

    I have a quick question. The following syntax compiles.
    private String t = key;
    private static String key = "key";
    But this doesn't compile.
    private String t = key;
    private String key = "key";
    Can anybody explain how it is treated in java compiler?
    Thanks.

    jverd wrote:
    doremifasollatido wrote:
    I understand that completely. I didn't say that the OP's version with static didn't work. I was just giving an alternative to show that you don't need static, if you change the order that the instance variables are declared.My problem with the underlined is that, while technically true, I can see where a newbie would take it as "oh, so that's how I can get rid of static," and focus only on how to satisfy the compiler, rather than on learning a) when it's appropriate to make something static or not from a design perspective, and b) what the implications of that decision are, for both static and non.
    I have just a wee bit of a prejudice against the "what do I type to make the error messages go away" approach. :-)That sounds good to me. We're currently trying to fix an issue caused by the fact that one class has most of its variables as static, when they should really be instance variables. There should only be one active instance of this class at a time, but the values of the static variables stick around when you call "new ThisClass()". So, old data interferes with new data, and various errors happen. The class has many static methods to access the static variables, but it should have been more of a Singleton--an actual object with non-static variables. The active instance of the Singleton would need to be replaced at logout/login (as opposed to shutdown completely and restart the JVM), but then at least when the new instance were created, then all of the variables would be initialized to empty--the old instance would disappear. The solution at the moment (solution by others--I don't agree) is to clear each static Vector and then set the reference to null (setting to null would be enough to drop the old data, but certain people don't get that...). This is fragile because many variables were missed in this "cleanup" process, and it will be easy to forget to "cleanup" new variables in the future. This class has been misdesigned for years (much longer than I've been here). The calls to static methods permeate the application, so it isn't easy to fix it quickly. There are several of these misdesigned classes in our application--a mix of static and non-static, when nothing or almost nothing should be static.

  • Error on compile - non-static variable can not be referencedfrom static con

    Error on compile happening with addButton?
    Thanks
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JFrame;
    public class Log implements ActionListener {
    JButton addButton;
    public static void addComponentsToPane(Container pane) {
    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
         c.gridy = 3;
    c.gridx = 0;
         JLabel callsignLabel= new JLabel("Callsign");
    pane.add(callsignLabel, c);
         c.gridy = 3;
    c.gridx = 1;
         JLabel nameLabel= new JLabel("Name");
    pane.add(nameLabel, c);
         c.gridy = 3;
    c.gridx = 2;
         JLabel timeLabel= new JLabel("Time");
    pane.add(timeLabel, c);
         c.gridy = 3;
    c.gridx = 3;
         JLabel dateLabel= new JLabel("Date");
    pane.add(dateLabel, c);
         c.gridy = 3;
    c.gridx = 4;
         JLabel frequencyLabel= new JLabel("Freq ");
    pane.add(frequencyLabel, c);
         c.gridy = 3;
    c.gridx = 5;
         JLabel locationLabel = new JLabel("Country/State");
    pane.add(locationLabel, c);
    c.gridy = 5;
    c.gridx = 0;
         addButton = new JButton("Add");
    pane.add(addButton, c);
         addButton.addActionListener(this);

    Thank you for the reply
    I am new to Java
    What is wrong with the way it is coded?The error message tells you what's wrong: You're trying to reference a non-static variable from a static context.
    If you don't know what that means, then click the link I provided and look at the results from that google search. You might have to go through a few before you find a satisfactory explanation. And after you've done that, if you have specific questions about things you didn't understand there, please post again.

  • Using a static variable declared in an applet in another class

    Hi guys,
    I created an applet and i want to use one of the static variables declared in teh applet class in another class i have. however i get an error when i try to do that...
    in my Return2 class i try to call the variable infoPanel (declared as a static JPanel in myApplet...myApplet is set up like so:
    public class myApplet extends JApplet implements ActionListener, ListSelectionListener
    here are some of the lines causing a problem in the Return2 class:
    myApplet.infoPanel.removeAll();
    myApplet.infoPanel.add(functionForm2.smgframeold);
    myApplet.infoPanel.validate();
    myApplet.infoPanel.repaint();
    here are some of the errors i get
    dummy/Return2.java [211:1] package myApplet does not exist
    myApplet.infoPanel.removeAll();
    ^
    dummy/Return2.java [212:1] package myApplet does not exist
    myApplet.infoPanel.add(functionForm2.smgframeold);
    ^
    dummy/Return2.java [213:1] package myApplet does not exist
    myApplet.infoPanel.validate();
    ^
    dummy/Return2.java [214:1] package myApplet does not exist
    myApplet.infoPanel.repaint();
    ^
    please help! thanks :)

    I don't declare any packages though....i think it just doesn't recognize myApplet for some reason..
    other errors i got compiling are:
    dummy/Return2.java [82:1] cannot resolve symbol
    symbol : variable myApplet
    location: class Return2
    updateDesc.setString(3, myApplet.staticName);
    I Don't get why i'm getting this error cuase they worked fine when myApplet was a standalone application, not an applet.
    myApplet is in the same folder as Return2 and it compiles properly.

  • How can I write an instance of a class in a static variable

    Hi !
    I have an instance of a class
    Devisen dev = new Devisen();
    In an other class I have a static method and I need there the content of some variables from dev.
    public static void abc()
    { String text=dev.textfield.getText()
    I get the errormessage, that the I cannot use the Not-static variable dev in a static variable.
    I understand that I cannot reference to the class Devisen because Devisen is not static I so I had to reference to an instance. But an instance is the same as a class with static methodes. (I think so)
    Is there a possibility, if I am in a static method, to call the content of a JTextField of an instance of a class ?
    Thank you Wolfgang

    Hallo, here is more code for my problem:
    class Login {
       Devisen dev=new Devisen();
    class Devisen {
       JTextField field2;
       if (!Check.check_field2()) return; // if value not okay than return
    class Check {
       public static void check_field2()
         HOW TO GET THE CONTENT OF field2 HERE ?
    One solution ist to give the instance to the static function, with the keyword "this"
    if (!Check.check_field2(this)) return;and get the instance
    public static void check_field2(Devisen dev)BUT is that a problem for memory to give every method an instance of the class ? I have 50 fields to control and I dont want do give every check_method an instance of Devisen, if this is a problem for performance.
    Or do I only give the place where the existing instance is.
    Hmm...?
    Thank you Wolfgang

  • Loading the final static variables at run time.. Please help

    Hello, fellow developers & Gurus,
    Please help me figure out the best way to do this:
    I need to load all my constants at run time. These are the public static final instance variables. The variables values are in the DataBase. How do I go about loading them.

    Your original question was diffeent, but your further posts show what you really want to do:
    1) all constants in 1 class
    2) available readonly for other classes
    3) updatable during runtime by changing in the database
    Did I understand you right?
    Then smiths' approach solves point 2):
    Instead, make the variables available through a method
    call - that way you avoid the whole final variable
    versus read-only attributes problem.
    //GLOBAL VARIABLES EXPOSED AS PUBLIC PROPERTIES
    public final class GlobalProperties
    public static int getTableSize();
    public static int getRowSize();
    Each "constant" should be a private static variable, and these methods simply return their values.
    The variables are initialized in a static initializer by accessing the db. Ok.
    You habe a table with one row containing as columns all the constants.
    A method readConstants() does a "select constant1, constant2, ... from const_table" and sets all the variables.
    The static initializer calls this method.
    Right?
    Ok, then you simply call readConstants() everytime you want to synchronize with the actual content of const_table.
    Was it this?

  • Using Static Variable against Context Attribute for Holding IWDView

    Dear Friends,
    I have a method which is in another DC which has a parameter of the type IWDView. In my view, I will have an action which will call the method in another component by passing the value for the view parameter. Here, I can achieve this in 2 types. One is - I declare a static variable and assign the wdDoModifyView's view as parameter value and I can pass this variable as parameter whenever calling that method or the second way - create an attribute and assign the same wdDoModifyView's view parameter as its value. Whenever I call this method, I can pass this attribute as parameter. What is the difference between these two types of holding the value since I am storing the same value i.e., wdDoModifyView's view parameter. But when I trigger the action from different user sessions, the first type of code (using static variable) prints the same value in both the sessions for view.hashCode() and View.toString(), but the same is printing the different values when I pass the attribute which holds the view parameter.
    Clarification on this is highly appreciated
    The problem I face is when I use static variable to get the view instance and export the data using the UI element's id, the data belonging to different user sessions is mixed up where as when I use Context Attribute, the same problem doesn't arise. I want to know the reason why it is so. Is there any other place or way where I can get the current view instance of each session instead of wdDoModifyView?

    Hi Sujai ,
    As you have specified the problem that we face when we use  static attributes, when end users are using the application .
    Static means i  have n number of objects but the static variable value will remain same every where.
    when it is context attribute for every object i.e nth object you have a nth context attribute i mean nth copy of the context attribute.
    so every user has a unique Iview parameter , when context is used and
    when static is used  , assume you have userA , his iview is set this intially  and u have another user B , when he is using  , since the variable is static and when you access this variable you will get the value of userA.
    Regards
    Govardan Raj

  • Non-static variable Help needed

    Hi, I am creating a multi threaded web server but get the following error
    non-static variable this cannot be referenced from a static context
    HttpRequest request = new HttpRequest(connectionSocket);
    Please could someone help.
    Many Thanks
    import java.io.* ;
    import java.net.* ;
    import java.util.* ;
    public final class MultiWebServer
    public static void main(String argv[]) throws Exception
         // Set the port number.
         int port = 6789;
    // Establish the listen socket.
                   String fileName;
                   ServerSocket listenSocket = new ServerSocket(port);
    // Process HTTP service requests in an infinite loop.
    while (true) {
         // Listen for a TCP connection request.
         Socket connectionSocket = listenSocket.accept();
    // Construct an object to process the HTTP request message.
    HttpRequest request = new HttpRequest(connectionSocket);
    // Create a new thread to process the request.
    Thread thread = new Thread(request);
    // Start the thread.
    thread.start();
    final class HttpRequest implements Runnable
         final static String CRLF = "\r\n";
         Socket socket;
    String requestMessageLine;
    String fileName;
    Date todaysDate;
         // Constructor
         public HttpRequest(Socket socket) throws Exception
              this.socket = socket;
              socket = null;
    // Implement the run() method of the Runnable interface.
    public void run()
         try {
              processRequest();
         } catch (Exception e) {
              System.out.println(e);
    private void processRequest() throws Exception
         // Get a reference to the socket's input and output streams.
         //InputStream is = new InputStream(socket.getInputStream());
         //DataOutputStream os = new DataOutputStream(socket.getOutputStream());
    BufferedReader inFromClient =
                        new BufferedReader(new InputStreamReader(
                             socket.getInputStream()));
                   DataOutputStream outToClient =
                        new DataOutputStream(
                             socket.getOutputStream());
         // Set up input stream filters.
         requestMessageLine = inFromClient.readLine();
         //BufferedReader br = null;
         // Get the request line of the HTTP request message.
    String requestLine = null;
    // Display the request line.
    System.out.println();
    System.out.println(requestLine);
    StringTokenizer tokenizedLine =
                             new StringTokenizer(requestMessageLine);
                   if (tokenizedLine.nextToken().equals("GET"))
                        fileName = tokenizedLine.nextToken();
                        if ( fileName.startsWith("/")==true )
                             fileName = fileName.substring(1);
    File file = new File(fileName);
                        int numOfBytes = (int)file.length();
                        FileInputStream inFile = new FileInputStream(fileName);
                        byte[] fileInBytes = new byte[numOfBytes];
                        inFile.read(fileInBytes);
                        /* Send the HTTP header */
                        outToClient.writeBytes("HTTP/1.1 200 Document Follows\r\n");
                        if (fileName.endsWith(".jpg"))
                             outToClient.writeBytes("Content-Type: image/jpeg\r\n");
                        if (fileName.endsWith(".jpeg"))
                             outToClient.writeBytes("Content-Type: image/jpeg\r\n");
                        if (fileName.endsWith(".gif"))
                             outToClient.writeBytes("Content-Type: image/gif\r\n");
                        if (fileName.endsWith(".html"))
                             outToClient.writeBytes("Content-Type: text/html\r\n");
                        if (fileName.endsWith(".htm"))
                             outToClient.writeBytes("Content-Type: text/html\r\n");
                        outToClient.writeBytes("Content-Length: " + numOfBytes + "\r\n");
                        outToClient.writeBytes("\r\n");
                        /* Now send the actual data */
                        outToClient.write(fileInBytes, 0, numOfBytes);
                        socket.close();
                   else
                   System.out.println("Bad Request Message");
                   todaysDate = new Date();          
                   try {
                        FileInputStream inlog = new FileInputStream("log.txt");
                        System.out.println(requestMessageLine + " " + todaysDate );
                        FileOutputStream log = new FileOutputStream("log.txt", true);
                        PrintStream myOutput = new PrintStream(log);
                        myOutput.println("FILE -> " + requestMessageLine + " DATE/TIME -> " + todaysDate);
                   catch (IOException e) {
                   System.out.println("Error -> " + e);
                   System.exit(1);
    socket.close();

    import java.io.* ;
    import java.net.* ;
    import java.util.* ;
    public final class MultiWebServer
    public MultiWebServer(){
    try{
    // Set the port number.
    int port=6789;
    // Establish the listen socket.
    String fileName;
    ServerSocket listenSocket=new ServerSocket(port);
    // Process HTTP service requests in an infinite loop.
    while(true){
    // Listen for a TCP connection request.
    Socket connectionSocket=listenSocket.accept();
    // Construct an object to process the HTTP request message.
    HttpRequest request=new HttpRequest(connectionSocket);
    // Create a new thread to process the request.
    Thread thread=new Thread(request);
    // Start the thread.
    thread.start();
    }catch(IOException ioe){
    }catch(Exception e){
    public static void main(String argv[]) throws Exception
    new MultiWebServer();
    final class HttpRequest implements Runnable
    final static String CRLF = "\r\n";
    Socket socket;
    String requestMessageLine;
    String fileName;
    Date todaysDate;
    // Constructor
    public HttpRequest(Socket socket) throws Exception
    this.socket = socket;
    socket = null;
    // Implement the run() method of the Runnable interface.
    public void run()
    try {
    processRequest();
    } catch (Exception e) {
    System.out.println(e);
    private void processRequest() throws Exception
    // Get a reference to the socket's input and output streams.
    //InputStream is = new InputStream(socket.getInputStream());
    //DataOutputStream os = new DataOutputStream(socket.getOutputStream());
    BufferedReader inFromClient =
    new BufferedReader(new InputStreamReader(
    socket.getInputStream()));
    DataOutputStream outToClient =
    new DataOutputStream(
    socket.getOutputStream());
    // Set up input stream filters.
    requestMessageLine = inFromClient.readLine();
    //BufferedReader br = null;
    // Get the request line of the HTTP request message.
    String requestLine = null;
    // Display the request line.
    System.out.println();
    System.out.println(requestLine);
    StringTokenizer tokenizedLine =
    new StringTokenizer(requestMessageLine);
    if (tokenizedLine.nextToken().equals("GET"))
    fileName = tokenizedLine.nextToken();
    if ( fileName.startsWith("/")==true )
    fileName = fileName.substring(1);
    File file = new File(fileName);
    int numOfBytes = (int)file.length();
    FileInputStream inFile = new FileInputStream(fileName);
    byte[] fileInBytes = new byte[numOfBytes];
    inFile.read(fileInBytes);
    /* Send the HTTP header */
    outToClient.writeBytes("HTTP/1.1 200 Document Follows\r\n");
    if (fileName.endsWith(".jpg"))
    outToClient.writeBytes("Content-Type: image/jpeg\r\n");
    if (fileName.endsWith(".jpeg"))
    outToClient.writeBytes("Content-Type: image/jpeg\r\n");
    if (fileName.endsWith(".gif"))
    outToClient.writeBytes("Content-Type: image/gif\r\n");
    if (fileName.endsWith(".html"))
    outToClient.writeBytes("Content-Type: text/html\r\n");
    if (fileName.endsWith(".htm"))
    outToClient.writeBytes("Content-Type: text/html\r\n");
    outToClient.writeBytes("Content-Length: " + numOfBytes + "\r\n");
    outToClient.writeBytes("\r\n");
    /* Now send the actual data */
    outToClient.write(fileInBytes, 0, numOfBytes);
    socket.close();
    else
    System.out.println("Bad Request Message");
    todaysDate = new Date();
    try {
    FileInputStream inlog = new FileInputStream("log.txt");
    System.out.println(requestMessageLine + " " + todaysDate );
    FileOutputStream log = new FileOutputStream("log.txt", true);
    PrintStream myOutput = new PrintStream(log);
    myOutput.println("FILE -> " + requestMessageLine + " DATE/TIME -> " + todaysDate);
    catch (IOException e) {
    System.out.println("Error -> " + e);
    System.exit(1);
    socket.close();

  • Non-static variable being used in static context

    I am currently attempting to write a basic user login system using basic applets. I have two JTextFields named "userText" and "passText".
    What i am attempting to do is use the ".getText()" method to get the text out of the JTextField and verifying the string against a string already in a file using the bufferedReader, etc.
    However when i try to compare the string in the file with the one in the text field using the following code:
    if ((line.compareTo(username)) == 0)
    i get the following error...
    "non-static variable being used in a static context"
    Any ideas?

    The static method doesn't know about instances of the class instead you pass the instance to the method:
    static public void myMethod(MyClass instance, String var) {
      if(instance.line.compareTo(var))
    And then the call would be:
    MyClass.myMethod(anInstance, userName);

  • How to give different value to a static variable???

    Hi all:
    Is there any solution to set different values to a static variable???I had try two ways but all have errors!
    1.Way_1
    protected String tmp=null;
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    tmp = "string1";
    else if (sayorpress==1)
    tmp = "string2";
    protected static String RESOURCE_STRING = tmp; <---error
    Error:non-static variable tmp cannot be referenced from a static context
    2.Way_2
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    protected static String RESOURCE_STRING = "string1"; <---error
    else if (sayorpress==1)
    protected static String RESOURCE_STRING = "string2"; <---error
    Error:illegal start of expression at
    not an expression statement at
    Thank you very mich!!!

    Try this:
    protected static String RESOURCE_STRING = null;
    protected void initSituation(int sayorpress)
    if (sayorpress==0)
    yourClass.RESOURCE_STRING = "string1";
    else if (sayorpress==1)
    yourClass.RESOURCE_STRING = "string2";
    You cannot declare a static variable inside a method. But you can access a static variable thorugh your class.

  • Runtime error in linking with static variables....

    Hi,
    I am building a shared library which includes a compiled object generated from a class containing the static variables only and also I have another version of same class with same & some new static variables in it and using that to generate another shared library. Now when I tried to run a program
    which links with both the library it core dumps when it tries to return from the program i.e when it finishes.
    Can someone please help me explain why my program is behaving like that?? Can duplicate inculsion of static variables in different scope can cause problem ?? How can this be avoided ?
    Also please be advised that the class with static variables gets generated at the compile time using a script which uses a DTD whose version (specification) can be different in both the libraries therefore I can't just seperate the common stuff into one class and specific into another.
    Thanks.
    Rajeev.

    Not to worry...found the answer in another post. Seems like patches need to applied to the OS.

  • Main method hangs setting static variable

    I have a very annoying intermittent problem. Once in a while (roughly 1 out of 30 times), my app hangs in the main method when assigning a value to a static variable.
    public static void main(String[] args) {
    //read args
    //do some very trivial stuff (never hangs here)
    someOtherNonStaticClass.aStaticInt = 100;//once in a while it hangs here???
    }I have tried setting "-Dsun.java2d.noddraw=true" but this hasnt helped. I have tried using JRE 1.4.1 and 1.4.2 and they both have this problem. Some machines seem to be worse than others but this may just be chance.
    When the app hangs, it appears in task manager as a javaw.exe process, but the app itself doesnt appear.
    Does anyone have any ideas or suggestions for me to try? Its pretty annoying not have a stack trace to work with.

    I have tried setting "-Dsun.java2d.noddraw=true" butWhy should it?
    this hasnt helped. I have tried using JRE 1.4.1 and
    1.4.2 and they both have this problem. Some machines
    seem to be worse than others but this may just be
    chance.
    When the app hangs, it appears in task manager as a
    javaw.exe process, but the app itself doesnt appear.That's normal. All Java apps would appear as javaw.exe. Because the JVM has the process.
    Does anyone have any ideas or suggestions for me to
    try? Yes. Stop accessing fields of another class. It's bad design to begin with, and it looks to me like you're breaking something someplace else by setting that value to 100 right then.

  • To use a static variable in another class,but report NullPointerException

    when TableMain is running,I run testRecord so that let TableMain add a occur informatin and
    happened time in a row in TableMain,but when I run testRecord,java report a NullPointerException and I dont know how to solve this problem,thanks for helping me to check my code;(error report info is in end)
    import java.awt.event.*;
    import javax.swing.table.*;
    import java.io.*;
    public class TableMain extends JFrame{
    JTable table;
    static OwnModel model;
    String[] columnHeader={"occur","time"};
    class OwnModel extends DefaultTableModel{
    public OwnModel(Object[] columnNames,int numRows){
    super(columnNames,numRows);
    public boolean isCellEditable(int row,int column){
    return false;
    public TableMain(){
    model=new OwnModel(columnHeader,0);
    table=new JTable(model);
    JScrollPane scroll=new JScrollPane(table);
    JButton save=new JButton("save record");
    JButton delete=new JButton("delete record");
    JPanel buttons=new JPanel();
    buttons.add(save);
    buttons.add(delete);
    JLabel sign=new JLabel("occur record");
    Container cp=getContentPane();
    cp.add(BorderLayout.NORTH,sign);
    cp.add(BorderLayout.CENTER,scroll);
    cp.add(BorderLayout.SOUTH,buttons);
    this.setSize(300,500);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public static void main(String[] args){
    new TableMain();
    import java.util.Vector;
    import java.util.Calendar;
    import java.text.SimpleDateFormat;
    public class testRecord{
    public static void main(String[] args){
    SimpleDateFormat simpledf=new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
    String tableName="friends";
    Calendar occurtime=Calendar.getInstance();
    Vector record=new Vector();
    record.add("send 'desc' sql, "+"operated table is :"+tableName);
    record.add(simpledf.format(occurtime.getTime()));
    System.out.println("model is "+Guide.model);
    System.out.println("record is "+record);
    Guide.model.addRow(record);
    error report:
    model is null
    record is [send 'desc' sql,operated table is :friends, 2004/05/26 11:39:03]
    Exception in thread "main" java.lang.NullPointerException
    at testRecord.main(testRecord.java:14)

    but I just use this constructor once,never use twice
    with same jvm;I thinks my idea is not too very badIt's a public constructor (if I'm looking in the right
    place) - it could be called from anywhere. To
    intialize a static variable outside the declaration,
    use a static initializer:private static String whatever;static {
    whatever = "whatever";
    }Or simply (in this case):private static String whatever = "whatever";

Maybe you are looking for

  • USB Install

    OK, so I installed Arch onto my 4gb USB Stick, as per usual procedures (I also read through the "Installing Arch Linux on a USB Key" wiki article. The problem is that everything worked fine, then I did some updates, which seem to have broken the inst

  • HDCP problems

    Updated Apple TV software today and am having problems with HDCP. Now I'm constantly getting this message "This content requires HDCP for playback. HDCP isn't supported by your HDMI connection." I've followed all the advice here http://support.apple.

  • Issue with date datatype

    Hi Team I am very much confused in the date related coversion for example if i query select name, hire_date from employee the o/p looks like this suresh 5/24/1999 but if i need to display like 24-may-1999 what i should use and please help me in under

  • I've bought a Macbook Pro yesterday, but there is no mac os x lion on it. Now my question is where can I download it for free?

    I've bought a Macbook Pro yesterday, but there is no mac os xlion on it. Now my question is where can I download it for free?

  • Vista and mic problems

    Vista and mic problemsW I'm sure this is the same problem as most. I did some searching and couldn't come up with a clear cut answer. I run Vista Ultimate 64bit with an Elite Pro card. Just installed Vista as a matter of fact. I am also using the Fat