I have the following error when I try to compile my project; any body knows what I can do with this error.
FATAL EXCEPTION: main
Process: com.bignerdranch.android.criminalintent, PID: 15284
java.lang.NoSuchMethodError: No static method
getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface;
in class Landroid/support/v4/content/res/ResourcesCompat; or its super
classes (declaration of
'android.support.v4.content.res.ResourcesCompat' appears in
/data/app/com.bignerdranch.android.criminalintent-sYwk5YXA0Ap8nyn-79YvKg==/base.apk)
at
android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
at
android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
at
android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
at
android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at
android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:81)
at
android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:71)
at
android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:67)
at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:753)
at
android.support.v7.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)
at
android.support.v7.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)
at
android.support.v7.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:621)
at
android.support.v7.app.AppCompatDelegateImplV9.onTitleChanged(AppCompatDelegateImplV9.java:631)
at
android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
at
android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at
com.bignerdranch.android.criminalintent.SingleFragmentActivity.onCreate(SingleFragmentActivity.java:21)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Here is the part it says it is failing in the log
public abstract class SingleFragmentActivity extends AppCompatActivity
{
protected abstract Fragment createFragment();//abstract method
#Override
protected void onCreate(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();
}
}
}
Always try to read and understand what Android Studio is telling you. In this case it tells you quite plainly that there is no such method as getFont() in the current context. You probably wanted/should've used ResourcesCompat.getFont(context, R.font.your_font); but there is no way to know because you didn't post a sample of your code. Please review Stack Overflow's posting guidelines. This will save everyone a lot of time.
Related
I have received numerous Crashlytics reports of an exception my app is throwing, but I have never seen this myself, and I am struggling to understand where it is coming from.
My running theory is that it is related to the Firebase Auth dependency I have - but that dependency isn't actively being used yet. There is a whole sign-up and sign-in flow that my production app has disabled. The only two instances of the library being used in production code is:
// Inside Activity.onCreate()
Firebase.auth.addAuthStateListener {
val user = it.currentUser
if (user != null) {
Firebase.analytics.setUserId(user.uid)
CoroutineScope(Dispatchers.IO).launch {
registerDeviceToken(applicationContext)
}
} else {
Firebase.analytics.setUserId(null)
Firebase.messaging.deleteToken()
}
}
and:
// Called from Activity.onStart()
fun hasPendingMagicLink(intent: Intent): Boolean {
val emailAddress = getMagicLinkEmailAddress()
return emailAddress != null
&& Firebase.auth.currentUser == null
&& Firebase.auth.isSignInWithEmailLink(intent.data.toString())
}
I have included the Crashlytics reports below.
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{com.poliziano.notanotherpomodoroapp/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}: java.lang.NullPointerException
android.app.ActivityThread.performLaunchActivity
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.poliziano.notanotherpomodoroapp/com.google.android.gms.auth.api.signin.internal.SignInHubActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by java.lang.NullPointerException
android.app.ActivityThread.performLaunchActivity
Caused by java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at com.google.android.gms.internal.auth-api.zzaz.checkNotNull(zzaz.java:2)
at com.google.android.gms.auth.api.signin.internal.SignInHubActivity.onCreate(SignInHubActivity.java:5)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I have a question about PreferenceScreen in Android Studio. I used MultiSelectListPreference and did not get an error, however when I used ListPreference, I got an error and does not open setting activity.
<PreferenceCategory
android:title="Time Table Setting">
<ListPreference
android:key="Header_List"
android:entries="#array/setting_header_list"
android:entryValues="#array/setting_header_values"
android:title="Display Dates"
android:summary="Monday to Friday, Saturday or Sunday"/>
</PreferenceCategory>
<Preference
android:key="Restart"
android:title="Save"/>
If you have any suggestions, Please help me out. Thank you
Here is the error message that I've got
2020-03-21 22:06:26.212 14206-14206/com.pythontaro.personaltimetable E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.name, PID: 14206
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.name.appname/com.name.appname.setting.SettingsActivity}: java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:225)
at androidx.preference.Preference.getPersistedString(Preference.java:1686)
at androidx.preference.ListPreference.onSetInitialValue(ListPreference.java:255)
at androidx.preference.Preference.onSetInitialValue(Preference.java:1614)
at androidx.preference.Preference.dispatchSetInitialValue(Preference.java:1587)
at androidx.preference.Preference.onAttachedToHierarchy(Preference.java:1311)
at androidx.preference.Preference.onAttachedToHierarchy(Preference.java:1326)
at androidx.preference.PreferenceGroup.addPreference(PreferenceGroup.java:249)
at androidx.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:170)
at androidx.preference.PreferenceInflater.rInflate(PreferenceInflater.java:345)
at androidx.preference.PreferenceInflater.rInflate(PreferenceInflater.java:346)
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:157)
at androidx.preference.PreferenceInflater.inflate(PreferenceInflater.java:109)
at androidx.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:216)
at androidx.preference.PreferenceFragmentCompat.addPreferencesFromResource(PreferenceFragmentCompat.java:361)
at com.name.appname.setting.SettingsActivity$SettingsFragment.onCreatePreferences(SettingsActivity.java:28)
at androidx.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:160)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1255)
at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1138)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1989)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2629)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1248)
at android.app.Activity.performStart(Activity.java:6679)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2609)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
This is code in Setting Activity Class
public class SettingsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
public static class SettingsFragment extends PreferenceFragmentCompat {
#Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.settings);
}
}}
This is code for string value
<!--Setting-->
<string-array name="setting_header_list">
<item>"Friday(default)"</item>
<item>"Saturday"</item>
<item>"Sunday"</item>
</string-array>
<string-array name="setting_header_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
This is the code of line 225 in SharedPreferencesImpl.java
final StructStat stat;
try {
/*
* Metadata operations don't usually count as a block guard
* violation, but we explicitly want this one.
*/
BlockGuard.getThreadPolicy().onReadFromDisk();
stat = Os.stat(mFile.getPath());
} catch (ErrnoException e) {
return true;
}
From your stack trace this is the key:
Caused by: java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
you are trying to use a java.util.HashSet where a java.lang.String is in use.
It's at SharedPreferencesImpl.java:225 when getString is being called. This is as far as I can go if you do not share the relevant part of your code.
EDIT
As the asker pointed out here in the comment section, the issue was that double quotation marks were used on string-array items.
I got error when detaching (removing) a Fragment from my FragmentManager.
Detaching:
public void onFragmentDetached(String tag) {
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(tag);
if (fragment != null) {
fragmentManager
.beginTransaction()
.disallowAddToBackStack()
.setCustomAnimations(R.anim.slide_left, R.anim.slide_right)
.remove(fragment)
.commitNow();
unlockDrawer();
}
}
Attaching:
getSupportFragmentManager()
.beginTransaction()
.disallowAddToBackStack()
.setCustomAnimations(R.anim.slide_left, R.anim.slide_right)
.replace(R.id.mainRootView, settingsFragment, SettingsFragment.TAG)
.commit();
Here is my error:
E/FragmentManager: No field with the name mListener is found in Animation class
java.lang.NoSuchFieldException: No field mListener in class Landroid/view/animation/Animation; (declaration of 'android.view.animation.Animation' appears in /system/framework/framework.jar!classes3.dex)
at java.lang.Class.getDeclaredField(Native Method)
at androidx.fragment.app.FragmentManagerImpl.getAnimationListener(FragmentManager.java:1301)
at androidx.fragment.app.FragmentManagerImpl.animateRemoveFragment(FragmentManager.java:1638)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1548)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:648)
at com.fearefull.todoreminder.ui.main.MainActivity.onFragmentDetached(MainActivity.java:148)
at com.fearefull.todoreminder.ui.settings.SettingsFragment.goBack(SettingsFragment.java:71)
at com.fearefull.todoreminder.ui.settings.SettingsViewModel.onNavigationBackClick(SettingsViewModel.java:23)
at com.fearefull.todoreminder.databinding.FragmentSettingsBindingImpl._internalCallbackOnClick(FragmentSettingsBindingImpl.java:188)
at com.fearefull.todoreminder.generated.callback.OnClickListener.onClick(OnClickListener.java:11)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3400(View.java:801)
at android.view.View$PerformClick.run(View.java:27301)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
I'm using SDK version 29, How can I fix this?
This bug has been fixed in newer versions of androidx.fragment as mentioned in bug report someone made due to existing issue.
to simply put, just add below line to your build.gradle(:app),
implementation "androidx.fragment:fragment:1.3.3"
The code is working fine without Proguard Rule setup. But when I enabled proguard in release build, The project is build successfully. App is installed successfully but while launching the app it crashed every time .
Here is the error log
2018-10-29 13:52:04.299 1942-1942/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.eighsquare.mcoopon, PID: 1942
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eighsquare.mcoopon/com.eighsquare.mcoopon.ui.splash.SplashActivity}: java.lang.RuntimeException: Cannot create an instance of class com.eighsquare.mcoopon.ui.splash.a
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.RuntimeException: Cannot create an instance of class com.eighsquare.mcoopon.ui.splash.a
at androidx.lifecycle.v$a.a(ViewModelProvider.java:202)
at androidx.lifecycle.v.a(ViewModelProvider.java:135)
at androidx.lifecycle.v.a(ViewModelProvider.java:103)
at com.eighsquare.mcoopon.base.BaseActivity$b.b(**BaseActivity.kt**:32)
at com.eighsquare.mcoopon.base.BaseActivity$b.a(BaseActivity.kt:16)
at kotlin.o.a(LazyJVM.kt:74)
at com.eighsquare.mcoopon.base.BaseActivity.q(Unknown Source:7)
at com.eighsquare.mcoopon.base.BaseActivity.onCreate(BaseActivity.kt:50)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NoSuchMethodException: <init> [class android.app.Application]
at java.lang.Class.getConstructor0(Class.java:2320)
at java.lang.Class.getConstructor(Class.java:1725)
at androidx.lifecycle.v$a.a(ViewModelProvider.java:200)
at androidx.lifecycle.v.a(ViewModelProvider.java:135)
at androidx.lifecycle.v.a(ViewModelProvider.java:103)
at com.eighsquare.mcoopon.base.BaseActivity$b.b(BaseActivity.kt:32)
at com.eighsquare.mcoopon.base.BaseActivity$b.a(BaseActivity.kt:16)
at kotlin.o.a(LazyJVM.kt:74)
at com.eighsquare.mcoopon.base.BaseActivity.q(Unknown Source:7)
at com.eighsquare.mcoopon.base.BaseActivity.onCreate(BaseActivity.kt:50)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
when I click on the BaseActivity.kt I am redirected to this code
val viewModel by lazy {
if (viewModelFactory != null)
ViewModelProviders.of(this, viewModelFactory).get(mViewModelClass)
else ViewModelProviders.of(this).get(mViewModelClass)
}
This code is placed in the BaseActivity to create Viewmodel.
Here is My BaseActivity.kt
abstract class BaseActivity<VM : ViewModel, DB : ViewDataBinding>(private val mViewModelClass: Class<VM>) : AppCompatBaseActivity() {
#LayoutRes
abstract fun getLayoutRes(): Int
abstract val viewModelFactory: ViewModelProvider.Factory?
val binding by lazy {
DataBindingUtil.setContentView(this, getLayoutRes()) as DB
}
val viewModel by lazy {
if (viewModelFactory != null)
ViewModelProviders.of(this, viewModelFactory).get(mViewModelClass)
else ViewModelProviders.of(this).get(mViewModelClass)
}
/**
* If you want to inject Dependency Injection
* on your activity, you can override this.
*/
open fun onInject() {}
open fun initView() {}
override fun onCreate(savedInstanceState: Bundle?) {
onInject()
LayoutInflaterCompat.setFactory2(layoutInflater, IconicsLayoutInflater2(delegate))
super.onCreate(savedInstanceState)
initViewModel(viewModel)
initView()
}
/**
*
* You need override this method.
* And you need to set viewModel to binding: binding.viewModel = viewModel
*
*/
abstract fun initViewModel(viewModel: VM)
fun isNetworkConnected(): Boolean {
return NetworkUtils.isNetworkConnected(this)
}
fun hideKeyboard() {
Utils.hideKeyboard(this)
}
fun changeFragment(fragment: Fragment, cleanStack: Boolean = false, addToBackStack: Boolean = true) {
Utils.changeFragment(this, fragment, cleanStack, addToBackStack)
}
}
I am using Dagger2
I lost my 2 hrs in searching the solution. Stackoverflow is the last hope.
After a long research I got a solution.
I Simply needed to add public #Inject constructor in my ViewModel class
eg;
class FullScreenViewModel public #Inject constructor(application: Application) : BaseViewModel<Any?>(application) {}
I'm using Firebase Facebook auth and trying to fetch profile picture to menu ImageView tried everything but it says same thing.
This is the Code in HomeScreen.java that has menu in it, And my Login is in MainScreen.java if you need other codes please let me know.
public class HomeScreen extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
private CircleImageView mProfile;
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.MyNavTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
mToolbar = (Toolbar) findViewById(R.id.nav_actionbar);
setSupportActionBar(mToolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.opendrawer, R.string.closedrawer);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
/**-------------------Facebook Profile Picture-----------------------*/
mProfile = (CircleImageView) findViewById(R.id.ivProfile);
int dimensionPixelSize = getResources().getDimensionPixelSize(com.facebook.R.dimen.com_facebook_profilepictureview_preset_size_large);
Uri profilePictureUri= Profile.getCurrentProfile().getProfilePictureUri(dimensionPixelSize , dimensionPixelSize);
Glide.with(this).load(profilePictureUri)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(mProfile);
}
ImageView I'm trying to put it in
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ivProfile"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
app:civ_border_width="2dp"
app:civ_border_color="#FFFFFF"/>
Error:
08-02 11:04:46.791 22863-22863/com.shopfolio.shopfolio E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shopfolio.shopfolio, PID: 22863
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shopfolio.shopfolio/com.shopfolio.shopfolio.HomeScreen}: java.lang.IllegalArgumentException: You must pass in a non null View
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException: You must pass in a non null View
at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:678)
at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:448)
at com.shopfolio.shopfolio.HomeScreen.onCreate(HomeScreen.java:56)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
08-02 11:04:46.791 22863-22863/com.shopfolio.shopfolio E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shopfolio.shopfolio/com.shopfolio.shopfolio.HomeScreen}: java.lang.IllegalArgumentException: You must pass in a non null View
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException: You must pass in a non null View
at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:678)
at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:448)
at com.shopfolio.shopfolio.HomeScreen.onCreate(HomeScreen.java:56)
at android.app.Activity.performCreate(Activity.java:6980)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6540)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Sorry if it's not clear enough