Search Results

Search found 15797 results on 632 pages for 'session variables'.

Page 146/632 | < Previous Page | 142 143 144 145 146 147 148 149 150 151 152 153  | Next Page >

  • Java - How to declare table[i][j] elements as instance variables?

    - by JDelage
    All, I am trying to code a Connect4 game. For this, I have created a P4Game class and a P4Board class which represents the i X j dimensions of the Connect4 board. In P4Game, I have the following: public class P4Game{ //INSTANCE VARIABLES private int nbLines; private int nbColumns; private P4Board [][] position; //CONSTRUCTOR public P4Game(int nbLines, int nbColumns){ this.nbColumns = nbColumns; this.nbLines = nbLines; P4Board [][] position = new P4Board [nbLines][nbColumns]; //Creates the table to receive the instances of the P4Board object.*/ for (int i=0; i<nbLines; i++){ for (int j=0; j<nbColumns; j++){ this.position[i][j] = new P4Board(i,j); //Meant to create each object at (line=i, column=j) } } } This causes a NullPointerException in the nested loops where I mention this.position[i][j]. I reference those objects in other methods of this class so I need them to be instance variables. I suppose the exception is due to the fact that I have not listed the table element position[i][j] as an instance variable at the beginning of the class. my question to people here is (1) is my assumption correct, and if so (2) what would be the syntax to declare instance variables of this form? Thank you all for your help with what I realize is a very basic question. Hopefully it will also benefit other newbies. Cheers, JDelage

    Read the article

  • What does it mean to say "Instance variables are not over-rided" in java?

    - by Ankit
    I am aware of the concept called field hiding in java. But still I am having a confusion in relation to instance variable being not over-ridden. According to my present knowledge, overriding a method of super-class means that the JVM will call the sub-class's over-ridden method though the super-class's method is available to the sub-class. And I read the similar thing for field hiding via the link:- Hiding Fields So, in any case we are over-ridding the instance if we change the values of the inherited instance variable in the sub-class. I am confused please help. I am using the following super-class:- public class Animal{ File picture; String food; int hunger; int width, height; int xcoord, ycoord; public void makeNoise(){ ......... } public void eat(){ ............. } public void sleep(){ .......... } public void roam(){ ............. } } It has sub-classes like Tiger, cat, dog,hippo etc. The sub-classes over-ride the makeNoise(), eat and roam() method. But each sub-class also uses a different set of values for instance variables. So as per my confusion, I am kind-of overriding all the instance variables and 3 methods of the super-class Animal; and I still have the super-class instance variables available to the sub-class with the use of the super keyword.

    Read the article

  • is using private shared objects/variables on class level harmful ?

    - by haansi
    Hello, Thanks for your attention and time. I need your opinion on an basic architectural issue please. In page behind classes I am using a private and shared object and variables (list or just client or simplay int id) to temporary hold data coming from database or class library. This object is used temporarily to catch data and than to return, pass to some function or binding a control. 1st: Can this approach harm any way ? I couldn't analyze it but a thought was using such shared variables may replace data in it when multiple users may be sending request at a time? 2nd: Please comment also on using such variables in BLL (to hold data coming from DAL/database). In this example every time new object of BLL class will be made. Here is sample code: public class ClientManager { Client objclient = new Client(); //Used in 1st and 2nd method List<Client> clientlist = new List<Client>();// used in 3rd and 4th method ClientRepository objclientRep = new ClientRepository(); public List<Client> GetClients() { return clientlist = objclientRep.GetClients(); } public List<Client> SearchClients(string Keyword) { return clientlist = objclientRep.SearchClients(Keyword); } public Client GetaClient(int ClientId) { return objclient = objclientRep.GetaClient(ClientId); } public Client GetClientDetailForConfirmOrder(int UserId) { return objclientRep.GetClientDetailForConfirmOrder(UserId); } } I am really thankful to you for sparing time and paying kind attention.

    Read the article

  • When should we use private variables and when should we use properties.

    - by Shantanu Gupta
    In most of the cases we usually creates a private variable and its corresponding public properties and uses them for performing our functionalities. Everyone has different approach like some ppl uses properties every where and some uses private variables within a same class as they are private and opens it to be used by external environment by using properties. Suppose I takes a scenario say insertion in a database. I creates some parameters that need to be initialized. I creates 10 private variables and their corresp public properties which are given as private string name; public string Name { get{return name;} set{name=value;} } and so on. In these cases what should be used internally variables or properties. And in those cases like public string Name { get{return name;} set{name=value>5?5:0;} //or any action can be done. this is just an eg. } In such cases what should be done.

    Read the article

  • How can I create global context variables in JBOSS?

    - by NobodyMan
    This is a follow-up to a question I posted a while back: "Can I use a single WAR in multiple environments?". I was able to create a single-war solution in Tomcat, but now we are migrating our app to JBoss 4.2 and I can't figure out how to set up global environment variables. In Tomcat 6 this was pretty straightforward: I simply put the following snippet in tomcat/conf/Catalina/myappname.xml: <Context ...> <Environment name="TARGET_ENV" value="DEV" type="java.lang.String" override="false"/> </Context> Then in my app I was able to resolve the environment name with the following: Context context = (Context) InitialContext().lookup("java:comp/env"); String targetEnvironment = (String) context.lookup("TARGET_ENV"); The problem is that I can't find out where/how to place global variables in JBoss. I've tried putting the <Environment> tag in the following files to no avail: server/all/deploy/jboss-web.deployer/context.xml server/default/deploy/jboss-web.deployer/context.xml I know that I can put environment variables in my app's web.xml but that defeats the purpose of having a unified war - I'd still need custom .war's for dev, qa and prod. I'm a JBoss newbie so if there's any additional information that would help just let me know and I'll append to this question. Many thanks! --N

    Read the article

  • Why aren't variables declared in "try" in scope in "catch" or "finally"?

    - by Jon Schneider
    In C# and in Java (and possibly other languages as well), variables declared in a "try" block are not in scope in the corresponding "catch" or "finally" blocks. For example, the following code does not compile: try { String s = "test"; // (more code...) } catch { Console.Out.WriteLine(s); //Java fans: think "System.out.println" here instead } In this code, a compile-time error occurs on the reference to s in the catch block, because s is only in scope in the try block. (In Java, the compile error is "s cannot be resolved"; in C#, it's "The name 's' does not exist in the current context".) The general solution to this issue seems to be to instead declare variables just before the try block, instead of within the try block: String s; try { s = "test"; // (more code...) } catch { Console.Out.WriteLine(s); //Java fans: think "System.out.println" here instead } However, at least to me, (1) this feels like a clunky solution, and (2) it results in the variables having a larger scope than the programmer intended (the entire remainder of the method, instead of only in the context of the try-catch-finally). My question is, what were/are the rationale(s) behind this language design decision (in Java, in C#, and/or in any other applicable languages)?

    Read the article

  • When should we use private variables and when should we use properties. Do Backing Fields should be

    - by Shantanu Gupta
    In most of the cases we usually creates a private variable and its corresponding public properties and uses them for performing our functionalities. Everyone has different approach like some people uses properties every where and some uses private variables within a same class as they are private and opens it to be used by external environment by using properties. Suppose I takes a scenario say insertion in a database. I creates some parameters that need to be initialized. I creates 10 private variables and their corresp public properties which are given as private string name; public string Name { get{return name;} set{name=value;} } and so on. In these cases mentioned above, what should be used internal variables or properties. And in those cases like public string Name { get{return name;} set{name=value>5?5:0;} //or any action can be done. this is just an eg. } In such cases what should be done.

    Read the article

  • How to set a PHP session variable through linux command prompt?

    - by Sev
    How to set a PHP session variable through linux command prompt? Clarification So, as you know we can set session variables in PHP using $_SESSION global variable when coding. I would like to know if there is a way to set this variable through php command prompt? For example, in the code, if I can set $_SESSION['temp'] = "whatever" Is there a way to set the same variable through command prompt PHP?

    Read the article

  • Why do ASP.NET applications appear to be running in a terminal server session?

    - by Heinzi
    Running the following ASPX page (IIS 6, Server 2003 R2) <%@ Page Language="vb" AutoEventWireup="false" %> <% Response.Write("Am I running in a terminal server session: " & _ System.Windows.Forms.SystemInformation.TerminalServerSession) %> yields the following output: Am I running in a terminal server session: True Why? IIS is running as a service, not as a Terminal Services application... (BTW, according to Reflector, SystemInformation.TerminalServerSession is just a wrapper for GetSystemMetrics(SM_REMOTESESSION).)

    Read the article

  • Hibernate save() and transaction rollback

    - by Marco
    Hi, In Hibernate when i save() an object in a transaction, and then i rollback it, the saved object still remains in the DB. It's strange because this issue doesn't happen with the update() or delete() method, just with save(). Here is the code i'm using: DbEntity dbEntity = getDbEntity(); HibernateUtil.beginTransaction(); Session session = HibernateUtil.getCurrentSession(); session.save(dbEntity); HibernateUtil.rollbackTransaction(); And here is the HibernateUtil class (just the involved functions, i guarantee the getSessionFactory() method works well - there is an Interceptor handler, but it doesn't matter now): private static final ThreadLocal<Session> threadSession = new ThreadLocal<Session>(); private static final ThreadLocal<Transaction> threadTransaction = new ThreadLocal<Transaction>(); /** * Retrieves the current Session local to the thread. * <p/> * If no Session is open, opens a new Session for the running thread. * * @return Session */ public static Session getCurrentSession() throws HibernateException { Session s = (Session) threadSession.get(); try { if (s == null) { log.debug("Opening new Session for this thread."); if (getInterceptor() != null) { log.debug("Using interceptor: " + getInterceptor().getClass()); s = getSessionFactory().openSession(getInterceptor()); } else { s = getSessionFactory().openSession(); } threadSession.set(s); } } catch (HibernateException ex) { throw new HibernateException(ex); } return s; } /** * Start a new database transaction. */ public static void beginTransaction() throws HibernateException { Transaction tx = (Transaction) threadTransaction.get(); try { if (tx == null) { log.debug("Starting new database transaction in this thread."); tx = getCurrentSession().beginTransaction(); threadTransaction.set(tx); } } catch (HibernateException ex) { throw new HibernateException(ex); } } /** * Rollback the database transaction. */ public static void rollbackTransaction() throws HibernateException { Transaction tx = (Transaction) threadTransaction.get(); try { threadTransaction.set(null); if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) { log.debug("Tyring to rollback database transaction of this thread."); tx.rollback(); } } catch (HibernateException ex) { throw new HibernateException(ex); } finally { closeSession(); } } Thanks

    Read the article

  • How long do FireFox, Chrome, Safari, and Opera cache SSL/TLS session keys?

    - by MJ
    To try to use a reason SSL/TLS session key timeout on the server-side, I'd like to know how long popular browsers cache session keys on the client. Microsoft describes this information for Windows/IE here: http://technet.microsoft.com/en-us/library/cc776467(WS.10).aspx But, I haven't been able to find similar information for other popular browsers. Does anyone know? Thanks!

    Read the article

  • Why is hibernate open session in view considered a bad practice?

    - by HeDinges
    And what kind of alternative strategies do you use for avoiding LazyLoadExceptions? I do understand that open session in view has issues with: Layered applications running in different jvm's Transactions are committed only at the end, and most probably you would like the results before. But, if you know that your application is running on a single vm, why not ease your pain by using an open session in view strategy?

    Read the article

  • How do you get the language from a session in Joomla?

    - by Moak
    I have some code that sets the lang var to the site default language. $lg = &JFactory::getLanguage(); $lg = explode('-',$lg->_default); $dlg = $lg[0]; if(!JRequest::getWord('lang', false )) JRequest::setVar('lang', $dlg ); however before setting it to $dlg I would like to find out if the language is stored in the user information or session. Can someone tell me how to check the session for language information?

    Read the article

  • Is it okay to mix session data with form and querystring values in a custom model binder?

    - by Byron Sommardahl
    Working on a custom model binder in ASP.NET MVC 2. Most of the time I am binding data from typical form or querystring data. There are times that I end up letting the model binder bind part of an object and get the rest out of session at the controller action level. Does it make better sense to bind the entire object from the model binder (e.g. querystring, form, and session)?

    Read the article

  • asp.net mvc 2 multithread

    - by Chris Cap
    I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm expecting). I have a controller httppost action that processes credit cards. I'm setting a session variable on the server to let me know if a user has attempted to process a card. I clear that session variable when I'm done. I am doing some very quick posts to test the process and the session variable is coming back null everytime because I clear the session variable at the end of the process. I have some debug prints that show me that the all requests are processed synchronously. That is...the first attempt occurs, it fails, session variable is cleared, second attempt tries and fails and the variable is cleared, etc... My first thought was that this was a side effect of debugging and that it just lined requests up for debugging purposes using the local webserver. So I put it on a development server and the same thing is occurring. Multiple submits/posts are processed synchronously. I even put a System.Threading.Sleep in there to make sure it would stop right after I set the session variable and it still won't even START the second request until the first is done. Has anyone else seen this behavior? My understanding was that a worker process was spawned for each request and that these actions could happen asychronously. Here's some psuedo code if (Session["CardCharged"] != null) return RedirectToAction("Index", "Problem"); Session["CardCharged"] = false; //starting the process System.Threading.Thread.Sleep(10000); //charge card here if (!providerResponse.IsApproved) { System.Diagnostics.Debug.WriteLine("failed"); Session["CardCharged"] = null; //have to allow them to charge again since this failed return View(myModel); } Session["CardCharged"] = true; return RedirectToAction("Index", "OrderComplete"); I should mention that my code ALWAYS fails the credit card check for testing purposes. I'm trying to test the situation where processing is STILL occurring and redirect the user elsewhere. I have set a dummy session variable elsewhere to assure that the session id "sticks". So I know the session id is the same for each request. Thanks

    Read the article

  • Can I use Upstart to start a script which requires the user's X session?

    - by ledneb
    I wrote a script which greps through the output of synclient to determine whether a laptop's touchpad has miraculously turned itself off (Ubuntu seems to /love/ doing this recently) and, if so, turns it back on. The script is something like this: #!/bin/bash while true ; do if [ `synclient | grep -e"TouchpadOff[\s]*1" | wc -l` -ge 1 ] ; then synclient TouchpadOff=0 fi sleep(3) done (I don't have the laptop to hand right now but you get the point! I will update later when I'm at my laptop if that's incorrect) So I tried running this as an upstart script so my touchpad can heal itself without any interaction. But it seems synclient doesn't find the current user's X session when my script is upstart'ed. I tried running it by using something like su -c myscript.sh ledneb in my script stanza, but to no avail. Should I be looking in the direction of /etc/X11/xinit/xinitrc rather than upstart? Is there a proper way to have this script run in the context of the current (or even a hard-coded) user's x session?

    Read the article

  • Handling Session timeout in asp.net so all info. is aviable before create/update record

    - by Jack
    I'm having problem with some data missing in the record. I've a ASP.net web app that take some information from the user then create a record on the database. It's your typical CRUD app but I've noticed lately that some record are missing couple fields. Where they are null value. I think it might have been an Session issue. What's the best way to handle session time out in a typical CRUD app? Thanks

    Read the article

  • Print over the internet from a remote linux session locally (on a Windows 7 machine) to the shared printers?

    - by obeliksz
    I'm trying to use a linux virtual machine as a file server for windows clients. I have successfully implemented remote file sharing (samba+ssh) with which I am able to print locally with a little program that I made for this purpose (jetforms style)... but I would like to hear about a somewhat more direct approach. How can I attach the printers to the server, so that I can for example open a file on the remote session and in the print dialogbox I would see my local printers (on the machine from which I have established a remote session)? I guess there should be some kind of putty tunneling, but dont know how. I have a windows 7 machine locally; there is a CentOS 6 VM over the internet. It has ssh, cups, and samba. I have found a question which asks the opposite: there is a windows based server to connect form linux but that windows has a domain, mine is just a simple windows workstation that is behind NAT and has a dynamic IP. That question is: Print from Linux to Windows networked printer.

    Read the article

< Previous Page | 142 143 144 145 146 147 148 149 150 151 152 153  | Next Page >