1
정적 유형 클래스가있는 참조를 통해 가능한 정의되지 않은 메서드 테스트를 호출합니다. 여기 정적 메서드에서 오류가 발생하는 이유
여기 내 수업package com.singleton.sample{
public class SampleSingleton{
public static function test():void{
trace('hello world')
}
}
}
이고 것은 내가이 내 수업을 제거하고 여전히 작동하지 않는
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
import com.singleton.sample.SampleSingleton;
public function init():void{
SampleSingleton.test() // error on this line
}
]]>
</mx:Script>
</mx:Application>
명명의 싱글 참조를 무시하십시오 내 MXML입니다 . 내가 내기 응용 프로그램 파일이 SampleSingleton라는
import com.singleton.sample.SampleSingleton;
public function init():void{
SampleSingleton.test(); // this gives me the error
com.singleton.sample.SampleSingleton.test(); // this works
}
SampleSingleton 클래스에 비 정적 메서드를 추가하고 인스턴스를 만들고 init 메서드에서 해당 메서드를 호출 할 수 있습니까? 코드가 나에게 잘 보이지만 프로젝트/클래스 경로 등에서 문제가있을 수 있습니다. –
재현 할 수 없습니다. 내가 생각할 수있는 유일한 것은'SampleSingleton'이 물리적으로 올바른 패키지에 있지 않다는 것입니다. – RIAstar
@RIAstar 필자는 그렇게 생각했지만 import 문을 입력했을 때 IDE는 com.singleton.sample.SampleSingleton을 자동 생성했습니다. 그래서 나는 모른다. 이것은 새로운 프로젝트이므로 뭔가 올바르게 설정되지 않았습니다. –