当我 运行 我的项目时,为什么 Android Studio 没有将我的最新更改部署到我的设备?
Why does Android Studio not deploy my latest changes to my device when I run my project?
Note:This question is not about how to fix a NullPointerException. This question is about why a piece of code that has been updated still generates a stacktrace in the Android Studio application for an older version.
我有一个 class 检查互联网连接。然而,这个class曾经有一段无效的代码,像这样:
public class InternetConnectivityChecker {
private Context context;
public InternetConnectivityChecker(Context context) {
context = context;
}
我修复了这段代码,将其更改为:
public class InternetConnectivityChecker {
private Context context;
public InternetConnectivityChecker(Context context) {
this.context = context;
}
我不断得到一个堆栈跟踪,粘贴在下面。为了解决这个问题,我决定完全删除 class 的调用。
这个 class 曾经在第 22 行从 SamaWebViewClient
调用。但是,现在它不再被调用了:
public class SamaWebViewClient extends WebViewClient {
private com.sama7.sama.listeners.OnReceivedErrorListener onReceivedErrorListener;
public SamaWebViewClient(com.sama7.sama.listeners.OnReceivedErrorListener listener) {
this.onReceivedErrorListener = listener;
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
onReceivedErrorListener.onReceivedError();
}
}
但是,现在当我 运行 我的代码处于调试模式时,即使我在 Gradle Build
window 中得到 0 个错误和 0 个警告,这就是我在 logcat:
03-02 08:49:29.240 24373-24373/com.sama7.sama E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sama7.sama, PID: 24373
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
at com.sama7.sama.InternetConnectivityChecker.isConnected(InternetConnectivityChecker.java:15)
at com.sama7.sama.SamaWebViewClient.onReceivedError(SamaWebViewClient.java:22)
at com.android.webview.chromium.WebViewContentsClientAdapter.onReceivedError(WebViewContentsClientAdapter.java:582)
at org.chromium.android_webview.AwContentsClient.onReceivedError(AwContentsClient.java:355)
at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:160)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
03-02 08:49:38.015 24373-24373/com.sama7.sama I/Process: Sending signal. PID: 24373 SIG: 9
为什么我没有构建最新的应用程序并将其部署到我的 Samsung Galaxy S5 设备?
对于将来发现此问题的任何人,以下是对我有用的方法。
Turning Instant Run Off
If you need to turn off Instant Run, go to Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run… .
这是 instant run 上的 Android 工具页面的摘录。
Note:This question is not about how to fix a NullPointerException. This question is about why a piece of code that has been updated still generates a stacktrace in the Android Studio application for an older version.
我有一个 class 检查互联网连接。然而,这个class曾经有一段无效的代码,像这样:
public class InternetConnectivityChecker {
private Context context;
public InternetConnectivityChecker(Context context) {
context = context;
}
我修复了这段代码,将其更改为:
public class InternetConnectivityChecker {
private Context context;
public InternetConnectivityChecker(Context context) {
this.context = context;
}
我不断得到一个堆栈跟踪,粘贴在下面。为了解决这个问题,我决定完全删除 class 的调用。
这个 class 曾经在第 22 行从 SamaWebViewClient
调用。但是,现在它不再被调用了:
public class SamaWebViewClient extends WebViewClient {
private com.sama7.sama.listeners.OnReceivedErrorListener onReceivedErrorListener;
public SamaWebViewClient(com.sama7.sama.listeners.OnReceivedErrorListener listener) {
this.onReceivedErrorListener = listener;
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
onReceivedErrorListener.onReceivedError();
}
}
但是,现在当我 运行 我的代码处于调试模式时,即使我在 Gradle Build
window 中得到 0 个错误和 0 个警告,这就是我在 logcat:
03-02 08:49:29.240 24373-24373/com.sama7.sama E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sama7.sama, PID: 24373
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
at com.sama7.sama.InternetConnectivityChecker.isConnected(InternetConnectivityChecker.java:15)
at com.sama7.sama.SamaWebViewClient.onReceivedError(SamaWebViewClient.java:22)
at com.android.webview.chromium.WebViewContentsClientAdapter.onReceivedError(WebViewContentsClientAdapter.java:582)
at org.chromium.android_webview.AwContentsClient.onReceivedError(AwContentsClient.java:355)
at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:160)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
03-02 08:49:38.015 24373-24373/com.sama7.sama I/Process: Sending signal. PID: 24373 SIG: 9
为什么我没有构建最新的应用程序并将其部署到我的 Samsung Galaxy S5 设备?
对于将来发现此问题的任何人,以下是对我有用的方法。
Turning Instant Run Off
If you need to turn off Instant Run, go to Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run… .
这是 instant run 上的 Android 工具页面的摘录。