我正在遵循Udacity的课程,最后在完成过程中遇到了这个错误。
您还可以通过单击here来检查Udacity的代码 以及我的布局文件1和2。
**
谢谢。
**
com.thelazyprogrammer.harshit.mycustomapps.ui.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:6998)
此错误指向setContentView(R.layout.activity_main);
但是不知道缺少了什么。 我的代码:-
public class MainActivity extends AppCompatActivity implements MasterListFragment.OnImageClickListener
{
// Variable to store the values of list index of selected image.
private int headIndex,
bodyIndex,
legIndex;
private boolean mTwoPane;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/*<---THE ABOVE ERROR POINTING BELOW LINE'S CODE--->*/
setContentView(R.layout.activity_main);
/*<------------------------------------------------>*/
/*Intent intent = new Intent(this, AndroidMeActivity.class);
startActivity(intent);*/
if(findViewById(R.id.android_me_linear_layout) != null)
{
mTwoPane=true;
// Setting grid view into two columns.
GridView gridView = (GridView) findViewById(R.id.images_grid_view);
gridView.setNumColumns(2);
// Getting rid of the button in the tablet mode.
Button nextButton = (Button) findViewById(R.id.next_button);
nextButton.setVisibility(View.GONE);
if(savedInstanceState!=null)
{
FragmentManager fragmentManager = getSupportFragmentManager();
BodyClassFragment headFragment, bodyFragment, legFragment;
// Creating new head, body, leg.
headFragment = new BodyClassFragment();
headFragment.setImageIds(AndroidImageAssets.getHeads());
bodyFragment = new BodyClassFragment();
bodyFragment.setImageIds(AndroidImageAssets.getBodies());
legFragment = new BodyClassFragment();
legFragment.setImageIds(AndroidImageAssets.getLegs());
// Adding fragment to it's container.
fragmentManager.beginTransaction()
.add(R.id.head_container, headFragment)
.add(R.id.body_container, bodyFragment)
.add(R.id.leg_container, legFragment)
.commit();
}
}
else
{
mTwoPane=false;
}
}