致命异常:主要(

时间:2018-09-02 13:15:41

标签: android

我正在编写新闻应用程序。该程序从导航抽屉活动开始,我通过xml api新闻对其进行了解析。 该程序在导航栏中仍然有2个片段。 启动应用程序后,它立即崩溃。 Studio不会突出显示代码中的错误……我寻求帮助!

我的MainActivity

package com.example.developer.nasibovtestcityguide;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {
    RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ReadNews readNews = new ReadNews(this, recyclerView);
        readNews.execute();
        recyclerView =(RecyclerView)findViewById(R.id.recyclerview);



        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void displaySelectedScreen (int id) {
        Fragment fragment = null;

        switch (id) {
            case R.id.nav_settings:
                fragment = new Settings();
                break;
            case R.id.nav_program:
                fragment = new About_program();
                break;
        }

        if (fragment != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.content_main, fragment);
            ft.commit();
        }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        displaySelectedScreen(id);
        return true;
    }
}

这是日志中的内容:

09-02 11:00:02.597 7291-7291/com.example.developer.nasibovtestcityguide E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.developer.nasibovtestcityguide, PID: 7291
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.developer.nasibovtestcityguide/com.example.developer.nasibovtestcityguide.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.constraint.RelativeLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.constraint.RelativeLayout
     Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.RelativeLayout
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.RelativeLayout" on path: DexPathList[[zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/base.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_resources_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/lib/x86, /system/lib, /vendor/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:606)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:965)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:995)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
09-02 11:00:02.610 7291-7291/com.example.developer.nasibovtestcityguide E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.example.developer.nasibovtestcityguide.MainActivity.onCreate(MainActivity.java:26)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
        Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.developer.nasibovtestcityguide-kMSTA8DN78AzgfL4CUUTug==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:353)
        at dalvik.system.DexFile.<init>(DexFile.java:100)
        at dalvik.system.DexFile.<init>(DexFile.java:74)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
        at dalvik.system.DexPathList.<init>(DexPathList.java:157)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:676)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:709)
        at android.app.LoadedApk.getResources(LoadedApk.java:936)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2242)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5672)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
                ... 6 more`enter code here`

1 个答案:

答案 0 :(得分:1)

您似乎已更换了

<android.support.constraint.ConstraintLayout

使用

<android.support.constraint.RelativeLayout

在您的xml文件中。您不需要android.support.constraint的前缀RelativeLayout,只需使用

<RelativeLayout