gpt4 book ai didi

android - 自定义 ImageView 未实例化 java.lang.UnsupportedOperationException

转载 作者:行者123 更新时间:2023-11-30 03:48:53 28 4
gpt4 key购买 nike

正在抛出以下错误。

The following classes could not be instantiated:
- com.m.widget.CustomImageView (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.UnsupportedOperationException: Unsupported Service: accessibility
at com.android.layoutlib.bridge.android.BridgeContext.getSystemService(BridgeContext.java:448)
at com.actionbarsherlock.internal.widget.IcsProgressBar.<init>(IcsProgressBar.java:340)
at com.actionbarsherlock.internal.widget.IcsProgressBar.<init>(IcsProgressBar.java:273)
at com.actionbarsherlock.internal.widget.IcsProgressBar.<init>(IcsProgressBar.java:269)
at com.m2catalyst.widget.CustomImageView.<init>(CustomImageView.java:32)
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:413)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:170)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:372)

最佳答案

错误消息告诉您发生了什么:

at com.actionbarsherlock.internal.widget.IcsProgressBar.(IcsProgressBar.java:340

这与您正在使用的 UI 编辑器不兼容。这样做:

public CustomImageView(Context context) {
this(context, null);
}


public CustomImageView(Context context, AttributeSet attrs){
this(context, attrs, 0);
}

public CustomImageView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
imageView = new ImageView(context, attrs, defStyle);
if (!isInEditMode()) progressBar = new IcsProgressBar(context, attrs, defStyle);
init();
}

类似的东西应该有所帮助。基本上使用 isInEditoMode 检查 View 是否位于 UI 编辑器中,并且不要运行该模式不支持的代码。

关于android - 自定义 ImageView 未实例化 java.lang.UnsupportedOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14467430/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com