I am building a django web app with a custom user model which extends the AbstractBaseUser. In one of my models I need to use this custom user model:
from accounts.models import User
class History(models.Model):
user = models.ForeignKey(User)
job = models.ForeignKey(Job)
Run Code Online (Sandbox Code Playgroud)
When I try to run the python manage.py makemigrations command this error message is outputted:
ImportError: cannot import name User
Run Code Online (Sandbox Code Playgroud)
In my settings.py I do the following to let django know that there is a custom user model:
AUTH_USER_MODEL …Run Code Online (Sandbox Code Playgroud) 我有一个FragmentPagerAdapter处理获取当前片段,跟踪选项卡数量和设置每个选项卡的选项卡标题.
public class ClothingSectionsPagerAdapter extends FragmentPagerAdapter {
private String[] mCategories;
public ClothingSectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
public void setContext(Context context) {
mCategories = context.getResources().getStringArray(R.array.category);
}
@Override
public Fragment getItem(int position) {
return ClothingCategoryFragment.newInstance(mCategories[position]);
}
@Override
public int getCount() {
return mCategories.length;
}
@Override
public CharSequence getPageTitle(int position) {
Log.d("getPageTitle", mCategories[position]);
return mCategories[position];
}
}
Run Code Online (Sandbox Code Playgroud)
在我的活动中,我实现了这个类.
ClothingSectionsPagerAdapter sectionsPagerAdapter =
new ClothingSectionsPagerAdapter(getSupportFragmentManager());
sectionsPagerAdapter.setContext(this);
mViewPager.setAdapter(sectionsPagerAdapter);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
mViewPager.setCurrentItem(startingFragmentPosition);
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的应用程序时.标签存在,但它们是无标题.getPageTitle永远不会调用该方法.我该如何解决?
我有一个小时的使用RxJava的经验,我试图在我的项目中实现它,而不是使用接口和监听器.
我有一个异步任务,它在一个单独的模块中调用谷歌云端点方法,并List<Profile>在完成时收到.
在onPostExecute()异步任务的方法中,我调用onNext以便任何订阅者都能接收到这些数据.
这是AsyncTask看起来像:
private BirthpayApi mApi;
private String mUserId;
private ReplaySubject<List<Profile>> notifier = ReplaySubject.create();
public GetFriends(String userId) {
mUserId = userId;
}
public Observable<List<Profile>> asObservable() {
return notifier;
}
@Override
protected List<Profile> doInBackground(Void... params) {
if (mApi == null) {
BirthpayApi.Builder builder = new BirthpayApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
// options for running against local devappserver
// - 10.0.2.2 is localhost's IP address in Android emulator
// - turn off compression when running against …Run Code Online (Sandbox Code Playgroud) 我在我的android项目中使用Butterknife.我之前使用过这个,但由于某种原因它不再适用于新的更新.
这是我的设置:
(App Module)build.gradle:
compile 'com.jakewharton:butterknife:8.4.0'
Run Code Online (Sandbox Code Playgroud)
活动:
@BindView(R.id.navigation_pager) ViewPager mViewPager;
/.../
@Override
protected void onCreate(Bundle savedInstanceState) {
/...
/...
ButterKnife.bind(this);
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
Run Code Online (Sandbox Code Playgroud)
为了Butterknife上班,我错过了什么?
谢谢.