我创建了一个使用 RecyclerView 和 CardView (针对PointOfInterest)的项目。这5个活动是相互关联的:
与此同时,我在 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);
}
答案 0 :(得分:0)
首先检查您的活动是否在Android清单文件中定义,然后调用
StartActivity(new Intent(getApplicationcontext(),RapidPenang.class));
就这样