我想測試我的應用程序的性能。我已經開始使用簡單的應用程序,並嘗試把traceview,但它突然失敗,在我的android手機強行關閉。請指導我如何設置我的代碼propley爲簡單的Android應用程序獲取手髒跟蹤視圖無法打開跟蹤文件
這裏是代碼 package test.check;
import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;
public class tracev extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Debug.startMethodTracing("traceview");
setContentView(R.layout.main);
}
@Override
protected void onStop() {
Debug.stopMethodTracing();
super.onStop();
}
}
這裏是清單文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.check"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".tracev"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
我還添加
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
,但它不工作。我認爲它這條線在logcat中的becasue,但我不知道該如何處理它
05-20 23:39:43.913: ERROR/dalvikvm(11673): Unable to open trace file '/sdcard/traceview.trace': Permission denied
logcat的
05-20 23:39:43.903: DEBUG/dalvikvm(11673): +++ active profiler count now 1
05-20 23:39:43.913: INFO/dalvikvm(11673): TRACE STARTED: '/sdcard/traceview.trace' 8192KB
05-20 23:39:43.913: ERROR/dalvikvm(11673): Unable to open trace file '/sdcard/traceview.trace': Permission denied
05-20 23:39:43.913: DEBUG/dalvikvm(11673): +++ active profiler count now 0
05-20 23:39:43.913: DEBUG/AndroidRuntime(11673): Shutting down VM
05-20 23:39:43.913: WARN/dalvikvm(11673): threadid=3: thread exiting with uncaught exception (group=0x4001e390)
05-20 23:39:43.913: ERROR/AndroidRuntime(11673): Uncaught handler: thread main exiting due to uncaught exception
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.check/test.check.tracev}: java.lang.RuntimeException: file open failed
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Looper.loop(Looper.java:123)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.main(ActivityThread.java:4595)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at java.lang.reflect.Method.invoke(Method.java:521)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at dalvik.system.NativeStart.main(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): Caused by: java.lang.RuntimeException: file open failed
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at dalvik.system.VMDebug.startMethodTracing(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at dalvik.system.VMDebug.startMethodTracing(VMDebug.java:156)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Debug.startMethodTracing(Debug.java:443)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.os.Debug.startMethodTracing(Debug.java:391)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at test.check.tracev.onCreate(tracev.java:12)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): ... 11 more
05-20 23:39:44.013: INFO/Process(94): Sending signal. PID: 11673 SIG: 3
05-20 23:39:44.013: INFO/dalvikvm(11673): threadid=7: reacting to signal 3
05-20 23:39:44.023: INFO/dalvikvm(11673): Wrote stack trace to '/data/anr/traces.txt'
05-20 23:39:51.213: DEBUG/KeyguardViewMediator(94): pokeWakelock(15000)
05-20 23:39:51.213: INFO/HtcLockScreen(94): Press Menu key to unlock screen
我想知道一個角度來看,有沒有在SD卡,並在前面它沒有選擇任何設備。可能是錯誤原因,這裏是圖片
你能告訴我們你的表現? – MByD 2011-05-20 21:57:54
您正在使用哪個Android版本?你在使用模擬器嗎?如果是這樣,你是否爲它創建了一個虛擬SD卡? – 2011-05-20 22:00:01
@ MByD我已經添加了Manifest文件 – user667340 2011-05-20 22:04:33