从主活动启动列表活动,并查找错误您是否在AndroidManifest.xml中声明了此活动



Code.

 public class Season extends ListActivity {
        private DataBaseHelper db;
        private String[] Name;
        private String[] Teedad;
        private ListView listView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.season);
                db = new DataBaseHelper(this);
                refresher();
                setListAdapter(new AA());
            listView=(ListView)findViewById(R.id.list);
                }
        class AA extends ArrayAdapter<String>{
            public AA(){
                super(Season.this,R.layout.raw_season,Name);
            }
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                LayoutInflater in = getLayoutInflater();
                View row = in.inflate(R.layout.raw_season, parent,false);
                TextView name = (TextView) row.findViewById(R.id.name_season);
                TextView teedad = (TextView) row.findViewById(R.id.teedad_dastan);
                name.setText(Name [position]);
                teedad.setText(Teedad [position]);
                return (row);
            }
}
       } 
    private void refresher(){
        db.openDataBase();
        int save = db.shomaresh_field("datastorys", "season");
        Name = new String[save];
        Teedad = new String[save];
        for (int i = 0; i <save; i++) {
            Name[i] = db.namayesh_fasl("datastorys", i);
            Teedad[i] = db.shomaresh_dastan("datastorys", Name[i].toString())+"";
        }
        db.close();
    }
}

清单。

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.farhad.bookdb">
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name="com.example.farhad.bookdb.MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.example.farhad.bookdb.Season">#I think, Is there any problem?#
            </activity>
        </application>
    </manifest>

呵。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:drawSelectorOnTop="false"
            android:id="@+id/list" />#I define here list#
    </RelativeLayout>

主活动代码

    public class MainActivity extends Activity {
        Button btn;
        Cursor c = null;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            btn = (Button)findViewById(R.id.btn);
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DataBaseHelper myDbHelper = new DataBaseHelper(MainActivity.this);
                    try {
                        myDbHelper.createDataBase();
                    } catch (IOException ioe) {
                        throw new Error("Unable to create database");
                    }
                    try {
                        myDbHelper.openDataBase();
                        Intent intent = new     Intent(MainActivity.this,Season.class);
                        startActivity(intent);
                    } catch (SQLException sqle) {
                        throw sqle;
                    }
                }
            });
        }
    }
  1. [1]:致命错误:主要您是否在AndroidManifest.xml中声明了此活动?

    致命错误:主要您是否在AndroidManifest.xml中声明了此活动?

    Android

    Studio:找不到显式活动类,您是否在 Android 清单中声明了此活动.xml

块引用 我在这个应用程序上工作了两天,但有一个问题让人感到困惑。我已经阅读了大多数关于它的帖子,但我无法解决它,请帮助我。

当使用 ListActivity 创建 Listview 时,有两件事必须包含一个 listView,其中 android:id 属性设置为 @android:id/list(不是 android:id="@+id/list")。

如果您将 android:id 属性设置为 @+id/list 来定义 ListView,那么它将给出错误。

试试这个。

 <activity
            android:name=".Season"/>

而不是

 <activity
            android:name="com.example.farhad.bookdb.Season"/>

这可能会对您有所帮助。

最新更新