我正在尝试实现traceview。我不确定它是否是正确的实施方式。请指导我。 我直接在Android手机而不是模拟器上运行。 代码
import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;
import android.webkit.WebView;
public class WebViewExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Debug.startMethodTracing("myapp");
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://mediasense2.appspot.com");
webView.setWebViewClient(new HelloWebViewClient());
Debug.stopMethodTracing();
}
}
没有
Debug.startMethodTracing("myapp");
Debug.stopMethodTracing();
该应用程序运行正常,但有了这些线条,它出现了“强制关闭”我还添加了
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
但仍然不起作用 Logcat错误
05-20 21:02:05.989: ERROR/AndroidRuntime(9171): Uncaught handler: thread main exiting due to uncaught exception
05-20 21:02:06.019: DEBUG/WifiService(94): acquireWifiLockLocked: WifiLock{NetworkLocationProvider type=2 binder=android.os.Binder@44998730}
05-20 21:02:06.019: DEBUG/WifiService(94): enable and start wifi due to updateWifiState
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidpeople.view/com.androidpeople.view.WebViewExample}: java.lang.RuntimeException: file open failed
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.os.Looper.loop(Looper.java:123)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.app.ActivityThread.main(ActivityThread.java:4595)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at java.lang.reflect.Method.invoke(Method.java:521)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at dalvik.system.NativeStart.main(Native Method)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): Caused by: java.lang.RuntimeException: file open failed
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at dalvik.system.VMDebug.startMethodTracing(Native Method)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at dalvik.system.VMDebug.startMethodTracing(VMDebug.java:156)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.os.Debug.startMethodTracing(Debug.java:443)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.os.Debug.startMethodTracing(Debug.java:391)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at com.androidpeople.view.WebViewExample.onCreate(WebViewExample.java:13)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
05-20 21:02:06.289: ERROR/AndroidRuntime(9171): ... 11 more
05-20 21:02:06.299: ERROR/PackageInstallationReceiver(245): Remove /data/local/tmp/com.androidpeople.view.apk Fail!
05-20 21:02:06.299: WARN/System.err(245): java.io.IOException: Error running exec(). Commands: [/system/xbin/su, 0, /system/bin/rm, /data/local/tmp/com.androidpeople.view.apk] Working Directory: null Environment: null
05-20 21:02:06.399: WARN/System.err(245): at java.lang.ProcessManager.exec(ProcessManager.java:196)
05-20 21:02:06.399: WARN/System.err(245): at java.lang.Runtime.exec(Runtime.java:225)
05-20 21:02:06.399: WARN/System.err(245): at java.lang.Runtime.exec(Runtime.java:313)
05-20 21:02:06.399: WARN/System.err(245): at java.lang.Runtime.exec(Runtime.java:246)
05-20 21:02:06.509: WARN/System.err(245): at com.htc.android.psclient.PackageInstallationReceiver.removeTempPackageFile(PackageInstallationReceiver.java:34)
05-20 21:02:06.509: WARN/System.err(245): at com.htc.android.psclient.PackageInstallationReceiver.access$000(PackageInstallationReceiver.java:8)
05-20 21:02:06.509: WARN/System.err(245): at com.htc.android.psclient.PackageInstallationReceiver$1.run(PackageInstallationReceiver.java:24)
05-20 21:02:06.509: WARN/System.err(245): Caused by: java.io.IOException: No such file or directory
05-20 21:02:06.529: WARN/System.err(245): at java.lang.ProcessManager.exec(Native Method)
05-20 21:02:06.529: WARN/System.err(245): at java.lang.ProcessManager.exec(ProcessManager.java:194)
05-20 21:02:06.529: WARN/System.err(245): ... 6 more
05-20 21:02:06.599: INFO/Process(94): Sending signal. PID: 9171 SIG: 3
05-20 21:02:06.599: INFO/dalvikvm(9171): threadid=7: reacting to signal 3
05-20 21:02:06.619: INFO/dalvikvm(9171): Wrote stack trace to '/data/anr/traces.txt'
05-20 21:02:07.669: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f050007
05-20 21:02:07.669: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f040000
05-20 21:02:07.669: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f050002
05-20 21:02:07.669: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f020000
05-20 21:02:07.669: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f030001
05-20 21:02:07.669: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f060004
05-20 21:02:07.669: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f040000
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f060007
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f040000
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f050000
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f020005
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f020004
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f060000
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f02001a
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f050001
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f0a03ee
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f020003
05-20 21:02:07.749: WARN/ResourceType(94): Resources don't contain package for resource number 0x7f040000
05-20 21:02:07.769: DEBUG/BackupManagerService(94): Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.androidpeople.view flg=0x20000000 (has extras) }
05-20 21:02:07.769: VERBOSE/BackupManagerService(94): updatePackageParticipantsLocked: com.androidpeople.view
05-20 21:02:07.819: VERBOSE/BackupManagerService(94): removePackageParticipantsLockedInner (com.androidpeople.view) removing 10 entries
05-20 21:02:07.819: VERBOSE/BackupManagerService(94): - PackageInfo{44c15a40 com.android.browser}
05-20 21:02:07.819: VERBOSE/BackupManagerService(94): - PackageInfo{44c012d8 com.android.mms}
05-20 21:02:07.819: VERBOSE/BackupManagerService(94): - PackageInfo{44b54158 com.htc.CustomizationSetup}
05-20 21:02:07.819: VERBOSE/BackupManagerService(94): - PackageInfo{44e99dd0 com.android.providers.telephony}
05-20 21:02:07.819: VERBOSE/BackupManagerService(94): - PackageInfo{44e0a040 com.android.providers.settings}
05-20 21:02:07.819: VERBOSE/BackupManagerService(94): - PackageInfo{44e01520 com.htc.android.htcime}
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): - PackageInfo{44cac200 com.android.providers.userdictionary}
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): - PackageInfo{44c682c8 android}
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): - PackageInfo{44c299a8 com.android.vending}
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): - PackageInfo{44b98b90 com.htc.provider.settings}
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): Adding 10 backup participants:
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44c15a40 com.android.browser} agent=com.android.browser.BrowserBackupAgent uid=10028 killAfterRestore=true restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44c012d8 com.android.mms} agent=com.android.mms.MmsBackupAgent uid=10030 killAfterRestore=true restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44b54158 com.htc.CustomizationSetup} agent=com.htc.CustomizationSetup.AccountBackupAgent uid=10001 killAfterRestore=true restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44e99dd0 com.android.providers.telephony} agent=com.android.providers.telephony.MessageBackupAgent uid=1001 killAfterRestore=false restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44e0a040 com.android.providers.settings} agent=com.android.providers.settings.SettingsBackupAgent uid=1000 killAfterRestore=false restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44e01520 com.htc.android.htcime} agent=com.htc.android.htcime.util.BackupAgent uid=10029 killAfterRestore=false restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44cac200 com.android.providers.userdictionary} agent=com.android.providers.userdictionary.DictionaryBackupAgent uid=10002 killAfterRestore=false restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44c682c8 android} agent=com.android.server.SystemBackupAgent uid=1000 killAfterRestore=false restoreNeedsApplication=false
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44c299a8 com.android.vending} agent=com.android.vending.VendingBackupAgent uid=10006 killAfterRestore=false restoreNeedsApplication=true
05-20 21:02:07.829: VERBOSE/BackupManagerService(94): PackageInfo{44b98b90 com.htc.provider.settings} agent=com.htc.provider.settings.BackupAgent uid=10001 killAfterRestore=false restoreNeedsApplication=false
05-20 21:02:08.059: DEBUG/NetworkLocationProvider(94): onCellLocationChanged [1133,66435990]
05-20 21:02:09.039: DEBUG/dalvikvm(164): GC freed 20648 objects / 941256 bytes in 909ms
05-20 21:02:09.449: WARN/Addapter(171): info.icon:2130837525
05-20 21:02:09.449: WARN/Addapter(171): info.icon:2130837504
答案 0 :(得分:2)
尝试改为
android.os.Debug.startMethodTracing(
Environment.getExternalStorageDirectory() + "/myapp");
实际写入SD卡。