我刚刚开始进行android编程,并且仍然在弄清楚片段和活动是如何工作的。所以我正在尝试一些代码,但我收到错误“StartFragment无法解析为类型”
这是我的代码
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
public class MainActivity extends FragmentActivity {
Fragment fragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
//StartFragment cannot be resolved to a type
StartFragment myfragment = new StartFragment();
transaction.add(R.id.namefrag, myfragment);
transaction.add(R.id.view_fragment,myfragment);
transaction.add(R.id.load, myfragment);
transaction.add(R.id.store,myfragment);
}
}