代码未在Kitkat版本上运行,但适用于Lollipop或更高版本的平台

时间:2017-11-27 01:09:22

标签: android

代码未在kitkat平台上运行。但是当它在棒棒糖或更高的平台上运行时,它运行时没有任何错误 这是代码

package com.digroof.whatslinkshare;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
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;
import android.widget.Button;
import android.widget.Toast;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Main_list extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {
     Button b1,b2,b3,b4;

     @RequiresApi(api = Build.VERSION_CODES.KITKAT)
      @Override
      protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) 
    findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
           Intent myIntent=new Intent(Intent.ACTION_SEND);
            myIntent.setType("text/plain");
            String shareBody= "null";
            String sharesub="null";
            myIntent.putExtra(Intent.EXTRA_SUBJECT,shareBody);
            myIntent.putExtra(Intent.EXTRA_TEXT,sharesub);
            startActivity(Intent.createChooser(myIntent,"Share Using"));
        }
    });

    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.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) 
    findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    b1=(Button)findViewById(R.id.button9);
    b2=(Button)findViewById(R.id.button10);
    b3=(Button)findViewById(R.id.button11);
    b4=(Button)findViewById(R.id.button12);
    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i=new Intent(Main_list.this,Discord_main.class);
            startActivity(i);
        }
    });
    b2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i=new Intent(Main_list.this,MainActivity.class);
            startActivity(i);
        }
    });
    b3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i=new Intent(Main_list.this,Facebook_main.class);
            startActivity(i);
        }
    });
    b4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i=new Intent(Main_list.this,Telegram_main.class);
            startActivity(i);
        }
    });

    }


   @Override
    public void onBackPressed() {
    Intent i=new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
    finish();
    System.exit(0);
     }

    @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_list, 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.about_id) {
        Intent i=new Intent(this,about_Activity.class);
        startActivity(i);
    }

    return super.onOptionsItemSelected(item);
  }

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

    if (id == R.id.nav_addgroup) {
        Intent i=new Intent(Main_list.this,Usr_add.class);
        startActivity(i);
    }   if (id == R.id.nav_refresh) {
        Toast.makeText(this, "Content View Refreshed Successful", 
        Toast.LENGTH_SHORT).show();

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
      }
     }

activity_main_list.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main_list"
    app:menu="@menu/activity_main_list_drawer" />

    </android.support.v4.widget.DrawerLayout>

content_main_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.digroof.whatslinkshare.Main_list"
tools:showIn="@layout/app_bar_main_list">

    <Button
    android:id="@+id/button9"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button10"
    android:layout_alignParentBottom="true"
    android:layout_alignStart="@+id/button10"
    android:layout_marginBottom="163dp"
    android:text="DISCORD"
    tools:layout_editor_absoluteX="147dp"
    tools:layout_editor_absoluteY="128dp" />

    <Button
    android:id="@+id/button10"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button11"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="60dp"
    android:text="WHATSAPP"
    tools:layout_editor_absoluteX="147dp"
    tools:layout_editor_absoluteY="128dp" />

    <Button
    android:id="@+id/button11"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button12"
    android:layout_alignLeft="@+id/button12"
    android:layout_alignStart="@+id/button12"
    android:layout_marginBottom="64dp"
    android:text="FACEBOOK"
    tools:layout_editor_absoluteX="147dp"
    tools:layout_editor_absoluteY="128dp" />

<Button
    android:id="@+id/button12"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button9"
    android:layout_alignLeft="@+id/button9"
    android:layout_alignStart="@+id/button9"
    android:layout_marginBottom="18dp"
    android:text="TELEGRAM"
    tools:layout_editor_absoluteX="147dp"
    tools:layout_editor_absoluteY="128dp" />
    </RelativeLayout>

在kitkat平台上发布后,显示错误

FATAL EXCEPTION: main
                                               Process: com.digroof.whatslinkshare, PID: 26627
                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.digroof.whatslinkshare/com.digroof.whatslinkshare.Main_list}: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                                                   at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:136)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:515)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                   at dalvik.system.NativeStart.main(Native Method)
                                                Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                   at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                   at com.digroof.whatslinkshare.Main_list.onCreate(Main_list.java:32)
                                                   at android.app.Activity.performCreate(Activity.java:5231)
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                   at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:136) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:515) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                   at dalvik.system.NativeStart.main(Native Method) 
                                                Caused by: java.lang.reflect.InvocationTargetException
                                                   at java.lang.reflect.Constructor.constructNative(Native Method)
                                                   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                   at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                   at com.digroof.whatslinkshare.Main_list.onCreate(Main_list.java:32) 
                                                   at android.app.Activity.performCreate(Activity.java:5231) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                   at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:136) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:515) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                   at dalvik.system.NativeStart.main(Native Method) 
                                                Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class ImageView
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                   at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:211)
                                                   at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:269)
                                                   at android.support.design.widget.NavigationView.<init>(NavigationView.java:178)
                                                   at android.support.design.widget.NavigationView.<init>(NavigationView.java:100)
                                                   at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                   at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                   at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                   at com.digroof.whatslinkshare.Main_list.onCreate(Main_list.java:32) 
                                                   at android.app.Activity.performCreate(Activity.java:5231) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                   at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                   at android.os.Looper.loop(Looper.java:136) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:515) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                   at dalvik.system.NativeStart.main(Native Method) 
                                                Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0200ad
                                                   at android.content.res.Resources.getValue(Resources.java:1123)
                                                   at android.support.v7.widget.ResourcesWrapper.getValue(ResourcesWrapper.java:204)
                                                   at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:332)
                                                   at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
                                                   at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
                                                   at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
                                                   at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:54)
                                                   at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:66)
                                                   at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)

gradle info

android {     compileSdkVersion 25     buildToolsVersion“26.0.2”     defaultConfig {         applicationId“com.digroof.whatslinkshare”         minSdkVersion 16         targetSdkVersion 25         versionCode 1         versionName“1.0”         testInstrumentationRunner“android.support.test.runner.AndroidJUnitRunner”         vectorDrawables.useSupportLibrary = true     }

1 个答案:

答案 0 :(得分:0)

要从Kitkat版本中删除错误,您需要将以下依赖项添加到app level build.gradle。

compile&#39; com.android.support:design:23.1.1&#39;

请将与23.1.1相同的版本与其他Android依赖项放在一起。