Search Results

Search found 985 results on 40 pages for 'instantiate'.

Page 19/40 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • Is there anything wrong with my Factory class?

    - by Alex
    class PieceFactory { @SuppressWarnings("rawtypes") public Piece createPiece(String pieceType) throws Throwable{ Class pieceClass = Class.forName(pieceType); Piece piece = (Piece) pieceClass.newInstance(); return piece; } } I'm not all used to handling exceptions yet therefore I'm just throwing them, but everywhere I use a method that uses this factory it tells me I have to throw exceptions like throwable. For example, in one of my classes I have a method that instantiates a lot of objects using the method that uses the factory. I can use the method in that class by just throwing the exception, however it won't work if I try to pass a reference to that class to another class and then use the method from there. Then it forces me to try catch the exception. I probably don't need a factory but it seemed interesting and I'd like to try to use patterns. The reason I created the factory was that I have 6 subclasses of Piece and I wan't to use a method to instantiate them by passing the type of subclass I want as an argument to the method.

    Read the article

  • AS3 Memory management when instantiating extended classes

    - by araid
    I'm developing an AS3 application which has some memory leaks I can't find, so I'd like to ask some newbie questions about memory management. Imagine I have a class named BaseClass, and some classes that extend this one, such as ClassA, ClassB, etc. I declare a variable: myBaseClass:BaseClass = new ClassA(); After a while, I use it to instantiate a new object: myBaseClass = new ClassB(); some time after myBaseClass = new ClassC(); and the same thing keeps happening every x millis, triggered by a timer. Is there any memory problem here? Are the unused instances correctly deleted by the garbage collector? Thanks!

    Read the article

  • Setting the initial value of a property when using DataContractSerializer

    - by Eric
    If I am serializing and later deserializing a class using DataContractSerializer how can I control the initial values of properties that were not serialized? Consider the Person class below. Its data contract is set to serialize the FirstName and LastName properties but not the IsNew property. I want IsNew to initialize to TRUE whether a new Person is being instantiate as a new instance or being deserialized from a file. This is easy to do through the constructor, but as I understand it DataContractSerializer does not call the constructor as they could require parameters. [DataContract(Name="Person")] public class Person { [DataMember(Name="FirstName")] public string FirstName { get; set; } [DataMember(Name = "LastName")] public string LastName { get; set; } public bool IsNew { get; set; } public Person(string first, string last) { this.FirstName = first; this.LastName = last; this.IsNew = true; } }

    Read the article

  • How to pass interface type/GUID reference to an automation method in Delphi

    - by Alan Clark
    In Delphi you can pass class references around to compare the types of objects, and to instantiate them. Can you do the same with interface references being passed to a COM automation server? For example, you can define a method taking a GUID parameter using the type library editor: function ChildNodesOfType(NodeType: TGUID): IMBNode; safecall; In this function I would like to return automation types that support the interface specified by NodeType, e.g. if Supports(SomeNode, NodeType) then result := SomeNode; But the Supports call always fails, I tried passing in the Guids defined in the type library but none of the different types (Ixxx, Class_xxxx, IId_Ixxxx) seem to work.

    Read the article

  • Why element creation requires the document object in DOM?

    - by maayank
    As noted by others, in Java, with the default W3C DOM libraries, one is required to use the Document object a factory to elements, i.e.: import org.w3c.dom.Document; import org.w3c.dom.Element; Document d; Element e; e = d.createElement("tag"); Why is that necessary? Why conceptually a method can't create an XML element without knowing all of the target document? Why I can't just instantiate using 'new' or something to that effect?

    Read the article

  • Java Spring 3.0 MVC Annotation vs COC. Whats the preferred method in the Java community?

    - by Athens
    I am using Spring's MVC framework for an application I'm hosting on Google's App Engine. So far, my controllers are registered via the @Controller annotation; however, prior to getting into Spring, I evaluated ASP.net MVC 2 which requires no configuration and is based on convention. Is convention over configuration (COC) the current and preferred method in the Java community to implement MVC with Spring. Also, this may be a result of my limited knowledge so far but i noticed that i could only instantiate my Controllers the required constuctor injection if i use the COC method via the ControllerClassNameHandlerMapping. For instance the following controller bean config will fail if i use the defaultannotationhandlermapping. <bean id="c" class="com.domain.TestController"> <constructor-arg ref="service" /> </bean> <bean id="service" class="com.domain.Service" /> My com.domain.TestController controller works fine if i use ControllerClassNameHandlerMapping/COC but it results in an error when i use defaultannotationhandlermapping/Annotations.

    Read the article

  • What is the equivalent to IScriptControl for Web.UI.Page?

    - by Jeff Dege
    We've been using IScriptControl to tie javascript objects to our UserControls and ServerControls, and it's worked fine. The problem is that ASP.NET seems to provide no method to tie a javascript object to a Page. Up to now, we've been putting plain functions in the global namespace, but I am developing a serious allergy to that practice. It'd be easy enough to wrap our functions into a javascript class, and to include the javascript file on the page, but how to instantiate the object, how to reference it from callback events, and how to pass data to it from the code-behind, I haven't figured out. Or rather, the methods we've been using up to now (hidden fields, emitted javascript strings, etc.), really bug me. Anyone have better ideas?

    Read the article

  • Asp .Net MVC Viewmodel should be class or struct?

    - by Jonas Everest
    Hey guys, I have just been thinking about the concept of view model object we create in asp.net MVC. Our purpose is to instantiate it and pass it from controller to view and view read it and display the data. Those view model are usually instantiated through constructor. We won't need to initialize the members, we may not need to redefine/override parameterless constructor and we don't need inheritance feature there. So, why don't we use struct type for our view model instead of class. It will enhance the performance.

    Read the article

  • Inheriting the main method

    - by Eric
    I want to define a base class that defines a main method that instantiates the class, and runs a method. There are a couple of problems though. Here is the base class: public abstract class Strategy { abstract void execute(SoccerRobot robot); public static void main(String args) { Strategy s = new /*Not sure what to put here*/(); s.execute(new SoccerRobot()) } } And here is an example derived class: public class UselessStrategy { void execute(SoccerRobot robot) { System.out.println("I'm useless") } } It defines a simple execute method, which should be called in a main method upon usage as a the main application. However, in order to do so, I need to instantiate the derived class from within the base class's main method. Which doesn't seem to be possible. I'd rather not have to repeat the main method for every derived class, as it feels somewhat unnessary. Is there a right way of doing this?

    Read the article

  • [C++] instantiating bitset using hex character.

    - by bndz
    Hey, I'm trying to figure out how to instantiate a 4 bit bitset based on a hex character. For instance, If I have a character with value 'F', I want to create a bitset of size 4 initialized to 1111 or if it is A, i want to initialize it to 1010. I could use a bunch of if statements like so: fn(char c) { bitset<4 temp; if(c == 'F') temp.set(); //... if(c == '9') { temp.set(1); temp.set(3); } //... } This isn't efficient, is there a way of easily converting the string to a decimal integer and constructing the bitset using the last 4 bits of the int? Thanks for any help.

    Read the article

  • Java: InitialContext.lookup(String) - what should the value o the parametr be?

    - by bguiz
    To instantiate a Stateful Session Bean inside of a JSP/ servlet, I am using: InitialContext ic = new InitialContext(); SomeStateful state = (SomeStateful) ic.lookup("java:comp/env/SomeStatefulBean"); Trial and error had me prefix the name of my EJB with java:comp/env/, so the above works (on Glassfish 2.1). However I want to know what the proper way to obtain this prefix is. Is there a CLI tool or function somewhere in the admin panel that will allow we to examine/ alter this? Is this platform/ application server dependant? Is there a setting within my ear, EJB-jar or war which I can examine or alter for this? (Forgive the beginner question) Thanks!

    Read the article

  • Static DB Provider in ASP.NET MVC Causing Memory Leak

    - by user364685
    Hi, I have got an app I'm going to write in ASP.NET MVC and I want to create a DatabaseFactory object something like this:- public class DatabaseFactory { private string dbConn get { return <gets from config file>; } public IDatabaseTableObject GetDatabaseTable() { IDatabaseTableObject databaseTableObject = new SQLDatabaseObject(dbConn); return databaseTableObject; } } and this works fine, but I obviously have to instantiate the DatabaseFactory in every controller that needs it. If I made this static, so I could, in theory just call DatabaseFactory.GetDatabaseTable() it would cause a memory leak, wouldn't it?

    Read the article

  • MySQL or SQL Server

    - by user203708
    I'm creating an application that I want to run on either MySQL or SQL Server (not both at the same time) I've created two PHP classes DatabaseMySQL and DatabaseSQLSVR and I'd like my application to know which database class to use based on a constant set up at install. define(DB_TYPE, "mysql"); // or "sqlsrv" I'm trying to think of the best way to handle this. My thought is to do an "if else" wherever I instantiate the database: $db = (DB_TYPE == "mysql") ? new DatabaseMySQL : new DatabaseSQLSVR; I know there has to be a better way of doing this though. Suppose I want to add a third database type later; I'll have to go and redo all my code. Yuk!! Any help would be much appreciated. Thank

    Read the article

  • C# method generic params parameter bug?

    - by Mike M
    Hey, I appears to me as though there is a bug/inconsistency in the C# compiler. This works fine (first method gets called): public void SomeMethod(string message, object data); public void SomeMethod(string message, params object[] data); // .... SomeMethod("woohoo", item); Yet this causes "The call is ambiguous between the following methods" error: public void SomeMethod(string message, T data); public void SomeMethod(string message, params T[] data); // .... SomeMethod("woohoo", (T)item); I could just use the dump the first method entirely, but since this is a very performance sensitive library and the first method will be used about 75% of the time, I would rather not always wrap things in an array and instantiate an iterator to go over a foreach if there is only one item. Splitting into different named methods would be messy at best IMO. Thoughts?

    Read the article

  • strategy for observer pattern?

    - by fayer
    I want to use observer pattern for a logging system. We have got logObservers and logObservables. The class that will have to log something will implement iLogObservable and include these methods: private $logObservers = array(); public function addLogObserver($logObserver) { $this->logObservers[] = $logObserver; } public function removeLogObserver($logObserver) { $this->logObservers[] = $logObserver; } public function write($type, $message) { foreach($this->logObservers as $logObserver) { $logObserver->log($level, $message); ; } } Then I noticed, that a lot of classes that will use logging will have these methods and I have to copy paste. So isn't it better to have these methods in a class I call LogObservable or just Log and then use strategy (instantiate this class inside all classes that will have to log). When I change the methods in Log, all logObservables will be affected. However, I have not seen anyone use observer pattern with strategy pattern yet, but it seems to be very efficient and remove the duplications. What do you think?

    Read the article

  • InvalidOperationException when using soap client

    - by codymanix
    I've added as wsdl file using the add servece reference dialog in vs2008. MyService serviceproxy = new MyService(); When I instantiate the service proxy, I get an InvalidOperationException with the following text (translated from german): Could not find default endpoint element to the contract "ServiceName.ServiceInterface" in the service model refers client configuration section. This may be because: The application configuration file was not found or not an endpoint in the client element item is found, which corresponded to this contract. Where servicename is the name I give the service when I add it in vs2008 and ServiceInterface the interface which is automatically generated for it.

    Read the article

  • NSURL not instantiating properly

    - by taokakao
    Hi, I am new to IPhone developing. I have got very strange issue with NSURL which is driving me crazy. I want to instantiate NSURL object to use it in loading image. But instantiation never happens in proper way. It always says my url in invalid. Basically I use code like below: NSString *str = @"http://google.com"; NSURL *url = [NSURL URLWithString:str]; but I also have tried a lot of different modifications (with CFStringRef + CFURLCreateStringByAddingPercentEscapes and so on). All of them are not working for me. In debugger url is set to "Invalid". What it could be? I don't think this is algorithmic or environment issue. It could be about some settings? Have anyone any idea of what happens?

    Read the article

  • Can I Always debug multiple instances of a same object that is of type thread with GDB?

    - by yan bellavance
    program runs fine. When I put a breakpoint a segmentation fault is generated. Is it me or GDB? At run time this never happens and if I instantiate only one object then no problems. Im using QtCreator on ubuntu x86_64 karmic koala. UPDATE1: I have made a small program containing a simplified version of that class. You can download it at: example program simply put a breakpoint on the first line of the function called drawChart() and step into to see the segfault happen UPDATE2: This is another small program but it is practically the same as the mandlebrot example and it is still happening. You can diff it with mandlebrot to see the small difference. almost the same as mandlebrot example program

    Read the article

  • Can default Symfony form-save actions be used to post data via AJAX?

    - by Prasad
    I was playing around with Symfony, jQuery, jqGrid & AJAX. For each new post submission, I am doing the foll: adding a routing entry in routing.yml defining a new action in the Actions file for the module. THis reads params, assigns values & saves the object As in the case of jqGrid, the 'Add Row' form is not a Symfony form. Is there a way to fool Symfony and post data to the executeCreate action to store a new entry. If not, does Symfony provide a way to quickly generate web services for AJAX requests for each of the modules? Is this a sensible feature? What I am going to have to do other-wise, is to create routing create a new Action get all parameters instantiate object assign values & save Any help in doing this faster will be appreciated. Thanks in advance

    Read the article

  • Property in a Windows Forms form class only accessable after Load event

    - by Spooky2010
    I'm instantiating and calling Form B from Form A. FormB has some custom properties, to allow me to pass it things like sqlAdaptors and dataset instances. When i instantiate and show Form B from Form A as a dialog form with a Using statement, it all works fine, but i find the properties i pass are not available in Form B until after the form_load event has fired. I was under the impression the properties when passed to a instantiated class should be available from a constructor, but this is not the case. If it try to access the properties before the form load event i get a null reference exception. Is this correct behavior ?

    Read the article

  • declaring a 2D array of pointer objects

    - by Tyler Stennette
    I'm having a tough time figuring out how to instantiate a 2D array of pointer objects. Here is how I'm doing it: Pieces* chessBoard[9][9]; When I want to set it to an actual object pointer, I'm doing the following: chessBoard[1][1] = new Rook(p1Rook); Rook is a class that inherits attributes from the Pieces class and p1Rook is a char variable set to 'R'. This class also implements virtual functions (not pure virtual) from Pieces such as move() or getPiece() that are unique to the particular chess piece. However, when I compile my program, I get the following error: ChessBoard.cpp:69: error: expected type-specifier before ‘Rook’ ChessBoard.cpp:69: error: cannot convert ‘int*’ to ‘Pieces*’ in assignment Can someone please explain what I should change to get rid of this rather annoying persistent error? I would appreciate it.

    Read the article

  • Handling Data Hierarchies in code

    - by Miau
    Hi there So, say I have a string to parse with a given format that maps to a tree like data structure. The string is kinda similar to a folder path, and the structure is similar to a file structure, except its got some rules so for something@cat1@otherSomething you would get /something/cat1/otherSomething for something@cat2@otherSomething you would get /something/cat2/otherSomething other examples /OtherThing/cat1/otherSomething/Blah /OtherThing/cat4/otherSomething Where something, cat1, otherSomethign, etc are some sort of instances of ICategory There are certain rules that control what subcategories are valid and which subcategories are not acceptable, at the moment I m considering a heavy Object hierachy, but I know this is not a flexible solution, I d prefer the categories to be a bit more general but again, since there are rules about what can go next I m not sure how to do this. An example of a rule can be: OtherThing can only have subcategories cat1 and cat4 ( anything else is invalid) An option would be to use some sort of convention based aproach to instantiate a particular class given a subsection of the string(like cat4) but it seems a bit too complex, I m all ears Thanks

    Read the article

  • C# Using singleton instead of a global static instance

    - by Farstucker
    I ran into a problem today and a friend recommended I use a global static instance or more elegantly a singleton pattern. I spent a few hours reading about singletons but a few things still escape me. Background: What Im trying to accomplish is creating an instance of an API and use this one instance in all my classes (as opposed to making a new connection, etc). There seems to be about 100 ways of creating a singleton but with some help from yoda I found some thread safe examples. ..so given the following code: public sealed class Singleton { public static Singleton Instance { get; private set; } static Singleton() { Instance = new Singleton(); } } How/Where would you instantiate the this new class and how should it be called from a separate class? Thanks for your help.

    Read the article

  • Using C# assemblies from VB6 code. Some issues.

    - by AngryHacker
    I have a C# assembly, which is regasmed, but is not in the GAC. In my VB6 code, I added a reference to the generated type library (the .tlb file). Then I instantiate the C# lib in my VB6 code. If I run it from the VB6 IDE, it does not work. The Set in the code below: Dim obj as MyCSharpNamespace.MyCSharpObject Set obj = New MyCSharpNamespace.MyCSharpObject causes this error: Automation error The system cannot find the file specified However, if I compile the VB6 project to an EXE and run it, it runs perfectly fine. I should add that all the VB6 project files (e.g. forms, modules, etc...) are in the same folder as the C# DLL and TLB. So why can't I run it from the IDE environment?

    Read the article

  • C++ interface inheritance problem

    - by james t
    Hey, i'm trying to create a c++ stomp client, my client constructor is : Client(std::string &server, short port, std::string &login, std::string &pass, Listener &listener); it gets a listener object which when Listener is the following interface : class Listener { virtual void message(StmpMessage message) =0; }; now i attempt to instantiate a client in a test class : class test : public virtual Listener { public: void message(StmpMessage message) { message.prettyPrint(); } int main(int argc, char* argv[]) { Client client("127.0.0.1", 61613, *this); return 0; } }; i'm sending this to the client because this is a listener object, i get the following error : /Users/mzruya/Documents/STOMPCPP/main.cpp:18: error: no matching function for call to 'Client::Client(const char [10], int, test&)' /Users/mzruya/Documents/STOMPCPP/Client.h:43: note: candidates are: Client::Client(std::string&, short int, std::string&, std::string&, Listener&) /Users/mzruya/Documents/STOMPCPP/Client.h:37: note: Client::Client(const Client&)

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >