Я следую за этим 5-летним курсом Android по Udemy и пытаюсь заставить это приложение работать с текущей версией Android Studio, я до сих пор смог выяснить, как хотя бы сделать его сборку, но теперь, когда я пытаюсь запустить приложение на Genymotion, оно не запускается в первый раз, а когда я запускаю второй раз, я получаю следующее:
and I get this in the "logcat" tab:
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)
And here is the BartalkActivity.java file:
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);
}
}
I noticed that when I just comment out the getActionBar()
bit, then it actually does run, but i assume something does not get "hidden" while using the app.
I've been looking at this whole "getActionBar() returning null" issue, and I keep seeing a bunch of answers, but none of them seem to be working. The most promising one of using getSupportActionBar()
doesn't even work since when i try to build it Android Studio complains it can't find that method.
What would i need to do to get this getActionBar()
method working...?
Update 01
So following совет Габриэле Мариотти , я изменил операторы импорта для использования AppCompatActivity (действительно не знал, как добавить библиотеки поддержки v7 даже после прочтения do c, связанного с Jaipraka sh Soni ). вот как теперь выглядит файл 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);
. почему это?