首页 > 解决方案 > Android Studio getActionBar() 返回 null?

问题描述

我在 Udemy 上关注这个 5 年历史的 Android 课程,并试图让这个应用程序在当前的 Android Studio 版本上运行,到目前为止,我已经能够弄清楚如何至少让它构建,但是现在当我尝试运行Genymotion上的应用程序第一次没有运行,当我第二次运行时,我得到了这个:

在此处输入图像描述

我在“logcat”选项卡中得到这个:

2020-07-08 22:41:34.665 2198-2198/? I/Zygote: seccomp disabled by setenforce 0
2020-07-08 22:41:34.666 2198-2198/? I/lta_bartalk_ne: Late-enabling -Xcheck:jni
2020-07-08 22:41:34.690 2198-2198/? W/lta_bartalk_ne: Unexpected CPU variant for X86 using defaults: x86
2020-07-08 22:41:34.814 2198-2223/com.example.delta_bartalk_new D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2020-07-08 22:41:34.809 2198-2198/com.example.delta_bartalk_new I/com.example.delta_bartalk_new: type=1400 audit(0.0:670): avc: denied { write } for comm=45474C20496E6974 name="property_service" dev="tmpfs" ino=10316 scontext=u:r:untrusted_app:s0:c70,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=1
2020-07-08 22:41:34.809 2198-2198/com.example.delta_bartalk_new I/com.example.delta_bartalk_new: type=1400 audit(0.0:671): avc: denied { connectto } for comm=45474C20496E6974 path="/dev/socket/property_service" scontext=u:r:untrusted_app:s0:c70,c256,c512,c768 tcontext=u:r:init:s0 tclass=unix_stream_socket permissive=1
2020-07-08 22:41:34.815 2198-2223/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libGLES_emulation.so from current namespace instead of sphal namespace.
2020-07-08 22:41:34.818 2198-2223/com.example.delta_bartalk_new E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found
2020-07-08 22:41:34.818 2198-2223/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libEGL_emulation.so from current namespace instead of sphal namespace.
2020-07-08 22:41:34.841 2198-2223/com.example.delta_bartalk_new D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-07-08 22:41:34.842 2198-2223/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libGLESv1_CM_emulation.so from current namespace instead of sphal namespace.
2020-07-08 22:41:34.856 2198-2223/com.example.delta_bartalk_new D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-07-08 22:41:34.866 2198-2198/com.example.delta_bartalk_new W/lta_bartalk_ne: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2020-07-08 22:41:34.889 2198-2223/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libGLESv2_emulation.so from current namespace instead of sphal namespace.
2020-07-08 22:41:34.891 2198-2223/com.example.delta_bartalk_new D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-07-08 22:41:34.894 2198-2198/com.example.delta_bartalk_new D/AndroidRuntime: Shutting down VM
    
    
    --------- beginning of crash
2020-07-08 22:41:34.895 2198-2198/com.example.delta_bartalk_new E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.delta_bartalk_new, PID: 2198
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.delta_bartalk_new/com.delta.bartalk_new.BartalkActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.hide()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        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:858)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.hide()' on a null object reference
        at com.delta.bartalk_new.BartalkActivity.onCreate(BartalkActivity.java:81)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        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:858) 

这是BartalkActivity.java文件:

package com.delta.bartalk_new;

import com.delta.bartalk_new.util.SystemUiHider;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 *
 * @see SystemUiHider
 */

public class BartalkActivity extends Activity {
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * If set, will toggle the system UI visibility upon interaction. Otherwise,
     * will show the system UI visibility upon interaction.
     */
    private static final boolean TOGGLE_ON_CLICK = true;

    /**
     * The flags to pass to {@link SystemUiHider#getInstance}.
     */
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

    /**
     * The instance of the {@link SystemUiHider} for this activity.
     */
    private SystemUiHider mSystemUiHider;

    //
// Bartalk instance variables
//
    TextView mOutputText;
    EditText mInputText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_bartalk);

