instantiation

android, The constructor MediaController() is undefined

寵の児 提交于 2019-12-25 13:47:31
问题 I have an android app, working fine with fragments, I need to show a video from a fragment, but in order to do this, I need to instantiate mediacontroller, but i get : The constructor MediaController() is undefined here my code: package com.orchard.elasto.custom; import com.egoclean.elasto.R; import android.content.Context; import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.TypedValue; import

Instantiating classes between jsp scriptlets

被刻印的时光 ゝ 提交于 2019-12-25 08:48:23
问题 Is it possible to instantiate a class and then invoke its methods between scriptlets in JSP? I am getting errors and I don't know why (java class and methods are fine). Any other way to do the same (i just want a string from a method in a class)? 回答1: Yes of-course. You can create objects for your classes and access their methods between scriptlets in JSP like this. <% Foo foo = new Foo(); foo.method1(); %> Another way of doing this is using useBeans of jsp to instantiate the class and access

Should I use a seperate beans.xml configuration for instantiating objects in my unit tests?

心不动则不痛 提交于 2019-12-25 07:48:04
问题 Here's my Beans.xml for my application <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="myRoom" class="org.world.hello.Room"> <property name="bottleCounter"> <bean id="myBottleCounter" class="org.world.hello.BottleCounter" /> </property> <property name=

Restrict object's creation

徘徊边缘 提交于 2019-12-25 05:16:12
问题 I have a very strange question here. I have Class A, Class B and Class C. I want to create object of Class B which can create the object of A. But how to restrict Class C from creating object of Class A. One way is define Class A inside Class B, so that Only Class B can create the instance of Class A and Class C cannot access Class A. But, I think nesting is a wrong way. Do we have any way to restrict the object creation? Is it possible to use attribute and reflection to help to restrict? If

C++ template for variable type declaration

让人想犯罪 __ 提交于 2019-12-25 03:07:35
问题 I have a number of classes with differing members, all of which have operations of the following type ::basedata::Maindata maindata; ::basedata::Subdata subinfo("This goes into the subinfo vector"); subinfo.contexts(contextInfo); maindata.subdata().push_back(subinfo); Note that I am asking how to set up generalized templates to perform these actions. I cannot set up a special case for each type of maindata and subinfo. I also need to be able to see how to call the template from my main code.

Reflection instantiation

别来无恙 提交于 2019-12-25 02:47:39
问题 I am currently trying to create a generic instance factory for which takes an interface as the generic parameter (enforced in the constructor) and then lets you get instantiated objects which implement that interface from all types in all loaded assemblies. The current implementation is as follows: public class InstantiationFactory<T> { protected Type Type { get; set; } public InstantiationFactory() { this.Type = typeof(T); if (!this.Type.IsInterface) { // is there a more descriptive

Access to instance variable, but not instance method in Python

↘锁芯ラ 提交于 2019-12-25 01:00:51
问题 I'm a newbie to python and I think similar question have been asked (including this one: Can you use a string to instantiate a class in python?), but I don't understand the answers or how to apply them. I'm trying to create multiple instances of a class using what i'll call 'instance names' in a list. Here's an example of what I'm trying to do: class InstanceNames(): def __init__(self): self.names = ['inst1', 'inst2', 'inst3'] class DoSomething(): instances = [] def __init__(self):

How can I use 1 notifyIcon between multiple forms?

为君一笑 提交于 2019-12-24 23:02:42
问题 I have a notifyIcon added to my main form of a project. I have other forms in the project that I want to be able to use the notifyIcon though which is proving difficult. What would be the best way to use 1 notifyIcon between multiple forms? I read a thread about not adding it to a form but instantiating it in its own class which made no sense to me. Thoughts? 回答1: Just expose a property on your main form to return a reference to the NotifyIcon. You can even make it static since there is only

How to make a type safe wrapper around Variant values

柔情痞子 提交于 2019-12-24 18:46:49
问题 I'm working with a OPC Server control that stores data tags as variant types, described by System.Runtime.InteropServices.VarEnum . These types include the following, VT_BSTR (string), VT_I2 (short) and VT_I4 (long). All these values are stored by the server as objects and then I have to cast to the correct value when I fetch them. I know that I can do something like the following: object tagValue = (object)"testing"; //this would be returned from a function rather than created this way!! var

Scala Reflection: instantiating a singleton object

▼魔方 西西 提交于 2019-12-24 18:25:06
问题 I'm using the following code to instantiate a scala object. This works, but there seems to be one problem: the println is printed out twice , each time with another hashcode. import scala.reflect.runtime.universe._ import scala.reflect.runtime.{universe => ru} object Test2 { println("init"+hashCode())} val mirror = ru.runtimeMirror(getClass.getClassLoader) val m = ru.typeOf[Test2.type].members.filter(_.isConstructor).head.asMethod val m2 = mirror.reflectClass(typeOf[Test2.type].typeSymbol