为什么按钮不能正常工作?

时间:2015-02-13 05:46:06

标签: java android android-studio gradle

我迁移到了gradle。这是回购https://github.com/jackygrahamez/MayDay/tree/gradle2

现在按钮无法正常工作。

enter image description here

清单文件在迁移之前有效,MainActivity有重复的条目。如果我评论MainActivity的第二个条目,它就会运行。

enter image description here

如果我们评论MainActivity的第一个条目并取消注释第二个条目,项目也会运行。当我这样做时,按钮在MainActivity窗口上工作。但他们设置页面按钮崩溃。

02-13 00:44:13.980  13854-13854/com.mayday.md D/AbsListView﹕ Get MotionRecognitionManager
02-13 00:44:13.990  13854-13854/com.mayday.md D/AndroidRuntime﹕ Shutting down VM
02-13 00:44:13.990  13854-13854/com.mayday.md W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41765da0)
02-13 00:44:14.000  13854-13854/com.mayday.md E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mayday.md, PID: 13854
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mayday.md/com.mayday.md.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
            at android.app.ActivityThread.access$900(ActivityThread.java:173)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5579)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.mayday.md.fragment.SetupMessageFragment.onActivityCreated(SetupMessageFragment.java:149)
            at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1794)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:967)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
            at com.mayday.md.MainActivity.onStart(MainActivity.java:219)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1177)
            at android.app.Activity.performStart(Activity.java:5461)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
            at android.app.ActivityThread.access$900(ActivityThread.java:173)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5579)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
            at dalvik.system.NativeStart.main(Native Method)

在fragment.SetupMessageFragment

 ...
 @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        activity = getActivity();
        if (activity != null) {
            metrics = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

            Fragment fragment = getFragmentManager().findFragmentById(R.id.sms_message);
            ((MessageTextFragment)fragment).setActionButtonStateListener(bAction);
            smsEditText = (EditText) fragment.getView().findViewById(R.id.message_edit_text);

            String currentMsg = SMSSettings.retrieveMessage(activity);
            if(currentMsg != null) {
                displaySettings(currentMsg);
            }
            bAction.setEnabled(!smsEditText.getText().toString().trim().equals(""));

            String pageId = getArguments().getString(PAGE_ID);
            String selectedLang = ApplicationSettings.getSelectedLanguage(activity);

            PBDatabase dbInstance = new PBDatabase(activity);
            dbInstance.open();
            currentPage = dbInstance.retrievePage(pageId, selectedLang);
            dbInstance.close();

            tvTitle.setText(currentPage.getTitle());

            if(currentPage.getContent() == null)
                tvContent.setVisibility(View.GONE);
            else
                tvContent.setText(Html.fromHtml(currentPage.getContent(), null, new MyTagHandler()));

            if(currentPage.getIntroduction() == null)
                tvIntro.setVisibility(View.GONE);
            else
                tvIntro.setText(currentPage.getIntroduction());

            if(currentPage.getWarning() == null)
                llWarning.setVisibility(View.GONE);
            else
                tvWarning.setText(currentPage.getWarning());

            bAction.setText(currentPage.getAction().get(0).getTitle());

            pageItemAdapter = new PageItemAdapter(activity, null);
            lvItems.setAdapter(pageItemAdapter);
            pageItemAdapter.setData(currentPage.getItems());

            AppUtil.updateImages(true, currentPage.getContent(), activity, metrics, tvContent, AppConstants.IMAGE_INLINE);

        }
    }
    ...

0 个答案:

没有答案