Notice
Recent Posts
Recent Comments
Link
관리 메뉴

DreamFactory7

안드로이드 오류 Caused by: java.lang.NoSuchMethodException: 생성자(Context,AttributeSet) 본문

삽질/Android

안드로이드 오류 Caused by: java.lang.NoSuchMethodException: 생성자(Context,AttributeSet)

우루사1호 2013. 5. 2. 13:36

제목 :

안드로이드 오류 Caused by: java.lang.NoSuchMethodException: 생성자(Context,AttributeSet)

05-02 04:12:50.088: E/AndroidRuntime(338): FATAL EXCEPTION: main
05-02 04:12:50.088: E/AndroidRuntime(338): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.a05_2_1/com.example.a05_2_1.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class com.example.a05_2_1.GraphicDraw
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.os.Looper.loop(Looper.java:123)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-02 04:12:50.088: E/AndroidRuntime(338):     at java.lang.reflect.Method.invokeNative(Native Method)
05-02 04:12:50.088: E/AndroidRuntime(338):     at java.lang.reflect.Method.invoke(Method.java:521)
05-02 04:12:50.088: E/AndroidRuntime(338):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-02 04:12:50.088: E/AndroidRuntime(338):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-02 04:12:50.088: E/AndroidRuntime(338):     at dalvik.system.NativeStart.main(Native Method)
05-02 04:12:50.088: E/AndroidRuntime(338): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class com.example.a05_2_1.GraphicDraw
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.view.LayoutInflater.createView(LayoutInflater.java:503)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-02 04:12:50.088: E/AndroidRuntime(338):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.Activity.setContentView(Activity.java:1647)
05-02 04:12:50.088: E/AndroidRuntime(338):     at com.example.a05_2_1.MainActivity.onCreate(MainActivity.java:12)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-02 04:12:50.088: E/AndroidRuntime(338):     ... 11 more
05-02 04:12:50.088: E/AndroidRuntime(338): Caused by: java.lang.NoSuchMethodException: GraphicDraw(Context,AttributeSet)
05-02 04:12:50.088: E/AndroidRuntime(338):     at java.lang.Class.getMatchingConstructor(Class.java:660)
05-02 04:12:50.088: E/AndroidRuntime(338):     at java.lang.Class.getConstructor(Class.java:477)
05-02 04:12:50.088: E/AndroidRuntime(338):     at android.view.LayoutInflater.createView(LayoutInflater.java:475)
05-02 04:12:50.088: E/AndroidRuntime(338):     ... 21 more

로그켓에 다음과같은 오류메시지가 나옴.
엄청많으니 잘찾아볼것

원인 :
View를상속받았으면 이에대한 생성자는 두개를 써줘야한다.

해결 :

public class GraphicDraw extends View {
    public GraphicDraw(Context context) {
        super(context);
    }

    public GraphicDraw(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }
   
   
    //중략
}

참고 :
GraphicDraw가 생성자임.


'삽질 > Android' 카테고리의 다른 글

안드로이드개발.터치이벤트안될때  (0) 2013.05.02