Launcher activity CrimeListActivity won't display

#1

All,

I’m going through the Criminal Intent project for the second time. I thought I made a mistake but I’ve gone through this project very carefully. For some reason the crime list activity never displays. I’ve checked my manifest file and also my edit configuration. Still it doesn’t show. has anyone else experienced this problem?

#2

Ok i found the issue. My fragment was incorrectly pointing to “crimefragment” instead of “crimelistfragment”.

#3

I don’t understand. How did you resolved it? Please explain it clearly.

#4

I returned a crimefragment instead of a crimelistfragment. After you create the singlefragmentactivity. You have to change the methods in the crimeactivity and CrimeListActivity. My return statement was writtent incorrectly. Are you having the same issue? Want to send me your code?

public class CrimeListActivity extends SingleFragmentActivity {
@Override
protected Fragment createFragment() {
return new CrimeListFragment();
}
}

#5

Thank you very much for your reply. After checking several times,I haven’t find anything wrong. So please help check my codes.

  1. CrimeActivity.java
    public class CrimeActivity extends SingleFragmentActivity {

    @Override
    protected Fragment createFragment() {
    return new CrimeFragment();
    }
    }

  2. CrimeListActivity.java
    public class CrimeListActivity extends SingleFragmentActivity {

    @Override
    protected Fragment createFragment() {
    return new CrimeFragment();
    }
    }
    3, SingleFragmentActivity.java
    public abstract class SingleFragmentActivity extends FragmentActivity {

    protected abstract Fragment createFragment();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);

     FragmentManager fm=getSupportFragmentManager();
     Fragment fragment = fm.findFragmentById(R.id.fragment_container);
    
     if (fragment == null) {
         fragment=createFragment();
         fm.beginTransaction().add(R.id.fragment_container, fragment).commit();
     }
    

    }
    }

#6

Finally, i find something wrong . In CrimeListActivity.java , the return is not right. It should be “return new CrimeListFragment”. How cerelessful am I.
Thank you very much.