如何删除此 "Execution failed for task ':app:compileDebugJavaWithJavac' " 错误? (带片段的导航视图)

How to remove this "Execution failed for task ':app:compileDebugJavaWithJavac' " error? (Navigation View with fragments)

这是我的带片段的 NavigationView 程序:

package com.example.anubhasharma.assign;


import android.support.v4.app.Fragment;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.FrameLayout;

public class MainActivity extends AppCompatActivity {

public BottomNavigationView mMainNav;
public FrameLayout mMainFrame;

public HomeFragment homeFragment;
public OfferFragment offerFragment;
public ProfileFragment profileFragment;
public HistoryFragment historyFragment;


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

    mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
    mMainNav = (BottomNavigationView) findViewById(R.id.main_nav);

    homeFragment = new HomeFragment();
    offerFragment = new OfferFragment();
    historyFragment = new HistoryFragment();
    profileFragment = new ProfileFragment();

    mMainNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {

            switch (item.getItemId()) {

                case R.id.nav_home :
                    mMainNav.setItemBackgroundResource(R.color.colorRed);
                    setFragment(homeFragment);
                    return true;

                case R.id.nav_profile :
                    mMainNav.setItemBackgroundResource(R.color.colorRed);
                    setFragment(profileFragment);
                    return true;

                case R.id.nav_offer :
                    mMainNav.setItemBackgroundResource(R.color.colorRed);
                    setFragment(offerFragment);
                    return true;

                case R.id.nav_history :
                    mMainNav.setItemBackgroundResource(R.color.colorRed);
                    setFragment(historyFragment);
                    return true;

                default:
                    return false;
                }
            }
        });
    }
}

public void setFragment(Fragment fragment) {


    android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.main_frame, fragment);
    fragmentTransaction.commit();
}

}

但是我遇到了这个错误: 任务“:app:compileDebugJavaWithJavac”执行失败。

Compilation failed; see the compiler error output for details.

这里是build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.anubhasharma.assign"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

此应用之前是 运行。我已经尝试了很多解决方案来消除这个错误。所以请帮助。 谢谢

转到底部的 "Build" 选项卡并检查编译器输出。如果您还没有更新到最新版本的 Android Studio(我使用的是 3.1.2)。然后就可以结构化的看到complier的输出了