6
6

More than 5 years have passed since last update.

Android レイアウトエディタでカスタムビューを使用しているときにExceptionのログが表示されている場合の対処法

Last updated at Posted at 2013-10-23

レイアウトエディタ内で以下エラーログが発生した場合の対処法

The following classes could not be instantiated:
- jp.xxxx.xxxxx (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse

java.lang.NullPointerException
    at xxx.xxxx.android.util.xxxx.xxxxx(WebUtil.java:23)
    at xxx.xxxx.android.view.xxxx.<init>(xxxxx.java:40)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(    at sun.reflect.NativeConstructorAccessorImpl.newInstance(    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(    at java.lang.reflect.Constructor.newInstance(    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
//コンストラクタ内で何か処理を入れている場合isInEditMode()で判定してやらないと上記ログが表示される
public CustomView(Context context) {
    super(context);
    // レイアウトエディターでisInEditMode()で判定しないとエディター内でExceptionが発生する
    if (!isInEditMode()) {
        // カスタムユーザーエージェントをセットする
        init();
    }
}
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6