KeyDispatchingTimedOut错误,单击按钮以启动活动

时间:2013-09-21 05:55:27

标签: java android

我正在尝试从SQLite表中的列中检索值并将其存储在数组中。我必须通过单击按钮从另一个活动开始该活动。但不幸的是,当我点击该按钮时,我收到KeyDisplatchTimedOut错误,这意外地停止了我的应用程序。

这是我的logcat -

09-21 01:35:54.379: E/ActivityManager(1226): ANR in com.example.fromstart (com.example.fromstart/.Dialog)
09-21 01:35:54.379: E/ActivityManager(1226): Reason: keyDispatchingTimedOut
09-21 01:35:54.379: E/ActivityManager(1226): Load: 0.79 / 0.61 / 0.6
09-21 01:35:54.379: E/ActivityManager(1226): CPU usage from 5274ms to 0ms ago:
09-21 01:35:54.379: E/ActivityManager(1226):   94% 18598/com.example.fromstart: 93% user + 1.3% kernel
09-21 01:35:54.379: E/ActivityManager(1226):   1.8% 961/adbd: 0.1% user + 1.7% kernel / faults: 491 minor
09-21 01:35:54.379: E/ActivityManager(1226):   1.5% 951/surfaceflinger: 0.3% user + 1.1% kernel
09-21 01:35:54.379: E/ActivityManager(1226):   0.5% 1226/system_server: 0.1% user + 0.3% kernel / faults: 8 minor
09-21 01:35:54.379: E/ActivityManager(1226):   0% 943/yaffs-bg-1: 0% user + 0% kernel
09-21 01:35:54.379: E/ActivityManager(1226): 100% TOTAL: 94% user + 3.7% kernel + 1.3% softirq
09-21 01:35:54.379: E/ActivityManager(1226): CPU usage from 684ms to 1225ms later:
09-21 01:35:54.379: E/ActivityManager(1226):   96% 18598/com.example.fromstart: 96% user + 0% kernel
09-21 01:35:54.379: E/ActivityManager(1226):     96% 18598/ample.fromstart: 96% user + 0% kernel
09-21 01:35:54.379: E/ActivityManager(1226):   3.7% 1226/system_server: 0% user + 3.7% kernel
09-21 01:35:54.379: E/ActivityManager(1226):     3.7% 1243/ActivityManager: 0% user + 3.7% kernel
09-21 01:35:54.379: E/ActivityManager(1226): 100% TOTAL: 94% user + 5.4% kernel
09-21 01:35:54.409: D/dalvikvm(1226): GC_FOR_ALLOC freed 162K, 32% free 7658K/11216K, paused 11ms, total 11ms
09-21 01:35:54.419: I/dalvikvm-heap(1226): Grow heap (frag case) to 8.748MB for 1127532-byte allocation
09-21 01:35:54.459: D/dalvikvm(1226): GC_FOR_ALLOC freed <1K, 29% free 8759K/12320K, paused 42ms, total 42ms
09-21 01:35:54.589: D/(1226): HostConnection::get() New Host Connection established 0xb8579720, tid 1243
09-21 01:36:02.879: W/ActivityManager(1226): Activity destroy timeout for ActivityRecord{b174f320 u0 com.example.fromstart/.MainActivity}

这就是我调用该活动的方式 -

activity1.java:

alert_menu = (Button) findViewById(R.id.alert_menu);
            alert_menu.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent i = new Intent(settings.this,Dialog.class);
                        startActivity(i);
                    }
                }); 

Dialog.java:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_dup);

for(int i =1;i<=info.getrowcountofpersons();i++) 
{
    items[i-1]=info.getPersonList(i); //this method will return each person name and will be stored in items[] array
    System.out.println("The list items are:"+items[i-1]); 
    Toast.makeText(getApplicationContext(), items[i-1], Toast.LENGTH_LONG).show();

}
}

但是不是为了循环,而是将数组初始化为private String[] items = {"Warrior","Archer","Wizard"};,而是显示对话框,我没有收到该错误。这可能是什么问题?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我认为您是在完成sqlite进程检索数据时单击按钮。所以你必须等到这个过程完成。最好使用AsyncTaskSQLite检索数据。有关更多详细信息,请参阅this主题。