代码。
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。
<?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]:致命错误:主要您是否在AndroidManifest. xml中声明了此活动?
致命错误:主要是你在AndroidManifest. xml中声明了这个活动吗?
Android Studio:找不到显式活动类您是否在AndroidManifest. xml中声明了此活动
我在这个应用程序上工作了两天,但是有一个问题让人困惑。我已经阅读了大多数关于它的帖子,但是我不能解决它,请帮助我。
使用ListActivity创建Listview时,有两件事必须包含一个ListView,其中android: id属性设置为@android:id/list(NOT android:id="@id/list")。
如果您将定义ListView并将android: id属性设置为@id/list,则会出现错误。
试试简单的这个。
<activity
android:name=".Season"/>
而不是,
<activity
android:name="com.example.farhad.bookdb.Season"/>
这可能对你有帮助。