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

默认的android studio程序在我运行时不起作用

谭浩皛
2023-03-14

我尝试运行一个空的应用程序(hello world的deafult应用程序),当我尝试运行该应用程序时,我得到了错误。

我执行的步骤是:

  • 创建了空项目:
  • 打开了Nexus S API P仿真程序。
  • 按下了运行按钮
  • 等待应用程序自行启动(它立即打开和关闭)
  • 从具有标题的菜单中重新打开应用程序

“MyCollege持续停止”“应用程序信息”“关闭应用程序”

你知道怎么解决这个吗?

这是我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mycollege">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyCollege">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是我的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

这是我的主要活动。java:

package com.example.mycollege;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

这是我在运行中的错误:

03/21 14:17:28: Launching 'app' on Nexus S API P.
App restart successful without requiring a re-install.
$ adb shell am start -n "com.example.mycollege/com.example.mycollege.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 16194 on device 'Nexus_S_API_P [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/ample.mycolleg: The ClassLoaderContext is a special shared library.
W/ample.mycolleg: Accessing hidden field Landroid/view/WindowInsets;->CONSUMED:Landroid/view/WindowInsets; (blacklist, reflection)
I/WindowInsetsCompat: Could not retrieve WindowInsets.CONSUMED field
    java.lang.NoSuchFieldException: No field CONSUMED in class Landroid/view/WindowInsets; (declaration of 'android.view.WindowInsets' appears in /system/framework/framework.jar!classes2.dex)
        at java.lang.Class.getDeclaredField(Native Method)
        at androidx.core.view.WindowInsetsCompat$BuilderImpl20.createWindowInsetsInstance(WindowInsetsCompat.java:1071)
        at androidx.core.view.WindowInsetsCompat$BuilderImpl20.<init>(WindowInsetsCompat.java:1040)
        at androidx.core.view.WindowInsetsCompat$Builder.<init>(WindowInsetsCompat.java:860)
        at androidx.core.view.WindowInsetsCompat.<clinit>(WindowInsetsCompat.java:55)
        at androidx.appcompat.widget.ActionBarOverlayLayout.<init>(ActionBarOverlayLayout.java:101)
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:896)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
        at com.example.mycollege.MainActivity.onCreate(MainActivity.java:12)
        at android.app.Activity.performCreate(Activity.java:7130)
        at android.app.Activity.performCreate(Activity.java:7121)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6649)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
W/ample.mycolleg: Accessing hidden method Landroid/view/WindowInsets;-><init>(Landroid/graphics/Rect;)V (blacklist, reflection)
I/WindowInsetsCompat: Could not retrieve WindowInsets(Rect) constructor
    java.lang.NoSuchMethodException: <init> [class android.graphics.Rect]
        at java.lang.Class.getConstructor0(Class.java:2327)
        at java.lang.Class.getConstructor(Class.java:1725)
        at androidx.core.view.WindowInsetsCompat$BuilderImpl20.createWindowInsetsInstance(WindowInsetsCompat.java:1092)
        at androidx.core.view.WindowInsetsCompat$BuilderImpl20.<init>(WindowInsetsCompat.java:1040)
        at androidx.core.view.WindowInsetsCompat$Builder.<init>(WindowInsetsCompat.java:860)
        at androidx.core.view.WindowInsetsCompat.<clinit>(WindowInsetsCompat.java:55)
        at androidx.appcompat.widget.ActionBarOverlayLayout.<init>(ActionBarOverlayLayout.java:101)
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:896)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
        at com.example.mycollege.MainActivity.onCreate(MainActivity.java:12)
        at android.app.Activity.performCreate(Activity.java:7130)
        at android.app.Activity.performCreate(Activity.java:7121)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6649)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.mycollege, PID: 16194
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mycollege/com.example.mycollege.MainActivity}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class androidx.appcompat.widget.ActionBarOverlayLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6649)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
     Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class androidx.appcompat.widget.ActionBarOverlayLayout
     Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class androidx.appcompat.widget.ActionBarOverlayLayout
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:896)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
        at com.example.mycollege.MainActivity.onCreate(MainActivity.java:12)
        at android.app.Activity.performCreate(Activity.java:7130)
        at android.app.Activity.performCreate(Activity.java:7121)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6649)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
     Caused by: java.lang.ExceptionInInitializerError
        at androidx.appcompat.widget.ActionBarOverlayLayout.<init>(ActionBarOverlayLayout.java:101)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:647) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:896) 
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:693) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170) 
        at com.example.mycollege.MainActivity.onCreate(MainActivity.java:12) 
        at android.app.Activity.performCreate(Activity.java:7130) 
        at android.app.Activity.performCreate(Activity.java:7121) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6649) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826) 
     Caused by: java.lang.NullPointerException
        at androidx.core.util.Preconditions.checkNotNull(Preconditions.java:64)
        at androidx.core.view.WindowInsetsCompat.toWindowInsetsCompat(WindowInsetsCompat.java:113)
        at androidx.core.view.WindowInsetsCompat$BuilderImpl20.build(WindowInsetsCompat.java:1058)
        at androidx.core.view.WindowInsetsCompat$Builder.build(WindowInsetsCompat.java:996)
        at androidx.core.view.WindowInsetsCompat.<clinit>(WindowInsetsCompat.java:56)
            ... 29 more

