【问题标题】:Roboguice example astroboy can't work with NullPointerExceptionRoboguice 示例 astroboy 无法使用 NullPointerException
【发布时间】:2014-11-25 08:55:57
【问题描述】:

我是 RoboGuice 的新手, 克隆 git 存储库后,我做了以下操作:

mvn 安装

显示成功。 然后我 cd 到 astroboy 并执行:

mvn 包

mvn android:deploy

这表明找不到android-support相关类,然后我添加了依赖项,但仍然得到:

11-25 16:41:50.984 7957-7957/org.roboguice.astroboy I/Process﹕ Sending signal. PID: 7957 SIG: 9
11-25 16:41:51.844 8095-8095/org.roboguice.astroboy D/roboguice.RoboGuice﹕ Using annotation database(s).
11-25 16:41:51.854 8095-8095/org.roboguice.astroboy D/roboguice.RoboGuice﹕ Using annotation database(s) : [, roboguice]
11-25 16:41:51.854 8095-8095/org.roboguice.astroboy D/roboguice.RoboGuice﹕ Time spent loading annotation databases : 4
11-25 16:41:51.984 8095-8095/org.roboguice.astroboy E/MoreInfoHPW_ViewGroup﹕ Parent view is not a TextView
11-25 16:41:52.054 8095-8095/org.roboguice.astroboy D/AndroidRuntime﹕ Shutting down VM
11-25 16:41:52.054 8095-8095/org.roboguice.astroboy W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41c5f898)
11-25 16:41:52.054 8095-8095/org.roboguice.astroboy E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at org.roboguice.astroboy.view.CustomView.onAttachedToWindow(CustomView.java:38)
at android.view.View.dispatchAttachedToWindow(View.java:13030)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2683)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1461)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1253)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6402)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
at dalvik.system.NativeStart.main(Native Method)

有什么意见吗?

【问题讨论】:

    标签: android roboguice


    【解决方案1】:

    如果您指的是Astroboy Example,以下是可能的解决方案之一。

    您可以添加以下行:

    RoboGuice.injectMembers(getContext(), this);
    RoboGuice.getInjector(getContext()).injectViewMembers(this);
    

    布局膨胀后

    LayoutInflater.from(context).inflate(R.layout.view_custom, this, true);
    

    initializeView() 方法中。那么问题就可以解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      • 2014-10-24
      • 2015-10-14
      相关资源
      最近更新 更多