gpt4 book ai didi

java - Activity 启动后导致应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 02:56:47 26 4
gpt4 key购买 nike

我想先运行“FakeActivity”类而不是“MainActivity”,但每次运行它时它都会崩溃。谁能告诉我为什么每次加载该 Activity 都会崩溃。以下是我的 Java 代码:

package com.example.android.findbar;

import android.location.Location;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class FakeActivity extends AppCompatActivity {

/*Global variables for user's Longitude and User's Latitude*/

EditText Longitude, Latitude;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fake);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Longitude = (EditText)findViewById(R.id.Longitude);
Latitude = (EditText)findViewById(R.id.Latitude);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

}

public void CheckLocation(View view){

String Longi = Longitude.getText().toString();
String Lati = Latitude.getText().toString();
String type = "Locator";
BackgroundWorker backgroundWorker = new BackgroundWorker(this);
backgroundWorker.execute(type, Longi, Lati);
}

}

然后是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="com.example.android.findbar.FakeActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_fake" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

然后是我的 list 文件:

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

<uses-permission android:name="android.permission.INTERNET" />

<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">

</activity>

<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
<activity android:name=".SecondActivity" />

<activity
android:name=".FakeActivity"
android:label="@string/title_activity_fake"
android:theme="@style/AppTheme.NoActionBar">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />

</intent-filter>

</activity>

</application>

</manifest>

日志猫

03-22 13:23:41.923 761-1248/? W/ActivityManager:   Force finishing activity com.example.android.findbar/.FakeActivity
03-22 13:23:42.046 1943-1958/? W/GooglePlayServicesUtil: Google Play services is missing.
03-22 13:23:42.048 761-772/? W/ActivityManager: Unable to start service Intent { act=com.google.android.gms.ads.identifier.service.START pkg=com.google.android.gms } U=0: not found
03-22 13:23:42.134 761-1827/? I/OpenGLRenderer: Initialized EGL, version 1.4
03-22 13:23:42.135 761-1827/? D/OpenGLRenderer: Swap behavior 1
03-22 13:23:42.230 761-783/? I/Choreographer: Skipped 40 frames! The application may be doing too much work on its main thread.
03-22 13:23:42.435 761-776/? W/ActivityManager: Activity pause timeout for ActivityRecord{dfb089c u0 com.example.android.findbar/.FakeActivity t4 f}
03-22 13:23:42.487 761-776/? I/WindowManager: Failed to capture screenshot of Token{52a62a5 ActivityRecord{dfb089c u0 com.example.android.findbar/.FakeActivity t4 f}} appWin=Window{e6b5ad2 u0 Starting com.example.android.findbar} drawState=3
03-22 13:23:42.640 761-783/? I/WindowManager: Destroying surface Surface(name=Starting com.example.android.findbar) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
03-22 13:23:42.932 761-777/? I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread.
03-22 13:23:44.635 761-1248/? W/ActivityManager: Force finishing activity com.example.android.findbar/.FakeActivity
03-22 13:23:44.635 761-1248/? I/ActivityManager: Killing 1943:com.example.android.findbar/u0a63 (adj 900): crash
03-22 13:23:44.667 761-777/? W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
03-22 13:23:44.669 761-1248/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@21574e8 attribute=null, token = android.os.BinderProxy@6d4495
03-22 13:23:45.008 761-783/? I/WindowManager: Destroying surface Surface(name=Application Error: com.example.android.findbar) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementInner:429 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop:232 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement:180 com.android.server.wm.WindowManagerService$H.handleMessage:8079 android.os.Handler.dispatchMessage:102
03-22 13:23:45.010 761-783/? W/AppOps: Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0
03-22 13:23:51.792 482-499/? W/AudioFlinger: write blocked for 10367 msecs, 5 delayed writes, thread 0xf14032c0
03-22 13:25:07.227 485-715/? E/Netd: Failed to dump IPv4 sockets for UID: No such file or directory
03-22 13:25:07.228 761-775/? E/NetworkManagement: Error closing sockets after enabling chain standby: android.os.ServiceSpecificException: destroySockets: No such file or directory
03-22 13:25:38.127 761-809/? W/WifiMode: WiredSSID, Invalid SupportedRates!!!
03-22 13:25:38.128 761-811/? W/WifiMode: WiredSSID, Invalid SupportedRates!!!
03-22 13:25:38.129 761-809/? W/WifiMode: WiredSSID, Invalid SupportedRates!!!
01-01 00:00:00.000 0-0/? E/Internal: device '192.168.63.101:5555' not found

最佳答案

首先,您需要检查您的 SDK 中 Google Play 服务是否可用。因为您的崩溃报告在 Logcat 的第二行中显示“Google Play 服务缺失”错误。

在 Android Studio 中单击:工具 > Android > SDK 管理器 > 启动独立 SDK 管理器。

查找:附加功能 > Google Play 服务。

如果未安装 Google Play 服务,请先安装它,然后再次运行项目。

关于java - Activity 启动后导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959441/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com