草庐IT

Constructor

全部标签

php - 在子 PHP 之后自动调用父构造函数

我尝试使用父类的名称(如构造函数)并为我部分工作。第一次调用"DarthVadermethod"像构造函数但从不调用"LukeSkywalkerconstructor"..有人知道怎么做吗?example:达斯.phpclassDarthVader{publicfunctionDarthVader(){echo"--Obi-Wannevertoldyouwhathappenedtoyourfather.\n";}publicfunctionreponse(){echo"--No.Iamyourfather\n";}}卢克.phpinclude("Darth.php")classLuke

PHP:在构造函数中调用用户定义的函数?

我在其构造函数中有一个类userAuth我添加了代码来检查用户是否有效,如果session中没有值,那么我检查cookie(作为“记住我”的一部分"功能),如果cookie中有一些值,那么我调用函数ConfirmUser从数据库中检查其真实性。根据confirmUser函数返回的值,我在构造函数中返回一个bool值(true或fales)。我创建了我的类:confirmUser函数接受两个字符串类型参数并返回一个整数值0,1,2。我无法在构造函数中添加confirmUser函数的代码,因为我在我的应用程序的更多地方使用了这个函数。所以,我想知道如何在PHP的构造函数中调用用户定义的函数

PHP[OOP] - 如何手动调用类构造函数?

请看下面的代码:01.classTest{02.publicfunction__construct($param1,$param2,$param3){03.echo$param1.$param2.$param3;04.}05.}06.07.$params=array('p1','p2','p3');08.09.$ob=newTest;10.11.if(method_exists($ob,'__construct')){12.call_user_func_array(array($ob,'__construct'),$params);13.}现在,问题是在第09行调用了构造函数但我想在第

android - 为什么 fragment 有默认构造函数?

fragment中有默认构造函数,我想知道它有什么用,提供什么功能?我在没有它的情况下运行代码它工作得很好而且我找不到删除它的任何错误publicclassSongListFragmentextendsFragment{privatestaticfinalStringSONG_IDS="song_ids";//TODO:Renameandchangetypesofparametersprivateint[]songIds;privateOnFragmentInteractionListenermListener;publicSongListFragment(){//Requiredem

java - Kotlin 房间 :Entities and Pojos must have a usable public constructor

当我运行我的应用程序时,出现跟随错误。Error:EntitiesandPojosmusthaveausablepublicconstructor.Youcanhaveanemptyconstructororaconstructorwhoseparametersmatchthefields(bynameandtype).Triedthefollowingconstructorsbuttheyfailedtomatch:ChatMsg(java.lang.String,int):[arg0:null,arg1:null]Error:EntitiesandPojosmusthaveausa

android - Dagger 2 错误 : dependency “cannot be provided without an @Inject constructor”

我正在尝试在我的Android项目中使用Dagger2。对于初学者,我想使用两个组件分别负责注入(inject)应用程序范围和Activity范围的依赖项。作为基本引用,除其他外,我使用了thisanswer.因此有两种不同的方式来设置组件之间的关系:使用@Subcomponent注释和使用dependencies参数。如果我选择第一个,我的AppContextComponent工作正常。但是,一旦我尝试从ActivityContextComponent注入(inject)依赖项,我就会收到此构建时错误:Error:com.example.ui.activity.MainActivit

java - Android 和 GSON 抛出 No-Args Constructor not found 异常

我的Android应用程序中出现GSON问题。JSON输入[{"id":"1202","parent_id":"0","agrpcount":"0","disp_order":"1","code":"PROD-NEW","name":"NewProducts","active":"1"},{"id":"1119","parent_id":"0","agrpcount":"0","disp_order":"2","code":"PROD-VID","name":"\\\"HowTo\\\"Videos","active":"1"},{"id":"1685","parent_id":"0"

java - intentservice 没有空的构造函数,但是有一个构造函数

我在Activity中有一个IntentService,当我尝试调用该服务时,它会抛出这个错误,我觉得这很奇怪,因为如果我声明了空的构造函数。错误:06-1715:48:34.603:E/AndroidRuntime(13363):FATALEXCEPTION:main06-1715:48:34.603:E/AndroidRuntime(13363):java.lang.RuntimeException:Unabletoinstantiateservicecl.prosys.rac.activity.HomeActivity$UploadService:java.lang.Instan

java - 上下文和 Activity 有什么区别?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:DifferencebetweenActivityContextandApplicationContext何时使用上下文和Activity。我已经阅读了在Constructor中使用Context和Activity作为参数的代码,如下所示,请澄清一下publicAmazedView(Contextcontext,Activityactivity){super(context);mActivity=activity;//initpaintandmakeislook"nice"withanti-aliasing.

android - 在 Android Samsung Galaxy S 上播放流音频的问题

我刚刚发布了人生中的第一个Android应用程序。这是Audiko.当我使用AndroidMediaPlayer时,我发现在SamsungGalaxyS上播放mp3文件时出现错误。在日志中我看到了这个:E/PlayerDriver(2747):PlayerDriver::itisanotProtectedfileE/(2747):IIIIIIIInsideConstructorofPVMFMemoryBufferReadDataStreamImplE/(2747):IIIIIIIInsideConstructorofPVMFMemoryBufferReadDataStreamImplE