刚开始学android,照《android应用开发揭秘》写了个例子,但是我运行时在模拟器里就报错“The application example04(process com.android.example) has stopped unexpectedly.please try again”我进Log里看到下面的错误:04-27 12:12:38.071: WARN/dalvikvm(217): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-27 12:12:38.071: ERROR/AndroidRuntime(217): Uncaught handler: thread main exiting due to uncaught exception
04-27 12:12:38.151: ERROR/AndroidRuntime(217): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.example/com.android.example.example04}: java.lang.IllegalArgumentException: column 'number' does not exist
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.os.Looper.loop(Looper.java:123)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.app.ActivityThread.main(ActivityThread.java:4310)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at java.lang.reflect.Method.invokeNative(Native Method)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at java.lang.reflect.Method.invoke(Method.java:521)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at dalvik.system.NativeStart.main(Native Method)
04-27 12:12:38.151: ERROR/AndroidRuntime(217): Caused by: java.lang.IllegalArgumentException: column 'number' does not exist
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java:99)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:339)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:91)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at com.android.example.example04.onCreate(example04.java:45)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
04-27 12:12:38.151: ERROR/AndroidRuntime(217):     ... 11 more我的代码如下:package com.android.example;import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;public class example04 extends Activity {
    /** Called when the activity is first created. */
LinearLayout m_LinearLayout;
ListView m_ListView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        m_LinearLayout = new LinearLayout(this);
        
        m_LinearLayout.setOrientation(LinearLayout.VERTICAL);
        m_LinearLayout.setBackgroundColor(android.graphics.Color.BLACK);
        
        m_ListView = new ListView(this);
        
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
        m_ListView.setBackgroundColor(Color.BLACK);
        
        m_LinearLayout.addView(m_ListView,param);
        
        setContentView(m_LinearLayout);
        
        Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        
        startManagingCursor(cur);
        
        ListAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.expandable_list_content,cur,new String[]{PhoneLookup.DISPLAY_NAME,PhoneLookup.NUMBER},new int[]{android.R.id.text1,android.R.id.text2});
        
        m_ListView.setAdapter(adapter);
        
        m_ListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
         @Override
         public void onItemSelected(AdapterView<?> arg0,View arg1,int arg2,long arg3)
         {
         DisplayToast("滚动到" + Long.toString(arg0.getSelectedItemId())+"项");
         }
         public void onNothingSelected(AdapterView<?> arg0){
        
         }
});
        
        m_ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
         public void onItemClick(AdapterView<?> arg0,View arg1,int arg2,long arg3)
         {
         DisplayToast("选中了第"+Integer.toString(arg2+1)+"项");
         }
});
    }
public void DisplayToast(String str)
{
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}

解决方案 »

  1.   

    还有一些Log错误:
    04-27 12:12:22.502: ERROR/ActivityThread(103): Failed to find provider info for android.server.checkin04-27 12:12:26.660: ERROR/AndroidRuntime(120): ERROR: thread attach failed04-27 12:12:21.620: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound04-27 12:12:21.681: ERROR/MediaPlayer(57): Unable to to create media player04-27 12:12:21.411: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound)04-27 12:12:08.208: ERROR/System(57): Failure starting core service04-27 12:12:08.208: ERROR/System(57): java.lang.SecurityException04-27 12:12:08.208: ERROR/System(57):     at android.os.BinderProxy.transact(Native Method)04-27 12:12:08.208: ERROR/System(57):     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)04-27 12:12:08.208: ERROR/System(57):     at android.os.ServiceManager.addService(ServiceManager.java:72)04-27 12:12:08.208: ERROR/System(57):     at com.android.server.ServerThread.run(SystemServer.java:176)04-27 12:12:08.217: ERROR/AndroidRuntime(57): Crash logging skipped, no checkin service04-27 12:12:08.038: ERROR/EventHub(57): could not get driver version for /dev/input/mouse0, Not a typewriter04-27 12:12:08.038: ERROR/EventHub(57): could not get driver version for /dev/input/mice, Not a typewriter04-27 12:12:02.977: ERROR/BatteryService(57): usbOnlinePath not found04-27 12:12:02.977: ERROR/BatteryService(57): batteryVoltagePath not found04-27 12:12:02.999: ERROR/SurfaceFlinger(57): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake04-27 12:11:46.527: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)04-27 12:11:46.527: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)04-27 12:11:46.527: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)04-27 12:11:46.527: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)04-27 12:12:02.977: ERROR/BatteryService(57): batteryTemperaturePath not found
      

  2.   

    推荐的解决方案http://www.cnblogs.com/moonz-wu/archive/2010/06/28/1766404.html
      

  3.   

    04-27 12:12:26.660: ERROR/AndroidRuntime(120): ERROR: thread attach failed
    这个错误是很正常的东西!因为正常的Android程序都会报这样的错误!
      

  4.   

    我的解决了,是我的main.xml出现了问题。你用图形的方式看看是否能显示出来
      

  5.   


    请问一下  你的那个main的怎么解决?  我的好像也是main这个问题
    AndroidRuntime   FATAL EXCEPTION :main
      

  6.   

    是因为书上用的Android SDK 与我们本机配置环境所用的Android SDK不是同一个版本。
      

  7.   

            ListAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.expandable_list_content,cur,new String[]{PhoneLookup.DISPLAY_NAME,PhoneLookup.NUMBER},new int[]{android.R.id.text1,android.R.id.text2});
            
            m_ListView.setAdapter(adapter);该参数有问题!
      

  8.   

    我也是刚学android,不知道对不对。你的程序中首先设置了一个容器的具体模式setContentView(R.layout.main);
    之后你应用了自己设定的一系列UI组件,你又一次设置了一个容器模式setContentView(m_LinearLayout);
    是不是有冲突。你把setContentView(R.layout.main);和你的layout文件夹下的main.xml文件删除试试。还有在数据传输的时候是否用到了标点,用到的标点是否是半角的。希望能解决,若不是以上希望回答正解