Pic for more clarification原因:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'void android.widget.Button.setOnClickListener(android.view.View $ OnClickListener)' 在com.example.vaibh.thinkingfastandslow.MainActivity.onCreate(MainActivity.java:107)
thecharactersoftheStory = (Button)findViewById(R.id.button2a);
thecharactersoftheStory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,TheCharactersoftheStory.class);
startActivity(i);
}
});
我的XML文件中有
<Button
android:id="@+id/button2a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1. The Characters of the Story" />