-1

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();
    }
}

Manifest.

    <?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.

    <?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>

MainActivity Code

    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]: FATAL ERROR : main have you declared this activity in your AndroidManifest.xml?

    FATAL ERROR : main have you declared this activity in your AndroidManifest.xml?

    Android Studio: Unable to find explicit activity class have you declared this activity in your AndroidManifest.xml

Blockquote I have work two days on this application but there is a problem which make confuse. I have read most post about it but I could not solve it please help me.

Community
  • 1
  • 1

2 Answers2

0

Try Simply this.

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

instead of,

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

This may helps you.

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48
0

When creating Listview with ListActivity then two things are MUST contain a ListView with the android:id attribute set to @android:id/list ( NOT android:id="@+id/list" ).

if you will defined ListView with the android:id attribute set to @+id/list then it will give error.

kunal
  • 308
  • 3
  • 15