我是Android编码新手。我正在尝试一个简单的代码,例如点击按钮,如果点击它会打开Google。如果我运行我的代码,如果我单击该按钮,浏览器将打开,并在一段时间后显示UNFORTUNATELY BROWSER STOPPED。请帮我。提前谢谢。
package com.example.single_button_google;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1= (Button) findViewById(R.id.button1);
b1.setOnClickListener(click);
}
View.OnClickListener click = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.google.co.in/"));
startActivity(intent);
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我的logcat:
02-04 04:50:19.910: D/AndroidRuntime(1174): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-04 04:50:19.920: D/AndroidRuntime(1174): CheckJNI is ON
02-04 04:50:20.000: D/dalvikvm(1174): Trying to load lib libjavacore.so 0x0
02-04 04:50:20.010: D/dalvikvm(1174): Added shared lib libjavacore.so 0x0
02-04 04:50:20.040: D/dalvikvm(1174): Trying to load lib libnativehelper.so 0x0
02-04 04:50:20.040: D/dalvikvm(1174): Added shared lib libnativehelper.so 0x0
02-04 04:50:20.050: D/dalvikvm(1174): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
02-04 04:50:20.270: D/dalvikvm(1174): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
02-04 04:50:20.840: E/memtrack(1174): Couldn't load memtrack module (No such file or directory)
02-04 04:50:20.840: E/android.os.Debug(1174): failed to load memtrack module: -2
02-04 04:50:21.200: D/AndroidRuntime(1174): Calling main entry com.android.commands.pm.Pm
02-04 04:50:21.240: D/AndroidRuntime(1174): Shutting down VM
02-04 04:50:21.240: D/dalvikvm(1174): Debugger has detached; object registry had 1 entries
02-04 04:50:22.040: D/AndroidRuntime(1185): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-04 04:50:22.050: D/AndroidRuntime(1185): CheckJNI is ON
02-04 04:50:22.120: D/dalvikvm(1185): Trying to load lib libjavacore.so 0x0
02-04 04:50:22.130: D/dalvikvm(1185): Added shared lib libjavacore.so 0x0
02-04 04:50:22.160: D/dalvikvm(1185): Trying to load lib libnativehelper.so 0x0
02-04 04:50:22.160: D/dalvikvm(1185): Added shared lib libnativehelper.so 0x0
02-04 04:50:22.160: D/dalvikvm(1185): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
02-04 04:50:22.380: D/dalvikvm(1185): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
02-04 04:50:22.960: E/memtrack(1185): Couldn't load memtrack module (No such file or directory)
02-04 04:50:22.960: E/android.os.Debug(1185): failed to load memtrack module: -2
02-04 04:50:23.290: D/AndroidRuntime(1185): Calling main entry com.android.commands.am.Am
02-04 04:50:23.380: I/ActivityManager(363): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.single_button_google/.MainActivity} from pid 1185
02-04 04:50:23.410: D/AndroidRuntime(1185): Shutting down VM
02-04 04:50:23.420: D/jdwp(1185): Got wake-up signal, bailing out of select
02-04 04:50:23.420: D/dalvikvm(1185): Debugger has detached; object registry had 1 entries
02-04 04:50:23.930: W/ActivityManager(363): Activity pause timeout for ActivityRecord{b4f82e48 u0 com.android.browser/.BrowserActivity t8}
02-04 04:50:24.000: W/InputMethodManagerService(363): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b505f218 attribute=null, token = android.os.BinderProxy@b51975c8
02-04 04:50:24.100: I/Choreographer(363): Skipped 51 frames! The application may be doing too much work on its main thread.
02-04 04:50:24.190: I/Choreographer(363): Skipped 58 frames! The application may be doing too much work on its main thread.
02-04 04:50:24.390: I/Choreographer(363): Skipped 48 frames! The application may be doing too much work on its main thread.
02-04 04:50:24.440: I/Choreographer(899): Skipped 288 frames! The application may be doing too much work on its main thread.
02-04 04:50:24.640: I/Choreographer(363): Skipped 50 frames! The application may be doing too much work on its main thread.
02-04 04:50:24.970: I/Choreographer(363): Skipped 52 frames! The application may be doing too much work on its main thread.
02-04 04:50:25.370: I/Choreographer(363): Skipped 51 frames! The application may be doing too much work on its main thread.
02-04 04:50:25.480: I/Choreographer(363): Skipped 58 frames! The application may be doing too much work on its main thread.
02-04 04:50:25.570: I/Choreographer(363): Skipped 54 frames! The application may be doing too much work on its main thread.
02-04 04:50:25.680: I/Choreographer(363): Skipped 69 frames! The application may be doing too much work on its main thread.
02-04 04:50:25.810: I/Choreographer(363): Skipped 72 frames! The application may be doing too much work on its main thread.
02-04 04:50:34.460: E/NativeDaemonConnector.ResponseQueue(363): Timeout waiting for response
02-04 04:50:34.460: E/VoldConnector(363): timed-out waiting for response to 12 volume mkdirs /storage/sdcard/Android/data/com.android.browser/files/
02-04 04:50:34.460: D/AndroidRuntime(1157): Shutting down VM
02-04 04:50:34.460: W/dalvikvm(1157): threadid=1: thread exiting with uncaught exception (group=0xb4adab90)
02-04 04:50:34.490: E/AndroidRuntime(1157): FATAL EXCEPTION: main
02-04 04:50:34.490: E/AndroidRuntime(1157): Process: com.android.browser, PID: 1157
02-04 04:50:34.490: E/AndroidRuntime(1157): java.lang.RuntimeException: Unable to get provider com.android.browser.provider.SnapshotProvider: java.lang.NullPointerException
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ActivityThread.installProvider(ActivityThread.java:4774)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4366)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4306)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ActivityThread.access$1400(ActivityThread.java:135)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1457)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.os.Handler.dispatchMessage(Handler.java:102)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.os.Looper.loop(Looper.java:137)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ActivityThread.main(ActivityThread.java:4998)
02-04 04:50:34.490: E/AndroidRuntime(1157): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 04:50:34.490: E/AndroidRuntime(1157): at java.lang.reflect.Method.invoke(Method.java:515)
02-04 04:50:34.490: E/AndroidRuntime(1157): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
02-04 04:50:34.490: E/AndroidRuntime(1157): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
02-04 04:50:34.490: E/AndroidRuntime(1157): at dalvik.system.NativeStart.main(Native Method)
02-04 04:50:34.490: E/AndroidRuntime(1157): Caused by: java.lang.NullPointerException
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.os.Parcel.readException(Parcel.java:1467)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.os.Parcel.readException(Parcel.java:1415)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.os.storage.IMountService$Stub$Proxy.mkdirs(IMountService.java:750)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ContextImpl.ensureDirsExistOrFilter(ContextImpl.java:2160)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ContextImpl.getExternalFilesDirs(ContextImpl.java:856)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ContextImpl.getExternalFilesDir(ContextImpl.java:839)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.content.ContextWrapper.getExternalFilesDir(ContextWrapper.java:210)
02-04 04:50:34.490: E/AndroidRuntime(1157): at com.android.browser.provider.SnapshotProvider.getOldDatabasePath(SnapshotProvider.java:116)
02-04 04:50:34.490: E/AndroidRuntime(1157): at com.android.browser.provider.SnapshotProvider.migrateToDataFolder(SnapshotProvider.java:123)
02-04 04:50:34.490: E/AndroidRuntime(1157): at com.android.browser.provider.SnapshotProvider.onCreate(SnapshotProvider.java:137)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.content.ContentProvider.attachInfo(ContentProvider.java:1589)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.content.ContentProvider.attachInfo(ContentProvider.java:1560)
02-04 04:50:34.490: E/AndroidRuntime(1157): at android.app.ActivityThread.installProvider(ActivityThread.java:4771)
02-04 04:50:34.490: E/AndroidRuntime(1157): ... 12 more
02-04 04:50:34.660: I/Choreographer(363): Skipped 45 frames! The application may be doing too much work on its main thread.
02-04 04:50:34.910: I/Choreographer(363): Skipped 64 frames! The application may be doing too much work on its main thread.
02-04 04:50:35.020: I/Choreographer(363): Skipped 65 frames! The application may be doing too much work on its main thread.
02-04 04:50:35.130: I/Choreographer(363): Skipped 64 frames! The application may be doing too much work on its main thread.
02-04 04:50:36.050: W/ActivityManager(363): Activity stop timeout for ActivityRecord{b4f82e48 u0 com.android.browser/.BrowserActivity t8}
答案 0 :(得分:0)
似乎是与模拟器和SD卡相关的问题。尝试更改模拟器上的某些配置或在真实设备上尝试应用。