[英]Google Glass Live Card Menu Action Causes Crash
I'm having some nullPointerException trouble with a Live Card Menu Activity on Google Glass. 我在Google Glass上进行Live Card菜单活动时遇到了nullPointerException问题。
I want to: 我想要:
The action to be performed is simply changing the boolean value of a variable located in my LiveCardService
class. 要执行的操作只是更改位于
LiveCardService
类中的变量的布尔值。
My LiveCardMenuActivity
code looks like this - 我的
LiveCardMenuActivity
代码如下所示-
public class LiveCardMenuActivity extends Activity {
LiveCardService liveCard; // call in the livecardservice class
// ... STANDARD MENU STUFF ... //
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_stop:
// Stop the service which will unpublish the live card.
stopService(new Intent(this, LiveCardService.class));
return true;
case R.id.action_ttoro:
liveCard.resetWaypoints(); // THIS IS WHERE IT CRASHES
return true;
default:
return super.onOptionsItemSelected(item);
}
}
...
}
In this case, when the program attempts to carry out "livecard.resetWaypoints()"
, the program crashes with a nullPointerException
. 在这种情况下,当程序尝试执行
"livecard.resetWaypoints()"
,程序将崩溃并nullPointerException
。
The "resetWaypoints()"
function in the LiveCardService looks like this (nothing special) - 该
"resetWaypoints()"
在LiveCardService功能看起来像这样(没有什么特别) -
public void resetWaypoints() {
ttoroActive = false;
bgbukActive = false;
lassyActive = false;
dployActive = false;
}
The monster logcat complaint looks like this - 怪物logcat投诉看起来像这样-
E/InputEventSender﹕ Exception dispatching finished signal.
E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI﹕ java.lang.NullPointerException
at [...].LiveCardMenuActivity.resetWaypoints(LiveCardMenuActivity.java:57)
at [...].LiveCardMenuActivity.onOptionsItemSelected(LiveCardMenuActivity.java:42)
at android.app.Activity.onMenuItemSelected(Activity.java:2604)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1054)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:765)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:157)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:908)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:898)
at com.google.android.glass.menu.SliderMenuView$1.onItemClick(SliderMenuView.java:81)
at com.google.android.glass.widget.CardScrollView.onTap(CardScrollView.java:1453)
at com.google.android.glass.widget.CardScrollView.access$2000(CardScrollView.java:94)
at com.google.android.glass.widget.CardScrollView$3.onGesture(CardScrollView.java:383)
at com.google.android.glass.touchpad.CombinedListener.onGesture(CombinedListener.java:185)
at com.google.android.glass.touchpad.OneFingerState.onEvent(OneFingerState.java:49)
at com.google.android.glass.touchpad.StateMachine.onEvent(StateMachine.java:100)
at com.google.android.glass.touchpad.GestureDetector.onMotionEvent(GestureDetector.java:283)
at com.google.android.glass.widget.CardScrollView.dispatchGenericFocusedEvent(CardScrollView.java:2103)
at android.view.View.dispatchGenericMotionEvent(View.java:7778)
at android.view.ViewGroup.dispatchGenericFocusedEvent(ViewGroup.java:1798)
at android.view.View.dispatchGenericMotionEvent(View.java:7778)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchGenericMotionEvent(PhoneWindow.java:2154)
at android.view.ViewRootImpl$ViewPostImeInputStage.processGenericMotionEvent(ViewRootImpl.java:3995)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3859)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3421)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3440)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3547)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3448)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3604)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3421)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3440)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3448)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3421)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3440)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3580)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3740)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2010)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1704)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1695)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1987)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.
The action I would like to do seems pretty straightforward. 我想做的动作似乎很简单。 I have looked at Google's documentation, as far as I have found, they just offer a very simple example of the menu.
我查看了Google的文档,据我发现,它们只是提供了菜单的一个非常简单的示例。
This liveCardMenuActivity
is registered in the Manifest. 此
liveCardMenuActivity
已在清单中注册。
Any tips would be much appreciated. 任何提示将不胜感激。
EDIT: Just to be clear, I want with a touch of a button to be able to change the values of those four boolean variables that are located in my LiveCardService class by calling a function I created in the LiveCardService class that does so. 编辑:为了清楚起见,我希望通过触摸按钮就能通过调用在LiveCardService类中创建的函数来更改位于LiveCardService类中的这四个布尔变量的值。 This is what the LiveCardService class looks like when starting the LiveCard
这是启动LiveCard时LiveCardService类的外观
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) { //WHEN ACTIVITY STARTS, LIVECARD IS NULL
// Create live card object
mLiveCard = new LiveCard(this, TAG);
// Set rendering view of the live card
remoteViews = new RemoteViews(getPackageName(), R.layout.live_card02);
// Can contain TextView, ImageView, etc
mLiveCard.setViews(remoteViews);
// Display the options MENU when the live card is tapped.
Intent menuIntent = new Intent(this, LiveCardMenuActivity.class);
mLiveCard.setAction(PendingIntent.getActivity(this, 100, menuIntent, 0));
mLiveCard.publish(PublishMode.REVEAL);
// Runs this live card every xxxx milliseconds
mHandler = new Handler();
mHandler.postDelayed(runnable, 1000);
}
else {
mLiveCard.navigate();
Log.d(TAG, "Livecard is not null");
}
return START_STICKY;
}
You definitely shouldn't keep this LiveCardService instance. 您绝对不应该保留此LiveCardService实例。
You should rather talk to your Service unsing intent: 您应该宁愿与您的服务取消意图:
Intent intent = new Intent(this, LiveCardService.class);
intent .setAction("RESET");
startService(intent);
and then, inside your Service: 然后,在您的服务中:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if("RESET".equals(intent.getAction()) {
// do the reset here
resetWaypoints();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.