【发布时间】:2018-08-12 15:05:41
【问题描述】:
我创建了一个使用 RecyclerView 和 CardView(用于 PointOfInterest)的项目。这 5 项活动相互关联:
- PointOfInterest.java
- PlacesAdapter.java
- Places.java
- layout_poi.xml
- activity_point_of_interest.xml
同时在 activity_main.xml 中我设计了主菜单和一些按钮。其中一个名为 Rapid Penang 的按钮(id: rapid_btn)。我将 Rapid Penang 的一项活动(来自 MainActivity.java)称为如下:
public class MainActivity extends AppCompatActivity {
private Button button_for_rapid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to call Rapid Penang class
button_for_rapid = (Button) findViewById(R.id.rapid_btn);
button_for_rapid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openRapid();
}
});
}
public void openRapid()
{
Intent intent_rapid = new Intent(this, RapidPenang.class);
startActivity(intent_rapid);
}
}
RapidPenang 只有一项活动,它是成功的。但是当我尝试对 PointOfInterest 活动(如上所述)执行完全相同的操作时,应用程序突然崩溃了。
这就是我尝试从 MainMenu 中名为 Point Of Interest 的按钮打开 PointOfInterest 活动的方式:
private Button button_for_poi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to call Point Of Interest class
button_for_poi = (Button) findViewById(R.id.poi_btn);
button_for_poi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openPOI();
}
});
}
public void openPOI()
{
Intent intent_poi = new Intent(this, PointOfInterest.class);
Intent intent_poi2 = new Intent(this, PlacesAdapter.class);
Intent intent_poi3 = new Intent(this, Places.class);
startActivity(intent_poi);
}
【问题讨论】:
-
请显示Logcat中显示的内容
-
"...包含 RecyclerView 和 CardView" - 这与启动 Activity 有什么关系。它只需要和 Intent 来启动一个 Activity(不管它包含什么)。
标签: java android android-recyclerview