我正在编写一个将文件放入文件夹的类,并在列表视图中显示内容。当我运行此活动时应用程序强制关闭...我调试了一段时间,并通过logcat搜索,我找不到问题...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if(!root.exists()){
root.mkdirs();
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.folders, buildDirArray(root)));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
public String[] buildDirArray(File dir){
int temp = dir.list().length;
String[] tm = dir.list();
String[] tmp = new String[temp];
for(int i=1;i==dir.list().length;i++){
tmp[i]=tm[i];
}
return tmp;
}
非常感谢任何帮助...... Logcat数据:
07-13 20:41:21.205: ERROR/Zygote(32): setreuid() failed. errno: 2
07-13 20:41:29.045: ERROR/Zygote(32): setreuid() failed. errno: 17
07-13 20:41:30.345: ERROR/BatteryService(58): usbOnlinePath not found
07-13 20:41:30.345: ERROR/BatteryService(58): batteryVoltagePath not found
07-13 20:41:30.345: ERROR/BatteryService(58): batteryTemperaturePath not found
07-13 20:41:30.364: ERROR/SurfaceFlinger(58): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
07-13 20:41:36.015: ERROR/EventHub(58): could not get driver version for /dev/input/mouse0, Not a typewriter
07-13 20:41:36.015: ERROR/EventHub(58): could not get driver version for /dev/input/mice, Not a typewriter
07-13 20:41:36.295: ERROR/System(58): Failure starting core service
07-13 20:41:36.295: ERROR/System(58): java.lang.SecurityException
07-13 20:41:36.295: ERROR/System(58): at android.os.BinderProxy.transact(Native Method)
07-13 20:41:36.295: ERROR/System(58): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
07-13 20:41:36.295: ERROR/System(58): at android.os.ServiceManager.addService(ServiceManager.java:72)
07-13 20:41:36.295: ERROR/System(58): at com.android.server.ServerThread.run(SystemServer.java:184)
07-13 20:41:37.315: ERROR/SoundPool(58): error loading /system/media/audio/ui/Effect_Tick.ogg
07-13 20:41:37.325: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressStandard.ogg
07-13 20:41:37.325: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressSpacebar.ogg
07-13 20:41:37.346: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressDelete.ogg
07-13 20:41:37.356: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressReturn.ogg
07-13 20:41:40.414: ERROR/ThrottleService(58): Could not open GPS configuration file /etc/gps.conf
07-13 20:41:42.795: ERROR/logwrapper(147): executing /system/bin/tc failed: No such file or directory
07-13 20:41:42.945: ERROR/logwrapper(148): executing /system/bin/tc failed: No such file or directory
07-13 20:41:43.065: ERROR/logwrapper(149): executing /system/bin/tc failed: No such file or directory
07-13 20:41:54.824: ERROR/HierarchicalStateMachine(58): TetherMaster - unhandledMessage: msg.what=3
07-13 20:43:11.984: ERROR/AndEngine(282): You have to add
07-13 20:43:11.984: ERROR/AndEngine(282): <uses-permission android:name="android.permission.WAKE_LOCK"/>
07-13 20:43:11.984: ERROR/AndEngine(282): to your AndroidManifest.xml !
07-13 20:43:11.984: ERROR/AndEngine(282): java.lang.SecurityException: Neither user 10033 nor current process has android.permission.WAKE_LOCK.
07-13 20:43:11.984: ERROR/AndEngine(282): at android.os.Parcel.readException(Parcel.java:1247)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.os.Parcel.readException(Parcel.java:1235)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:236)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.os.PowerManager$WakeLock.acquire(PowerManager.java:250)
07-13 20:43:11.984: ERROR/AndEngine(282): at org.anddev.andengine.ui.activity.BaseGameActivity.acquireWakeLock(BaseGameActivity.java:202)
07-13 20:43:11.984: ERROR/AndEngine(282): at org.anddev.andengine.ui.activity.BaseGameActivity.doResume(BaseGameActivity.java:165)
07-13 20:43:11.984: ERROR/AndEngine(282): at org.anddev.andengine.ui.activity.BaseGameActivity.onWindowFocusChanged(BaseGameActivity.java:82)
07-13 20:43:11.984: ERROR/AndEngine(282): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:1981)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.view.View.dispatchWindowFocusChanged(View.java:3788)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:658)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.view.ViewRoot.handleMessage(ViewRoot.java:1921)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.os.Looper.loop(Looper.java:123)
07-13 20:43:11.984: ERROR/AndEngine(282): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-13 20:43:11.984: ERROR/AndEngine(282): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 20:43:11.984: ERROR/AndEngine(282): at java.lang.reflect.Method.invoke(Method.java:521)
07-13 20:43:11.984: ERROR/AndEngine(282): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-13 20:43:11.984: ERROR/AndEngine(282): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-13 20:43:11.984: ERROR/AndEngine(282): at dalvik.system.NativeStart.main(Native Method)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): FATAL EXCEPTION: main
07-13 20:43:20.614: ERROR/AndroidRuntime(282): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.momentum.xpad/com.momentum.xpad.folders}; have you declared this activity in your AndroidManifest.xml?
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.app.Activity.startActivityForResult(Activity.java:2817)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.app.Activity.startActivity(Activity.java:2923)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.momentum.xpad.main.onOptionsItemSelected(main.java:69)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.app.Activity.onMenuItemSelected(Activity.java:2195)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.view.View$PerformClick.run(View.java:8816)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.os.Handler.handleCallback(Handler.java:587)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.os.Handler.dispatchMessage(Handler.java:92)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.os.Looper.loop(Looper.java:123)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at java.lang.reflect.Method.invoke(Method.java:521)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-13 20:43:20.614: ERROR/AndroidRuntime(282): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:3)
日志说:
You have to add <uses-permission android:name="android.permission.WAKE_LOCK"/> to your AndroidManifest.xml !
哦,有些行进一步向下,日志中还有一个错误:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.momentum.xpad/com.momentum.xpad.folders}; have you declared this activity in your AndroidManifest.xml?
答案 1 :(得分:0)
android.content.ActivityNotFoundException:无法找到显式活动类{com.momentum.xpad / com.momentum.xpad.folders};你有没有在AndroidManifest.xml中声明这个活动?
你有没有在你的清单中宣布它?