2013-11-21 3 views
0

EditText 클래스를 확장하려고하는데 작동하지 않는 것 같습니다. 나는 서브 클래스로 활동을 확장 내 공용 클래스 MainActivity에서이 클래스를 만들었습니다Extended EditText 클래스가 인스턴스화되지 않습니다.

public class EditText2 extends EditText 
{ 

    public EditText2(Context context) { 
     super(context); 
     // TODO Auto-generated constructor stub 
    } 

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

    public EditText2(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     // TODO Auto-generated constructor stub 
    }  
} 

손 코딩을 시도하고 activity_main.xml을 편집 Eclipse에서 그래픽 레이아웃 탭을 사용하여 같은 새 클래스를 추가 할 수 :

<first.words.firstwords.MainActivity.EditText2 
    android:id="@+id/user_input" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:text="EditText2" > 

    <requestFocus /> 
</first.words.firstwords.MainActivity.EditText2> 

하지만 내가 얻을 : com.android.layoutlib.bridge.impl.RenderSessionImpl.getDefaultProperties에서

java.lang.NullPointerException이 (RenderSessionImpl.java:14 76) at com.android.layoutlib.bridge.BridgeRenderSession.getDefaultProperties (BridgeRenderSession.java:68) at com.android.ide.eclipse.adt.internal.editors.layout.gle2.ViewHierarchy.getDefaultProperties (ViewHierarchy.java : 710) com.android.ide.eclipse.adt.internal.editors.layout에서 com.android.ide.eclipse.adt.internal.editors.layout.properties.XmlProperty.getStringValue (XmlProperty.java:209에서 ) . properties.XmlProperty.getValue (XmlProperty.java:221) com.android.ide.eclipse.adt.internal.editors.layout.properties.XmlPropertyEditor.getText (XmlPropertyEditor.java:116)에서 com.android.ide에서 . eclipse.adt.internal.editors.layout.properties.XmlPropertyEditor.paint (XmlPropertyEditor.java:131) at org.eclipse.wb.internal.core.model.property.table.PropertyTable.drawProperty (Pr org.eclipse.wb.internal.core.model.property.table.PropertyTable.drawContent (PropertyTable.java:1151) at org.eclipse.wb.internal.core.model.property. table.PropertyTable.handlePaint (PropertyTable.java:1094) 에서 org.eclipse.wb.internal.core.model.property.table.PropertyTable.access $ 200 (PropertyTable.java:64) at org.eclipse.wb.internal .core.model.property.table.PropertyTable $ 3.handleEvent (PropertyTable.java:187) at org.eclipse.swt.widgets.EventTable.sendEvent (EventTable.java:84) at org.eclipse.swt.widgets. Widget.sendEvent (Widget.java:1276) at org.eclipse.swt.widgets.Widget.sendEvent (Widget.java:1300) at org.eclipse.swt.widgets.Widget.sendEvent (Widget.java:1285) at org.eclip org.eclipse.swt.widgets.Composite.gtk_expose_event (Composite.java:709) at org.eclipse.swt.widgets.Canvas.gtk_expose_event Canvas.java:167) at org.eclipse.swt.widgets.Widget.windowProc (Widget.java:1769) at org.eclipse.swt.widgets.Control.windowProc (Control.java:5116) at org. eclipse.swt.widgets.Display.windowProc (Display.java:4377) at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event (네이티브 메소드) at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event (OS.java:8317) at org.eclipse.swt.widgets.Display.eventProc (Display.java:1193) at org.eclipse.swt.internal.gtk.OS._gdk_window_process_all_updates (기본 메소드) 에서 org.eclipse.swt.internal.gtk.OS.gdk_window_process_all_updates (OS.java:5571) at org.eclipse.swt.widgets.Display.update (Display.java:4330) at org.eclipse.swt. widgets.Display.runDeferredLayouts (Display.java:3588) at org.eclipse.swt.widgets.Display.readAndDispatch (Display.java:3173) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine $ 9 .run (PartRenderingEngine.java:1053) at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run (PartRenderingEngine.자바 : 942) org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI (E4Workbench.java:86) 에서 org.eclipse.ui.internal.Workbench $ 5.run (Workbench.java:588에서) org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench (Workbench.java:543) at org.eclipse.ui.PlatformUI org.eclipse.equinox.internal.app.EclipseAppHandle.run에서 org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:124) 에서 .createAndRunWorkbench (PlatformUI.java:149) (EclipseAppHandle .java : 196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication (EclipseAppLauncher.java:110) at org.eclipse.core.runtime.in ternal.adaptor.EclipseAppLauncher.start (EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:353) at org.eclipse.core.runtime.adaptor.EclipseStarter. sun.reflect.DelegatingMethodAccessorImpl.invoke에서 sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) 에서 sun.reflect.NativeMethodAccessorImpl.invoke0 (기본 방법) 에서 실행 (EclipseStarter.java:180) (DelegatingMethodAccessorImpl.java : 43) at java.lang.reflect.Mavod.invoke (Method.java:606) at org.eclipse.equinox.launcher.Main.invokeFramework (Main.java:629) at org.eclipse.equinox.launcher .Main.basicRun (Main.java:584) at org.eclipse.equinox.launcher.Main.run (Main.java:1438) activity_main.xml과의 ClassNotFoundException에서

org.eclipse.equinox.launcher.Main.main (Main.java:1414)에서 나는 응용 프로그램을 실행할 때. 나는 인터넷 검색을했고 Extending a EditText in Android. What do I do wrong?What's the right way to extend EditText to give it additional “default” functionality을 보았다.

누구든지 내가 본 시간이 너무 많아서 볼 수 없기 때문에 내가 잘못 읽은 곳을 볼 수 있습니까?

답변

0

이유는 EditText2이 내부 클래스이기 때문입니다. $ 사용) (다음과 같이)를 참조해야합니다 : EditText2.java) :

<view class="first.words.firstwords.MainActivity$EditText2" 
... 
... 

또는 새로운 클래스 파일 (예를 들어,이 이동합니다.

Here 당신이 시도해 볼만한 제안입니다.

+0

아, 알겠습니다. 알겠습니다. 내가 뭔가를 잊었음에 틀림 없다는 것을 알았다. 흥미로운 점 : XML 태그에 대해 EditText insted를 사용하면 여전히 실패합니다. 감사합니다 Amulya. –

관련 문제