我一直在努力创建一个月的Android应用。每次我试图运行应用程序时都会崩溃。我很难阅读LogCat并了解它实际上对我说的内容。所以,我创建了一个新项目,并从developers.android.com复制了一些代码并尝试运行它,同样的事情发生了。我认为这是虚拟设备,所以我查了解其中的东西,我发现它说我应该配置SD卡存储。所以我也这样做了。我仍然有同样的问题,无法运行应用程序!我还在手机中启用了开发人员选项以及未知来源选项。我只有两个活动(MainActivity和Main2Activity)
MainActivity.java文件中没有代码,并且.xml文件中没有任何内容与它们相关联。我正在尝试进行向上导航功能,这就是正在发生的事情。
当我在虚拟设备中调试应用程序时,这是LogCat的输出。如果我运行应用程序而不是调试它,我有更多的错误,但我不能发布它,因为它超过了最大字符数:
02-02 20:58:53.710 15712-15712/? E/memtrack: Couldn't load memtrack module (No such file or directory)
02-02 20:58:53.710 15712-15712/? E/android.os.Debug: failed to load memtrack module: -2
02-02 20:58:53.740 1299-1332/system_process E/InputDispatcher: channel '1219634a com.jetlabb.thegoods/com.jetlabb.thegoods.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
02-02 20:58:54.500 15738-15738/? E/memtrack: Couldn't load memtrack module (No such file or directory)
02-02 20:58:54.500 15738-15738/? E/android.os.Debug: failed to load memtrack module: -2
02-02 20:58:54.540 940-940/? E/EGL_emulation: tid 940: eglCreateSyncKHR(1237): error 0x3004 (EGL_BAD_ATTRIBUTE)
02-02 20:58:54.680 15748-15755/? E/art: Failed writing handshake bytes (-1 of 14): Broken pipe
02-02 21:01:16.030 1575-1595/com.google.android.gms.persistent E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'end' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at java.util.zip.Inflater.<init>(Inflater.java:82)
at com.android.okio.GzipSource.<init>(GzipSource.java:57)
at com.android.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:478)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:668)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:379)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:491)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:802)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:767)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:674)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:658)
at com.google.android.gms.auth.be.j.a(SourceFile:209)
at com.google.android.gms.auth.be.appcert.a.a(SourceFile:263)
at com.google.android.gms.auth.be.appcert.a.a(SourceFile:132)
at com.google.android.gms.auth.be.appcert.b.a(SourceFile:43)
at com.google.android.gms.auth.b.b.a(SourceFile:62)
at com.google.android.gms.auth.b.a.a(SourceFile:120)
at com.google.android.gms.auth.b.a.a(SourceFile:61)
at com.google.android.gms.auth.be.cron.AuthCronService.a(SourceFile:44)
at com.google.android.gms.gcm.au.run(SourceFile:140)
02-02 21:01:16.030 1575-1595/com.google.android.gms.persistent E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at com.google.android.gms.org.conscrypt.Platform.closeGuardOpen(SourceFile:383)
at com.google.android.gms.org.conscrypt.OpenSSLSocketImpl.startHandshake(SourceFile:297)
at com.google.android.gms.org.conscrypt.KitKatPlatformOpenSSLSocketImplAdapter.startHandshake(SourceFile:318)
at com.google.android.gms.common.net.SSLCertificateSocketFactory.a(SourceFile:258)
at com.google.android.gms.common.net.SSLCertificateSocketFactory.createSocket(SourceFile:558)
at com.android.okhttp.Connection.upgradeToTls(Connection.java:171)
at com.android.okhttp.Connection.connect(Connection.java:151)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:948)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:766)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:674)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:658)
at com.google.android.gms.auth.be.j.a(SourceFile:209)
at com.google.android.gms.auth.be.appcert.a.a(SourceFile:263)
at com.google.android.gms.auth.be.appcert.a.a(SourceFile:132)
at com.google.android.gms.auth.be.appcert.b.a(SourceFile:43)
at com.google.android.gms.auth.b.b.a(SourceFile:62)
at com.google.android.gms.auth.b.a.a(SourceFile:120)
at com.google.android.gms.auth.b.a.a(SourceFile:61)
at com.google.android.gms.auth.be.cron.AuthCronService.a(SourceFile:44)
at com.google.android.gms.gcm.au.run(SourceFile:140)
02-02 21:01:16.040 1575-1595/com.google.android.gms.persistent E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:271)
at android.net.SSLCertificateSocketFactory.verifyHostname(SSLCertificateSocketFactory.java:190)
at android.net.SSLCertificateSocketFactory.createSocket(SSLCertificateSocketFactory.java:435)
at com.android.okhttp.Connection.upgradeToTls(Connection.java:171)
at com.android.okhttp.Connection.connect(Connection.java:151)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:208)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:948)
at com.google.android.gms.http.GoogleHttpClient.a(SourceFile:766)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:674)
at com.google.android.gms.http.GoogleHttpClient.execute(SourceFile:658)
at com.google.android.gms.phenotype.service.sync.PhenotypeConfigurator.a(SourceFile:1353)
at com.google.android.gms.phenotype.service.sync.PhenotypeConfigurator.a(SourceFile:799)
at com.google.android.gms.phenotype.service.sync.PhenotypeConfigurator.a(SourceFile:753)
at com.google.android.gms.phenotype.service.sync.PhenotypeConfigurator.c(SourceFile:475)
at com.google.android.gms.phenotype.service.sync.PhenotypeConfigurator.a(SourceFile:438)
at com.google.android.gms.gcm.au.run(SourceFile:140)
02-02 21:01:16.110 951-1292/? E/Drm: Failed to find drm plugin
02-02 21:01:18.650 951-1292/? E/Drm: Failed to find drm plugin
这是AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jetlabb.thegoods">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Child activity of main activity -->
<activity
android:name=".Main2Activity"
android:label="@string/title_activity_main2"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
Main2Activity.java
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
public class Main2Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getActionBar().setDisplayHomeAsUpEnabled(true);
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();
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bars up/home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}