Java – greenroot eventbus failed to send event
I'm using eventbus to pass from a long-running thread to fragments that update its UI This long - running thread is basically listening for network activity, parsing it and putting events on the bus I have 2 clips set to receive events
An error occurred when I updated the fragments UI (textview) from the fragments onevent method How do I update the UI in a fragment from a separate thread?
This is my snippet code and the logcat output I see
Of logcat:
10-15 02:19:44.637: I/System.out(682): debugger has settled (1440) 10-15 02:19:45.021: V/BRRT(682): start thread 10-15 02:19:45.021: V/BRRT(682): past start thread 10-15 02:19:45.031: V/TEST(682): running thread... 10-15 02:19:45.121: D/Event(682): No subscribers registered for event class com.broadreach.radiotester.io.ExpeditionEvent 10-15 02:19:45.121: D/Event(682): No subscribers registered for event class de.greenrobot.event.NoSubscriberEvent 10-15 02:19:45.261: V/BRRT(682): OneUp event received: 204 : 32 10-15 02:19:45.271: W/ResourceType(682): No package identifier when getting value for resource number 0x00000000 10-15 02:19:45.351: E/Event(682): Could not dispatch event: class com.broadreach.radiotester.io.ExpeditionEvent to subscribing class class com.broadreach.radiotester.screens.OneUpScreen 10-15 02:19:45.351: E/Event(682): android.content.res.Resources$NotFoundException: String resource ID #0x0 10-15 02:19:45.351: E/Event(682): at android.content.res.Resources.getText(Resources.java:247) 10-15 02:19:45.351: E/Event(682): at android.widget.TextView.setText(TextView.java:3428) 10-15 02:19:45.351: E/Event(682): at com.broadreach.radiotester.screens.OneUpScreen.onEvent(OneUpScreen.java:47) 10-15 02:19:45.351: E/Event(682): at java.lang.reflect.Method.invokeNative(Native Method) 10-15 02:19:45.351: E/Event(682): at java.lang.reflect.Method.invoke(Method.java:511) 10-15 02:19:45.351: E/Event(682): at de.greenrobot.event.EventBus.invokeSubscriber(EventBus.java:569) 10-15 02:19:45.351: E/Event(682): at de.greenrobot.event.EventBus.postToSubscription(EventBus.java:500) 10-15 02:19:45.351: E/Event(682): at de.greenrobot.event.EventBus.subscribe(EventBus.java:288) 10-15 02:19:45.351: E/Event(682): at de.greenrobot.event.EventBus.register(EventBus.java:189) 10-15 02:19:45.351: E/Event(682): at de.greenrobot.event.EventBus.registerSticky(EventBus.java:166) 10-15 02:19:45.351: E/Event(682): at com.broadreach.radiotester.screens.OneUpScreen.onResume(OneUpScreen.java:33) 10-15 02:19:45.351: E/Event(682): at android.support.v4.app.Fragment.performResume(Fragment.java:1547) 10-15 02:19:45.351: E/Event(682): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:978) 10-15 02:19:45.351: E/Event(682): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121) 10-15 02:19:45.351: E/Event(682): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 10-15 02:19:45.351: E/Event(682): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484) 10-15 02:19:45.351: E/Event(682): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482) 10-15 02:19:45.351: E/Event(682): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163) 10-15 02:19:45.351: E/Event(682): at android.support.v4.view.ViewPager.populate(ViewPager.java:1073) 10-15 02:19:45.351: E/Event(682): at android.support.v4.view.ViewPager.populate(ViewPager.java:919) 10-15 02:19:45.351: E/Event(682): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441) 10-15 02:19:45.351: E/Event(682): at android.view.View.measure(View.java:12603) 10-15 02:19:45.351: E/Event(682): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677) 10-15 02:19:45.351: E/Event(682): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293) 10-15 02:19:45.351: E/Event(682): at android.view.View.measure(View.java:12603) 10-15 02:19:45.351: E/Event(682): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677) 10-15 02:19:45.351: E/Event(682): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369) 10-15 02:19:45.351: E/Event(682): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660) 10-15 02:19:45.351: E/Event(682): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553) 10-15 02:19:45.351: E/Event(682): at android.view.View.measure(View.java:12603) 10-15 02:19:45.351: E/Event(682): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677) 10-15 02:19:45.351: E/Event(682): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293) 10-15 02:19:45.351: E/Event(682): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2072) 10-15 02:19:45.351: E/Event(682): at android.view.View.measure(View.java:12603) 10-15 02:19:45.351: E/Event(682): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1044) 10-15 02:19:45.351: E/Event(682): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418) 10-15 02:19:45.351: E/Event(682): at android.os.Handler.dispatchMessage(Handler.java:99) 10-15 02:19:45.351: E/Event(682): at android.os.Looper.loop(Looper.java:137) 10-15 02:19:45.351: E/Event(682): at android.app.ActivityThread.main(ActivityThread.java:4340) 10-15 02:19:45.351: E/Event(682): at java.lang.reflect.Method.invokeNative(Native Method) 10-15 02:19:45.351: E/Event(682): at java.lang.reflect.Method.invoke(Method.java:511) 10-15 02:19:45.351: E/Event(682): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 10-15 02:19:45.351: E/Event(682): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 10-15 02:19:45.351: E/Event(682): at dalvik.system.NativeStart.main(Native Method) 10-15 02:19:45.351: D/Event(682): No subscribers registered for event class de.greenrobot.event.SubscriberExceptionEvent 10-15 02:19:45.551: V/BRRT(682): FourUp event received: 204 : 32 10-15 02:19:45.561: W/ResourceType(682): No package identifier when getting value for resource number 0x00000000
This is a fragment (they look the same):
public class OneUpScreen extends ScreenFragment { private Button name; private TextView c00Title,c00Data; //DEBUG public String title; //DEBUG private int counter = 0; //for logging and convenience private static final String TAG = "BRRT"; @Override public void onResume(){ super.onResume(); EventBus.getDefault().registerSticky(this); } @Override public void onPause(){ EventBus.getDefault().unregister(this); super.onDestroy(); } //process the bus messaging public void onEvent(ExpeditionEvent event){ Log.v(TAG,"OneUp event received: " + event.getEventId() + " : " + event.getEventScreenValue()); c00Data = (TextView) getView().findViewById(R.id.c00Data); c00Data.setText(counter); counter++; } @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { View v = inflater.inflate(R.layout.one_up_screen_layout,container,false); name = (Button) v.findViewById(R.id.lblTitle); c00Title = (TextView) v.findViewById(R.id.c00Title); c00Data = (TextView) v.findViewById(R.id.c00Data); Bundle bundle = this.getArguments(); //initial set up of the text on the screen //null check name.setText((bundle.getString("name") == null) ? "error" : bundle.getString("name")); c00Title.setText((bundle.getString("c00Title") == null) ? "error" : bundle.getString("c00Title")); title = bundle.getString("c00Title"); return v; } public OneUpScreen(){ } public static OneUpScreen newInstance() { OneUpScreen frag = new OneUpScreen(); return frag; } //attach the config for this instance. @Override public void setConfig(ScreenConfig sc){ //set up the data to paint the screen for the first time Bundle b = new Bundle(); //Now we have to parse some stuff into a bundle and send the bundle to the fragment b.putString("name",sc.getName()); b.putString("c00Title",sc.getEvents().get(0).getCleanName()); b.putInt("c00Data",sc.getEvents().get(0).getEventID()); //pass it along this.setArguments(b); } @Override public void update(SparseArray<String> sensorDataMap) { Log.v(TAG,"OneUp Update called: " + counter); counter++; } }
The onevent method is where I look here This method is called if you notice in the log However, I can't click on its internal textview Initially, I just referenced textview in the oncreate () method But I saw an example, you look at it again in event handling, so I turned to that, no luck
If I take out:
c00Data.setText(counter);
Then the valgus effect is very good
What did I miss here?
Solution
Well, for later people here, this is my way to solve this problem
It turns out that the key error I see is not an event - related error, but a resource - related error
10-15 02:19:45.271: W/ResourceType(682): No package identifier when getting value for resource number 0x00000000
I looked at so elsewhere and found this:
No package identifier when getting value for resource number
Then I go back to my code and rewrite textview The settext () call looks different
Old mode (counter is an int):
c00Data.setText(counter);
new method:
c00Data.setText(""+counter);
I did I shouted