我使用了带有“空activity”模板的Android Studio 4.1.3

共有1个答案

颛孙正卿
2023-03-14

null

这里有件事你可以做

  1. 检查activity_main.xml中第17行的内容,尝试移除该组件或该特定行,看看是否有效。
  2. 确保应用程序的主题继承自theme.AppCompat。
 类似资料:
  • 我是Android Studio的新手。我现在使用它是希望获得一些错误消息,以解释为什么我的APK不能在蓝色堆栈中运行。APK是在Unity中建造的。 在安装了Android Studio,一个手机模拟器等之后,我仍然无法运行apk。它说: 在堆栈溢出中已经有一个关于这个错误的帖子。但是,我的AndroidManifest.xml在我看来很好。我也尝试过‘无效缓存/重新启动’但没有效果。当我转到“

  • 下面是我用raspberry PI的python(Thonny Idle)编写的代码。 请忽略Url,它不是真实地址。密码 错误 回溯(最近一次呼叫最后一次): 文件“/home/pi/Documents/PythonCode/TestingFirebase-1.py”,第17行,在 文件“/usr/local/lib/python3.7/dist-packages/firebase/decora

  • 我的Android应用3年后就可以使用了。我定期更新。 它包含一些视图上的动画,我使用MPAndroidChart库。大约2个月以来,当我从Android Studio(在真实设备或仿真设备上)启动我的应用程序时,动画图表工作正常,但当我从Play Store下载应用程序时,这些动画不再工作了!这很奇怪!! 使用的方法是ObjectAnimator.start()。 有人已经有这个问题了吗? 谢谢

  • 按下开始按钮后,它运行程序,但它不允许我使用右下角的退出按钮,我不知道为什么它会这样做。有人能帮忙吗。我希望它继续运行该程序,但仍然允许我使用该按钮,因此,如果我想中途退出,它将允许我。项目描述:“对于我的项目,我将使用python创建一个随机迷宫生成软件。我将创建一个网格呈现给用户。该软件将从左上角开始,然后创建迷宫,沿随机方向运行,最后在右下角结束。”

  • 我有一个maven项目,我在其中使用了spring数据和JPA(hibernate)。并通过XML进行配置。envers的默认架构已更改。但它不起作用。当我看到DDL输出时,它说: 错误组织。冬眠工具hbm2ddl。方案更新-HH000388:不成功:更改表格退伍军人。USERPROFILE_ROLE_AUD add constraint FK_nbpfx0RJC9HQIIV4VOFP82KC外键

  • 我正在写一个程序,显示如下所示的航班信息: 我的问题是使用方法时: 当正常运行时,由于某种原因它不会执行,但是当我使用调试器执行程序时,一切都执行得很好,我得到了一个有意义的输出(格式不是很好,但我可以使用),为什么会发生这种情况? 输出应该是这样的: 当我正常运行时,我会得到这个: 这是当我一步虽然(或运行调试): 我希望输出的是单步执行部分(稍后我将处理格式化) eddit:我已经在错误流中添