我正在开发新闻应用程序,但是我已经实现了新闻应用程序的结构,但出现以下错误
无法执行任务。 java.util.concurrent.TimeoutException 在java.util.concurrent.FutureTask.get(FutureTask.java:206) 在com.crashlytics.android.core.CrashlyticsBackgroundWorker.submitAndWait(CrashlyticsBackgroundWorker.java:41) 在com.crashlytics.android.core.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:321) 在com.crashlytics.android.core.CrashlyticsController $ 6.onUncaughtException(CrashlyticsController.java:301) 在com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:42) 在java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068) 在java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063) 在java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
在我的MainActivity.java下面
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawer;
private Toolbar toolbar;
private NavigationView nvDrawer;
private ActionBarDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set a Toolbar to replace the ActionBar.
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Find our drawer view
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerToggle = setupDrawerToggle();
// Tie DrawerLayout events to the ActionBarToggle
mDrawer.addDrawerListener(drawerToggle);
nvDrawer = (NavigationView) findViewById(R.id.nvView);
// Inflate the header view at runtime
View headerLayout = nvDrawer.inflateHeaderView(R.layout.nav_header);
// We can now look up items within the header if needed
ImageView ivHeaderPhoto = (ImageView) headerLayout.findViewById((R.id.header_image));
ivHeaderPhoto.setImageResource(R.drawable.ic_sportnews);
setupDrawerContent(nvDrawer);
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent, new BBCSportFragment()).commit();
fragmentManager.beginTransaction().replace(R.id.flContent, new FoxSportsFragment()).commit();
fragmentManager.beginTransaction().replace(R.id.flContent, new TalkSportsFragment()).commit();
throw new RuntimeException("This is a crash");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
switch (item.getItemId()) {
case android.R.id.home:
mDrawer.openDrawer(GravityCompat.START);
return true;
}
return super.onOptionsItemSelected(item);
}
private void setupDrawerContent(NavigationView navigationView) {
navigationView.setNavigationItemSelectedListener(
menuItem -> {
selectDrawerItem(menuItem);
return true;
});
}
public void selectDrawerItem(MenuItem menuItem) {
// Create a new fragment and specify the fragment to show based on nav item clicked
Fragment fragment = null;
Class fragmentClass = null;
switch (menuItem.getItemId()) {
case R.id.bbcsports_fragment:
fragmentClass = BBCSportFragment.class;
break;
case R.id.talksports_fragment:
fragmentClass = TalkSportsFragment.class;
break;
case R.id.foxsports_fragment:
fragmentClass = FoxSportsFragment.class;
break;
case R.id.footballitalia_fragment:
fragmentClass = FootballItaliaFragment.class;
break;
case R.id.espn_fragment:
fragmentClass = ESPNFragment.class;
break;
default:
}
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
// Highlight the selected item has been done by NavigationView
menuItem.setChecked(true);
// Set action bar title
setTitle(menuItem.getTitle());
// Close the navigation drawer
mDrawer.closeDrawers();
}
private ActionBarDrawerToggle setupDrawerToggle() {
// NOTE: Make sure you pass in a valid toolbar reference. ActionBarDrawToggle() does not require it
// and will not render the hamburger icon without it.
return new ActionBarDrawerToggle(this, mDrawer, toolbar, R.string.drawer_open, R.string.drawer_close);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggles
drawerToggle.onConfigurationChanged(newConfig);
}
}
在app.gradle下面
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileOptions.incremental = false
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 28
defaultConfig {
applicationId "edgar.yodgorbek.sportnews"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
//noinspection GradleCompatible
implementation 'com.android.support:design:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.jakewharton:butterknife:8.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
implementation 'com.google.dagger:dagger:2.15'
annotationProcessor 'com.google.dagger:dagger-compiler:2.15'
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.10.0'
implementation group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '3.9.0'
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}
低于AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="edgar.yodgorbek.sportnews">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".component.MyApplication"
android:allowBackup="true"
android:appComponentFactory="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:appComponentFactory">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".detail.DetailActivity" />
<meta-data
android:name="io.fabric.ApiKey"
android:value="aa34578052122e6724e8bca9a7766bc012923b95" />
</application>
</manifest>