//
// Bartalk code
//
        mOutputText = (TextView) findViewById(R.id.fullscreen_content);
        mInputText= (EditText) findViewById(R.id.input_text);

        mInputText.addTextChangedListener(new TextWatcher(){
            public void afterTextChanged(Editable s) {}
            public void beforeTextChanged(CharSequence s, int start, int count, int after){}
            public void onTextChanged(CharSequence s, int start, int before, int count){
                mOutputText.setText(mInputText.getText());
            }
        });

        ActionBar actionBar = getActionBar();
        actionBar.hide();

        final View controlsView = findViewById(R.id.fullscreen_content_controls);
        final View contentView = findViewById(R.id.fullscreen_content);

// Set up an instance of SystemUiHider to control the system UI for
// this activity.
        mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                    // Cached values.
                    int mControlsHeight;
                    int mShortAnimTime;

                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
// If the ViewPropertyAnimator API is available
// (Honeycomb MR2 and later), use it to animate the
// in-layout UI controls at the bottom of the
// screen.
                            if (mControlsHeight == 0) {
                                mControlsHeight = controlsView.getHeight();
                            }
                            if (mShortAnimTime == 0) {
                                mShortAnimTime = getResources().getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView.animate()
                                    .translationY(visible ? 0 : mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        } else {
// If the ViewPropertyAnimator APIs aren’t
// available, simply show or hide the in-layout UI
// controls.
                            controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
                        }

                        if (visible && AUTO_HIDE) {
// Schedule a hide().
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });

// Set up the user interaction to manually show or hide the system UI.
        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (TOGGLE_ON_CLICK) {
                    mSystemUiHider.toggle();
                } else {
                    mSystemUiHider.show();
                }
            }
        });

// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
        findViewById(R.id.input_text).setOnTouchListener(mDelayHideTouchListener);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
        delayedHide(100);
    }


    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }

            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    /**
     * Schedules a call to hide() in [delay] milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

我注意到,当我只是注释掉该getActionBar()位时,它确实会运行,但我认为在使用该应用程序时某些内容不会“隐藏”。

我一直在研究整个“getActionBar() 返回 null”问题,并且一直看到一堆答案,但似乎没有一个有效。最有希望的使用方法getSupportActionBar()甚至不起作用,因为当我尝试构建它时,Android Studio 抱怨它找不到该方法。

我需要做什么才能使这种getActionBar()方法起作用...?

更新 01 因此,按照Gabriele Mariotti 的建议,我将导入语句更改为使用 AppCompatActivity(即使在阅读了Jaiprakash Soni链接的文档后,也不知道如何添加 v7 支持库)。这就是BartalkActivity.java文件现在的样子:

package com.delta.bartalk_new;

import com.delta.bartalk_new.util.SystemUiHider;

import android.annotation.TargetApi;
//import android.app.ActionBar;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
//import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 *
 * @see SystemUiHider
 */

public class BartalkActivity extends AppCompatActivity {
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * If set, will toggle the system UI visibility upon interaction. Otherwise,
     * will show the system UI visibility upon interaction.
     */
    private static final boolean TOGGLE_ON_CLICK = true;

    /**
     * The flags to pass to {@link SystemUiHider#getInstance}.
     */
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

    /**
     * The instance of the {@link SystemUiHider} for this activity.
     */
    private SystemUiHider mSystemUiHider;

    //
// Bartalk instance variables
//
    TextView mOutputText;
    EditText mInputText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_bartalk);

//
// Bartalk code
//
        mOutputText = (TextView) findViewById(R.id.fullscreen_content);
        mInputText= (EditText) findViewById(R.id.input_text);

        mInputText.addTextChangedListener(new TextWatcher(){
            public void afterTextChanged(Editable s) {}
            public void beforeTextChanged(CharSequence s, int start, int count, int after){}
            public void onTextChanged(CharSequence s, int start, int before, int count){
                mOutputText.setText(mInputText.getText());
            }
        });

        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();

        final View controlsView = findViewById(R.id.fullscreen_content_controls);
        final View contentView = findViewById(R.id.fullscreen_content);

// Set up an instance of SystemUiHider to control the system UI for
// this activity.
        mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                    // Cached values.
                    int mControlsHeight;
                    int mShortAnimTime;

                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
