gpt4 book ai didi

java - 安卓AVD “Unfortunately, has stopped.”

转载 作者:行者123 更新时间:2023-11-30 03:23:43 26 4
gpt4 key购买 nike

我的应用程序只工作一次,在第二次运行时(和其他...)我得到“不幸的是,我的应用程序已停止”。我已经尝试了很多,但对我没有任何影响。这是代码:

主要 Activity : 包 com.example.myfirstapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;



public class MainActivity extends Activity {


public void onCreate(Bundle savedInstanceState) {
final Context context = this;

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Intent intent = new Intent(context, WebViewActivity.class);
startActivity(intent);
}


@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
}
@Override
protected void onResume() {
super.onResume();
// The activity has become visible (it is now "resumed").
}
@Override
protected void onPause() {
super.onPause();
// Another activity is taking focus (this activity is about to be "paused").
}
@Override
protected void onStop() {
super.onStop();
// The activity is no longer visible (it is now "stopped")
}
@Override
protected void onDestroy() {
super.onDestroy();
// The activity is about to be destroyed.
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected (MenuItem item) {
switch (item.getItemId()) {
case R.id.exit:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

WebView Activity :

package com.example.myfirstapp;





import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);

webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);

webView.loadUrl("http://mysite.com");

}
@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
}
@Override
protected void onResume() {
super.onResume();
// The activity has become visible (it is now "resumed").
}
@Override
protected void onPause() {
super.onPause();
// Another activity is taking focus (this activity is about to be "paused").
}
@Override
protected void onStop() {
super.onStop();
// The activity is no longer visible (it is now "stopped")
}
@Override
protected void onDestroy() {
super.onDestroy();
// The activity is about to be destroyed.
}
}

日志:

09-05 05:53:27.080: I/Choreographer(815): Skipped 76 frames!  The application may be doing too much work on its main thread.
09-05 05:53:27.391: D/dalvikvm(815): GC_FOR_ALLOC freed 88K, 6% free 2654K/2808K, paused 136ms, total 139ms
09-05 05:53:27.760: I/Choreographer(815): Skipped 88 frames! The application may be doing too much work on its main thread.
09-05 05:53:27.771: D/gralloc_goldfish(815): Emulator without GPU emulation detected.
09-05 05:53:27.931: I/Choreographer(815): Skipped 38 frames! The application may be doing too much work on its main thread.
09-05 05:53:28.630: E/chromium_net(815): external/chromium/net/disk_cache/backend_impl.cc:1107: [0905/055328:ERROR:backend_impl.cc(1107)] Critical error found -8
09-05 05:53:28.641: W/chromium_net(815): external/chromium/net/disk_cache/storage_block-inl.h:119: [0905/055328:WARNING:storage_block-inl.h(119)] Failed data load.
09-05 05:53:28.651: D/chromium(815): Unknown chromium error: -401
09-05 05:53:28.670: W/chromium_net(815): external/chromium/net/disk_cache/storage_block-inl.h:119: [0905/055328:WARNING:storage_block-inl.h(119)] Failed data load.
09-05 05:53:29.210: E/cutils-trace(815): Error opening trace file: No such file or directory (2)
09-05 05:53:29.271: D/TilesManager(815): Starting TG #0, 0x2a2a6710
09-05 05:53:58.921: W/IInputConnectionWrapper(815): showStatusIcon on inactive InputConnection
09-05 05:54:00.280: I/Choreographer(815): Skipped 44 frames! The application may be doing too much work on its main thread.

最佳答案

您应该在执行任何其他操作之前调用 super。我仍然不明白需要将其分配给最终的 Context 对象

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context context = this;
setContentView(R.layout.activity_main);

Intent intent = new Intent(this, WebViewActivity.class);
startActivity(intent);
}

关于java - 安卓AVD “Unfortunately, <app> has stopped.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18632795/

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