我在做一个简单的数据库的小程序,模仿网上的一个用tab进行切换的课程表。每一个tab页显示一个新的activity,,每一个新的activity里面都有一个listview用来显示课程的详细信息。
出现的问题是:
 Intent intent1=new Intent();
 intent1.setClass(MyLessonscheduleActivity.this, MyMondayList.class);
 myTab.addTab(myTab.newTabSpec("Mon").setIndicator("星期一", res.getDrawable(R.drawable.mon)).setContent(intent1));
这样编码,程序根本不能运行。数据库的插入删除等其他功能都能实现,就是这个tab页的切换进行显示的功能不能实现(程序运行就直接报错)。求高手赐教,本人菜鸟中的菜鸟,在此万分的感激。。最好能有源码或者类似的程序让我借鉴一下。感激不尽!!!!!!!

解决方案 »

  1.   

    MyMondayList有没有在menifest中注册?
    还是把错误log贴上来把
      

  2.   

    好的,我把所有的代码都贴上来,谢谢你们的帮助,麻烦你们了啊。
    这是那个Tab界面,主程序的代码:
    package com.apk.lry;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.TabActivity;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.ArrayAdapter;
    import android.widget.GridView;
    import android.widget.ListView;
    import android.widget.TabHost;
    import android.widget.TabHost.OnTabChangeListener;
    import android.widget.Toast;public class MyLessonscheduleActivity extends TabActivity {
        /** Called when the activity is first created. */
        private Menu myMenu;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            TabHost myTab=getTabHost();
            Resources res=getResources();
           Intent intent1=new Intent();
           intent1.setClass(MyLessonscheduleActivity.this, MyMondayList.class);
           myTab.addTab(myTab.newTabSpec("Mon").setIndicator("星期一", res.getDrawable(R.drawable.mon)).setContent(intent1));
           myTab.addTab(myTab.newTabSpec("Tue").setIndicator("星期二", res.getDrawable(R.drawable.tue)).setContent(R.id.text2));
           myTab.addTab(myTab.newTabSpec("Wed").setIndicator("星期三", res.getDrawable(R.drawable.wed)).setContent(R.id.text3));
           myTab.addTab(myTab.newTabSpec("Thu").setIndicator("星期四", res.getDrawable(R.drawable.thu)).setContent(R.id.text4));
           myTab.addTab(myTab.newTabSpec("Fri").setIndicator("星期 五", res.getDrawable(R.drawable.fri)).setContent(R.id.text5));
    }
       @Override
        public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    myMenu=menu;
    Resources res=getResources();
    Drawable draw=res.getDrawable(R.drawable.add);
    myMenu.add(0, 1, Menu.NONE, "添加").setIcon(draw);
    draw=res.getDrawable(R.drawable.setting);
    myMenu.add(0, 2, Menu.NONE, "设置").setIcon(draw);
    draw=res.getDrawable(R.drawable.help);
    myMenu.add(1, 3, Menu.NONE, "帮助").setIcon(draw);
    draw=res.getDrawable(R.drawable.exit);
    myMenu.add(1, 4, Menu.NONE, "退出").setIcon(draw);
    myMenu.add(2, 5, Menu.NONE, " 其他");

    return super.onCreateOptionsMenu(menu);

    } @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    int id=item.getItemId();
    if(id==1)
    {
       Intent intent0=new Intent();
           intent0.setClass(MyLessonscheduleActivity.this, MyAddLesson.class);
           startActivity(intent0);
    }
    if(id==2)
    {
    Toast.makeText(getApplicationContext(),item.getTitle(), Toast.LENGTH_SHORT).show();
    }
    if(id==3)
    {
    Toast.makeText(getApplicationContext(),item.getTitle(), Toast.LENGTH_SHORT).show();
    }
    if(id==5)
    {
    Toast.makeText(getApplicationContext(),item.getTitle(), Toast.LENGTH_SHORT).show();
    }
    if(id==4)


    {
    new AlertDialog.Builder(this).setTitle("确认退出").setMessage("您确认退出")
    .setPositiveButton("确定", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    finish();

    }
    }).setNegativeButton("取消", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub
    dialog.cancel();

    }
    }).show();






    }
    return super.onOptionsItemSelected(item);
    }
        
        
        
    }
      

  3.   

    这是那个mondaylist 的activity的代码:
    package com.apk.lry;import java.util.ArrayList;
    import java.util.HashMap;import android.app.Activity;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;public class MyMondayList extends Activity {
    private ListView mylistview1;
       private MyDBAdapter myadapterDB;
       private Cursor myCursorDB;
       SimpleAdapter listItemAdapter;  
            private ArrayAdapter<String> adapter;
       ArrayList<HashMap<String, Object>> listData; @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    mylistview1=(ListView)findViewById(R.id.listviewfordb);
      myadapterDB=new MyDBAdapter(this);
            myadapterDB.open();
            getAllData();
            listItemAdapter = new SimpleAdapter(MyMondayList.this,  
             listData,// 数据源  
              R.layout.listviewsytle,// ListItem的XML实现  
             // 动态数组与ImageItem对应的子项  
              new String[] { "lesson", "address", "time","teacher" },  
              // ImageItem的XML文件里面的一个ImageView,两个TextView ID  
              new int[] { R.id.textview1, R.id.textview2, R.id.textview3 ,R.id.textview4});  
             mylistview1.setAdapter(listItemAdapter);
           
    }
    public void getAllData() {  
     Cursor c =myadapterDB.select();  
     int DBcount=c.getCount();
     if(DBcount<=1)
     {
     Toast.makeText(MyMondayList.this, "数据库内没有数据", Toast.LENGTH_SHORT).show();
     }
     else
     {
     
     int columnsSize = c.getColumnCount(); 

     listData = new ArrayList<HashMap<String, Object>>();  
     // 获取表的内容  
     while (c.moveToNext()) {  
     HashMap<String, Object> map = new HashMap<String, Object>();  
    for (int i = 0; i < columnsSize; i++) {  
     map.put("lesson", c.getString(0));  
     map.put("address", c.getString(1));  
     map.put("time", c.getString(2));  
     map.put("teacher", c.getString(3));  
     }  
     listData.add(map);  
     }             
     }  
    }}
      

  4.   

    这是mondaylist中listview控件的style:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TextView 
         android:id="@+id/textview1"
         android:layout_width="180dip"
         android:layout_height="wrap_content"
         android:text="课程"
            />
         <TextView 
         android:id="@+id/textview2"
         android:layout_width="180dip"
         android:layout_height="wrap_content"
         android:text="地点"
            />
          <TextView 
         android:id="@+id/textview3"
         android:layout_width="180dip"
         android:layout_height="wrap_content"
         android:text="时间"
            />
           <TextView 
         android:id="@+id/textview4"
         android:layout_width="180dip"
         android:layout_height="wrap_content"
         android:text="教师"
            />
          
            
        </LinearLayout>
    本人是菜鸟中的菜鸟,欢迎各位大神指正。谢谢你们了,真是太麻烦人了。。