Android:Fabric用户时间线不工作
我遵循文档,我的项目似乎设置得很好。然而,当我运行该项目时,应用程序显示的是“无推特”文本视图,而不是时间线。我的代码基本上就是文档中的代码,只是因为我想先看到它开始工作,然后再做其他事情 以下是我的活动onCreate:Android:Fabric用户时间线不工作,android,twitter-fabric,Android,Twitter Fabric,我遵循文档,我的项目似乎设置得很好。然而,当我运行该项目时,应用程序显示的是“无推特”文本视图,而不是时间线。我的代码基本上就是文档中的代码,只是因为我想先看到它开始工作,然后再做其他事情 以下是我的活动onCreate: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_social);
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){
}
这是我的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>
非常感谢您的帮助好吧,我想这是您的钥匙有问题(consumerKey&ConsumerCret) AndroidManifest.xml
<application
...
android:name="TimeLineFabricApplication"
...
活动: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);
}
}
布局: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>
我的结果是:
帮助我的关键是我发现自己在创建的应用程序的fabric.io中。你确定你与你的用户在fabric.io上创建了应用程序吗
在LogCat或AndroidMonitor中,您会看到类似这样的内容:无法获取应用程序身份验证令牌com.twitter.sdk.android.core.TwitterApiException:403禁止TwitterAuthConfig应该在应用程序中,而不是在活动中。您还可以扩展ListActivity的活动?您所说的“在应用程序中”是什么意思"? 这正是Fabric注入代码的地方。是的,活动扩展了ListActivityNo,现在实际发生的是堆栈跟踪显示classNotFound异常java.lang.NoClassDefFoundError:解析失败:Lretrofit/RestAdapter$Builder;这发生在这一行:final TweetTimelineListAdapter=new TweetTimelineListAdapter.Builder(this).setTimeline(userTimeline.build();因此,目前还不确定这个问题。我创建了另一个平凡的项目,它加载得很好,所以我认为这些键工作得很好。请参阅此帮助,了解改装错误:。你能把所有的密码都写在这个问题上吗?(编辑问题)
<?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>