0

I followed the documentation and my project appeared to get set up just fine. However, when i run the project The app is displaying the "No Tweets' TextView, not a timeline. My code is basically what was in the doc, just cuz i wanna see it get working first before i do anything else.

Here's my Activity's onCreate:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_social);


    try{
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(this, new Twitter(authConfig));

        final UserTimeline userTimeline = new UserTimeline.Builder()
                .screenName("fabric")
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(this, userTimeline);

        setListAdapter(adapter);
    }catch(Exception ex){

    }

And here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="org.witrackclub.wtc.SocialActivity"
tools:showIn="@layout/activity_social">

<TextView android:id="@id/android:empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal|center_vertical"
    android:text="No Tweets"/>

<ListView android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:divider="#e1e8ed"
    android:dividerHeight="1dp"
    android:drawSelectorOnTop="false"/>

</LinearLayout>

Help would be much appreciated

RunFranks525
  • 163
  • 1
  • 2
  • 14
  • TwitterAuthConfig should be in Application and not in the Activity. And you activity extend of ListActivity? – fechidal89 Feb 06 '16 at 01:49
  • what do you mean by "in Application"? That's just where Fabric injected that code. And yes the Activity extends ListActivity – RunFranks525 Feb 06 '16 at 01:53

1 Answers1

0

Well, I think that is a problem with your keys (consumerKey & consumerSecret).

AndroidManifest.xml

<application
    ...
    android:name="TimeLineFabricApplication"
    ...

The Application: TimeLineFabricApplication.java

import android.app.Application;
import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import io.fabric.sdk.android.Fabric;

public class TimeLineFabricApplication extends Application{

    @Override
    public void onCreate() {
        super.onCreate();

        TwitterAuthConfig authConfig =  new TwitterAuthConfig("consumerKey", "consumerSecret");
        Fabric.with(this, new Twitter(authConfig));
    }
}

The Activity: MainActivity.java

import android.app.ListActivity;
import android.os.Bundle;
import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;

public class MainActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final UserTimeline userTimeline = new UserTimeline.Builder()
            .screenName("fabric")
            .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
            .setTimeline(userTimeline)
            .build();
        setListAdapter(adapter);
    }
}

And the Layout: activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal|center_vertical"
        android:text="No Tweets"/>

    <ListView android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:divider="#e1e8ed"
        android:dividerHeight="1dp"
        android:drawSelectorOnTop="false"/>
</LinearLayout>

My result:

My Result

the keys that helped me was that I found myself in fabric.io of the created application. Are you sure you created an app on Fabric.io with your user?

In the LogCat or AndroidMonitor, You see something like: Failed to get app auth token com.twitter.sdk.android.core.TwitterApiException: 403 Forbidden

fechidal89
  • 723
  • 5
  • 25
  • No, what actually seems to be happening now is the stack trace shows a classNotFound exception java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit/RestAdapter$Builder; – RunFranks525 Feb 09 '16 at 18:58
  • and that happens on this line: final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this) .setTimeline(userTimeline) .build(); so unsure of the issue at the moment – RunFranks525 Feb 09 '16 at 19:16
  • I created another trivial project and It loaded fine, so I think the keys work fine. – RunFranks525 Feb 09 '16 at 20:53
  • see this help with retrofit error: https://github.com/twitter/twitter-kit-android/issues/31. Can you put all code on the question? (editing the question) – fechidal89 Feb 10 '16 at 19:12