// If the ViewPropertyAnimator API is available
// (Honeycomb MR2 and later), use it to animate the
// in-layout UI controls at the bottom of the
// screen.
                            if (mControlsHeight == 0) {
                                mControlsHeight = controlsView.getHeight();
                            }
                            if (mShortAnimTime == 0) {
                                mShortAnimTime = getResources().getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView.animate()
                                    .translationY(visible ? 0 : mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        } else {
// If the ViewPropertyAnimator APIs aren’t
// available, simply show or hide the in-layout UI
// controls.
                            controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
                        }

                        if (visible && AUTO_HIDE) {
// Schedule a hide().
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });

// Set up the user interaction to manually show or hide the system UI.
        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (TOGGLE_ON_CLICK) {
                    mSystemUiHider.toggle();
                } else {
                    mSystemUiHider.show();
                }
            }
        });

// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
        findViewById(R.id.input_text).setOnTouchListener(mDelayHideTouchListener);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
        delayedHide(100);
    }


    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }

            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    /**
     * Schedules a call to hide() in [delay] milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

但现在它给了我同样的“不断停止”错误,但在 logcat 中得到了一个不同的错误:

2020-07-09 10:35:50.719 2135-2135/? I/Zygote: seccomp disabled by setenforce 0
2020-07-09 10:35:50.721 2135-2135/? I/lta_bartalk_ne: Late-enabling -Xcheck:jni
2020-07-09 10:35:50.751 2135-2135/? W/lta_bartalk_ne: Unexpected CPU variant for X86 using defaults: x86
2020-07-09 10:35:50.912 2135-2160/com.example.delta_bartalk_new D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2020-07-09 10:35:50.909 2135-2135/com.example.delta_bartalk_new I/com.example.delta_bartalk_new: type=1400 audit(0.0:718): avc: denied { write } for comm=45474C20496E6974 name="property_service" dev="tmpfs" ino=9292 scontext=u:r:untrusted_app:s0:c70,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=1
2020-07-09 10:35:50.915 2135-2160/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libGLES_emulation.so from current namespace instead of sphal namespace.
2020-07-09 10:35:50.921 2135-2160/com.example.delta_bartalk_new E/libEGL: load_driver(/vendor/lib/egl/libGLES_emulation.so): dlopen failed: library "/vendor/lib/egl/libGLES_emulation.so" not found
2020-07-09 10:35:50.921 2135-2160/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libEGL_emulation.so from current namespace instead of sphal namespace.
2020-07-09 10:35:50.943 2135-2160/com.example.delta_bartalk_new D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-07-09 10:35:50.944 2135-2160/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libGLESv1_CM_emulation.so from current namespace instead of sphal namespace.
2020-07-09 10:35:50.950 2135-2160/com.example.delta_bartalk_new D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-07-09 10:35:50.982 2135-2135/com.example.delta_bartalk_new D/AndroidRuntime: Shutting down VM
2020-07-09 10:35:50.985 2135-2135/com.example.delta_bartalk_new E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.delta_bartalk_new, PID: 2135
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.delta_bartalk_new/com.delta.bartalk_new.BartalkActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        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:858)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:696)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:552)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.delta.bartalk_new.BartalkActivity.onCreate(BartalkActivity.java:66)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        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:858) 
2020-07-09 10:35:50.992 2135-2160/com.example.delta_bartalk_new D/vndksupport: Loading /vendor/lib/egl/libGLESv2_emulation.so from current namespace instead of sphal namespace.
2020-07-09 10:35:50.994 2135-2160/com.example.delta_bartalk_new D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so

所以现在它在抱怨setContentView(R.layout.activity_bartalk);。为什么是这样?

标签: javaandroidandroid-studio

解决方案


在更仔细地检查了 logcat 输出后,我注意到了一些关于 AppCompat 主题的东西,进一步查找,发现了这张票: 如何修复:“你需要在这个活动中使用 Theme.AppCompat 主题(或后代)”

在遵循此操作并在 values/colors.xml 中添加我自己的文本颜色之后,我能够在 Genymotion 中正确加载。感谢Gabriele Mariotti为我提供使用AppCompatActivity.


推荐阅读