当前位置: 首页 > 知识库问答 >
问题:

代码不是在Kitkat版本上运行的,而是在Lollipop或更高的平台上运行的

邹缪文
2023-03-14

代码不在kitkat平台上运行。但当它运行在lollipop或更高的平台上时,它不会出现任何错误

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)

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个答案

宰父劲
2023-03-14

如果运行堆栈跟踪的原因,您可以看到它无法加载NavigationView。

试着倒读stacktrace的原因,以更好地了解原因。

1)原因:Android.View.InflateException:二进制XML文件第18行:inflating类ImageView时出错。

2)原因:java.lang.Reflect.InvocationTargetException

3)原因:Android.View.InflateException:二进制XML文件第16行:inflating类Android.Support.Design.Widget.NavigationView时出错

这使我认为,在NavigationView中,它试图加载一个不存在或ID不正确的imageview。

我还假设它发生在通货膨胀期间,与app:headerlayout=“@layout/nav_header_main_list”有关。

检查您的nav_header_main_list资源以查找ID不正确的imageview。

 类似资料:
  • 我创建了一个测试项目(maven)来测试REST API的性能。我正在使用Jeter插件 这是我的pom片段 我有一个Jenkins文件在我的项目像这样 当我触发Jenkins上的构建时,构建成功了,我在控制台输出中看到了这一点 问题是,它什么也做不了。Performace趋势图没有显示任何东西。 如果我在本地机器上运行相同的项目,它工作得非常好。我在日志中看到类似的东西,证实了这一点。生成的输出

  • 案例1: 使用时: 获取异常: 看到的超文本标记语言套件异常:java.lang.RuntimeException:java.lang.RuntimeException: GoogleChrome在路径中找不到!请将包含“chrome.exe”或“google-chrome”或“GoogleChrome”的目录添加到您的PATH环境可用,或显式指定GoogleChrome路径,如下所示:*goog

  • 首先也是最重要的是,我对Java知之甚少,对SWT更是知之甚少,所以我就到此为止。今天早些时候,我试着运行我在上找到的这个简单程序https://mkyong.com/swt/swt-hello-world-example 以下是代码: 当我运行它时,会出现以下错误: 我从中了解到的是,SWT正在用Java11编译,而它应该用Java8编译,但是——这是一个很大的BUT——我没有Java11我删除

  • 我被要求连接到公司大型机上的Db2数据库。我得到了主机名、端口号和数据库。我能够使用Java和IBM JDK版本1.8以及Db2 Universal JDBC驱动程序成功地连接到它。现在我已经连接到它,我如何找出什么是下面躺着的大型机平台。哪里是z/OS、OS/400还是VSE?是否有任何SQL查询可以获得该平台信息?另外,如何找出DB2的版本?

  • 我正在尝试学习适用于Android的OpenGL ES 1.0。我的应用程序运行良好,直到今天早上我将设备升级到Android 5.0.1,Lollipop。我最初尝试调试这个问题很快发现我的应用程序仍然可以在运行KitKat的模拟器上运行,但在我的设备和模拟器上的Lollipop上崩溃。 我的应用程序使用OpenGL绘制了一个简单的立方体,每边都有不同的纹理。我已经将它故障处理到它在glDraw

  • 问题内容: 我正在运行Jenkins pipline(在Jenkins v2.58上),并且正在尝试使生成版本在从属服务器而非主服务器上运行。但是,无论我在Jenkinsfile中尝试使用哪种魔术,Jenkins都可以在master上运行。 如何指定从执行器? 这是我的玩具Jenkinsfile,如果有帮助的话: 问题答案: 正确的语法似乎是: 另外,请确保您的主机正在运行。