0

Android アプリケーションにガイド付きツアーを組み込もうとしていますが、解決できない非常に単純なエラーが発生しました。このエラーは XML ファイルにあります。ここにあります:

The following classes could not be instantiated:
- com.rohit.ShowcaseView (Open Class, Show Exception)
Exception Details java.lang.NoSuchMethodException: com.rohit.ShowcaseView.<init>
(android.content.Context, android.util.AttributeSet)   at java.lang.Class.getConstructor0(Class.java:2730)   at java.lang.Class.getConstructor(Class.java:1676)   at android.view.LayoutInflater.inflate(LayoutInflater.java:469)   at android.view.LayoutInflater.inflate(LayoutInflater.java:373)

これが私のXMLファイル全体です。

<?xml version="1.0" encoding="utf-8"?>
<!-- This is our ShowCase template that we will use
  whenever we want to showcase an item.
  Here we can customise the colors of the showcase. -->
<com.rohit.ShowcaseView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:showcaseview="http://schemas.android.com/apk/res/com.rohit"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    showcaseview:sv_backgroundColor="@color/showcase_background"
    showcaseview:sv_buttonText="@string/showcase_button_ok" />

これが私のShowcaseViewクラスの一部です:

protected ShowcaseView(Context context) {
    this(context, null, R.styleable.CustomTheme_showcaseViewStyle);
}

protected ShowcaseView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Get the attributes for the ShowcaseView
    final TypedArray styled = context.getTheme()
            .obtainStyledAttributes(attrs, R.styleable.ShowcaseView, R.attr.showcaseViewStyle,
                    R.style.ShowcaseView);
    mBackgroundColor = styled
            .getInt(R.styleable.ShowcaseView_sv_backgroundColor, Color.argb(128, 80, 80, 80));
    int showcaseColor = styled
            .getColor(R.styleable.ShowcaseView_sv_showcaseColor, Color.parseColor("#33B5E5"));

    int titleTextAppearance = styled
            .getResourceId(R.styleable.ShowcaseView_sv_titleTextAppearance,
                    R.style.TextAppearance_ShowcaseView_Title);
    int detailTextAppearance = styled
            .getResourceId(R.styleable.ShowcaseView_sv_detailTextAppearance,
                    R.style.TextAppearance_ShowcaseView_Detail);

    buttonText = styled.getString(R.styleable.ShowcaseView_sv_buttonText);
    styled.recycle();

    metricScale = getContext().getResources().getDisplayMetrics().density;
    mEndButton = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null);

    mShowcaseDrawer = new ClingDrawerImpl(getResources(), showcaseColor);

    // TODO: This isn't ideal, ClingDrawer and Calculator interfaces should be separate
    mTextDrawer = new TextDrawerImpl(metricScale, mShowcaseDrawer);
    mTextDrawer.setTitleStyling(context, titleTextAppearance);
    mTextDrawer.setDetailStyling(context, detailTextAppearance);

    ConfigOptions options = new ConfigOptions();
    options.showcaseId = getId();
    setConfigOptions(options);

    init();
}

ここで何が間違っていますか?解決策が見つかりません。この問題に関するヘルプをいただければ幸いです。

4

1 に答える 1

0

you need to define a constructor in your custom view that takes context and AttributeSet as params:

public ShowcaseView(Context context, AttributeSet attrs) {
    super(context, attrs);

}

It is needed to construct the object from xml file.

Just add this constructor to your class and include additional code if needed.

See the related part of logcat output that complains about non-existence of this constructor:

 Exception Details java.lang.NoSuchMethodException: com.rohit.ShowcaseView.<init>
 (android.content.Context, android.util.AttributeSet)
于 2014-03-11T23:12:54.163 に答える