Andorid - crash when creating CompactTweetView


#1

Hi,

I’ve integrated Fabric, with Twitter & TweetUI enabled, in my android App.
The integration with Twitter work, I can authenticate the user and search tweets, but I can’t get the TweetView or CompactTweetView to work. Each time I instantiate a new View the app crashes with “java.lang.IllegalArgumentException: MetricsManager may not be null”.

Could you help me?

Thank you very much.

Here the complete stack crash stack trace:
at com.twitter.sdk.android.tweetui.internal.TweetViewMetric.(TweetViewMetric.java:30)
at com.twitter.sdk.android.tweetui.BaseTweetView.getTweetViewMetric(BaseTweetView.java:355)
at com.twitter.sdk.android.tweetui.BaseTweetView.initComponents(BaseTweetView.java:347)
at com.twitter.sdk.android.tweetui.BaseTweetView.(BaseTweetView.java:135)
at com.twitter.sdk.android.tweetui.BaseTweetView.(BaseTweetView.java:115)
at com.twitter.sdk.android.tweetui.CompactTweetView.(CompactTweetView.java:23)
at com.laser.twitter.TweetsFragment$2.success(TweetsFragment.java:129)
at com.twitter.sdk.android.core.Callback.success(Callback.java:23)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)


#2

Can you share your Fabric.with call and how you’re initializing the CompactTweetView please?


#3

I am also facing the same issue.


#4

I’m initializing Fabric with the following parameters:

TwitterAuthConfig authConfig = new TwitterAuthConfig("...","...");
 Fabric.with(this, new Twitter(authConfig), new TweetUi(), new Crashlytics());

I was able to partially solve the problem by adding the "Direct message"permissione in the App definition of Twitter website.
The problem still occurs randomly sometime at startup, when the main activity starts. When the Main activity is created the App:

  1. Requests a session (logged or quest)
  2. Search tweets by hash tag
  3. Show the tweets in UI with tweet compact view.
    Sometime the “java.lang.IllegalArgumentException: MetricsManager may not be null” is thrown, if I catch it and retry a little bit later everything works.

#5

Reference to crash issue of CompactTweetView

CustomListAdaper extends BaseAdapter
than looking at
function getview{

It’s crashing each and everytime.

}

public class CustomTweetListAdapter extends BaseAdapter {
Context mContext;
private List<Tweet> data;
public CustomTweetListAdapter(Context context, List<Tweet> data) {
this.mContext = context;
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Tweet getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Tweet tweet = getItem(position);

if (convertView == null) {
convertView = View.inflate(mContext, R.layout.tweet_item, null);
ViewHolder holder = new ViewHolder(convertView);
CompactTweetView tweetView = new CompactTweetView(mContext,
tweet);
holder.layout_TweetContainer.addView(tweetView);
});
}
return convertView;
}
class ViewHolder {
FrameLayout layout_TweetContainer;
public ViewHolder(View view) {
layout_TweetContainer = (FrameLayout) view.findViewById(R.id.my_tweet_layout);
view.setTag(this);
}
}
}

> While we are fetching tweet again using tweetid , seems system is not crashing anymore but in this scenario we are fetching data twice, serious loss of optimization.

Here is code snapshot;

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Tweet tweet = getItem(position);
if (convertView == null) {
convertView = View.inflate(mContext, R.layout.tweet_item, null);
final ViewHolder holder = new ViewHolder(convertView);
TweetUtils.loadTweet(tweet.id, new LoadCallback<Tweet>() {
@Override
public void success(Tweet tweet) {
CompactTweetView tweetView = new CompactTweetView(mContext,
tweet);
holder.layout_TweetContainer.addView(tweetView);
}
@Override
public void failure(TwitterException exception) {
// Toast.makeText(...).show();
}
});
}
return convertView;
}**

#6

Thank you for the report. This issue has been resolved in Twitter 1.3.2 (TweetUi 1.0.7 if you use just TweetUi) and these new artifacts are now available.

This issue was introduced in Twitter 1.3.1 (TweetUi 1.06) and could result from a race if a TweetView or CompactTweetView was rendered immediately after starting the kit.


#7

Great work twitter fabric development team.


#8