java从主activite按意图启动ListActivity并查找错误您是否在AndroidManifest中声明了此活动。xml
代码
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:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.example.farhad.bookdb">
<application
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity 安卓:name="com.example.farhad.bookdb.MainActivity">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
安卓: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:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<ListView
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:drawSelectorOnTop="false"
安卓: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]: FATAL ERROR : main have you declared this activity in your AndroidManifest.xml?
FATAL ERROR : main 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.
# 1 楼答案
试试这个
而不是
这可能对你有帮助
# 2 楼答案
在使用ListActivity创建Listview时,必须有两件事包含一个将android:id属性设置为@android:id/list(非android:id=“@+id/list”)的Listview
如果在定义ListView时将android:id属性设置为@+id/list,则会出现错误