3

我在我的 android 应用程序中使用这里ShowcaseView的库。我想与. 但我不知道如何使用它?我尝试过以下代码,但它会抛出. 请帮我解决这个问题。ShowcaseViewActionbar CompatNullPointerexception

谢谢你。

代码 :

public class Activity1 extends ActionBarActivity implements
        OnShowcaseEventListener {

    ShowcaseView sv;
    ShowcaseView.ConfigOptions co;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.screen1);
            co = new ShowcaseView.ConfigOptions();
            co.hideOnClickOutside = false;
            co.block = false;
       }catch (Exception ex) {
            ex.printStackTrace();
       }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);

        ActionViewTarget target = new ActionViewTarget(this,
                ActionViewTarget.Type.OVERFLOW);
        sv = ShowcaseView.insertShowcaseView(target, this, "Edit",
                "Click here to edit image.", co);
     }
}

错误日志:

11-29 17:12:19.792: E/AndroidRuntime(20991): FATAL EXCEPTION: main
11-29 17:12:19.792: E/AndroidRuntime(20991): java.lang.NullPointerException
11-29 17:12:19.792: E/AndroidRuntime(20991):    at com.espian.showcaseview.targets.ViewTarget.getPoint(ViewTarget.java:22)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at com.espian.showcaseview.targets.ActionViewTarget.getPoint(ActionViewTarget.java:52)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at com.espian.showcaseview.ShowcaseView$3.run(ShowcaseView.java:240)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at android.os.Handler.handleCallback(Handler.java:725)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at android.os.Looper.loop(Looper.java:137)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at android.app.ActivityThread.main(ActivityThread.java:5283)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at java.lang.reflect.Method.invokeNative(Native Method)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at java.lang.reflect.Method.invoke(Method.java:511)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-29 17:12:19.792: E/AndroidRuntime(20991):    at dalvik.system.NativeStart.main(Native Method)
4

2 回答 2

4

我解决了这个问题。OnCreateOptionsMenu()用以下代码替换代码。

代码:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);

        sv = ShowcaseView.insertShowcaseViewWithType(ShowcaseView.ITEM_ACTION_ITEM,
            R.id.action_edit, FaceFrameActivity_dual.this,"Edit", 
           "Click here to edit image.", co);
     }
于 2013-11-30T04:45:59.413 回答
0

请参阅此博客文章。我正在使用支持库,它工作正常。

以下代码将创建三个背靠背显示的视图(溢出菜单、我的页面中的视图和操作栏项)。

    ShowcaseViews views = new ShowcaseViews(activity, new ShowcaseViews.OnShowcaseAcknowledged() {
        @Override
        public void onShowCaseAcknowledged(ShowcaseView showcaseView) {
            Toast.makeText(activity, "clicked", Toast.LENGTH_SHORT).show();
        }
    });

    views.addView(new ShowcaseViews.ItemViewProperties(ShowcaseViews.ItemViewProperties.ID_OVERFLOW, R.id.test, R.id.test, ShowcaseView.ITEM_ACTION_OVERFLOW));
    views.addView(new ShowcaseViews.ItemViewProperties(R.id.search_keyword, R.string.test, R.string.test, 0.5f));
    views.addView(new ShowcaseViews.ItemViewProperties(R.id.action_refresh, R.string.test, R.string.test, ShowcaseView.ITEM_ACTION_ITEM, 0.5f));
    views.show();
于 2014-02-18T16:15:40.657 回答