Android O Webview crash with DexGuard - android

This crash has only been reproducible in Android 8/8.1 for me. This also only happens in obfuscated builds, unobfuscated builds are not affected. I have tried adding keep rules for the entire codebase and all dependencies and it does not fix the crash, but -dontobfuscate does.
On first launch, the app works fine and when you click a spinner, it pops up the SelectPopupAdapter dialog. On second launch, the same spinner will crash the app if selected. Clearing the app data makes the spinner work again.
The class is a fairly simple webview:
public class WebViewActivity {
#BindView(R.id.web_view)
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
ButterKnife.bind(this);
setupWebSettings();
webView.setWebViewClient(new CustomWebview());
webView.postUrl(url, postData.getBytes());
webView.setOnKeyListener((v, keyCode, event) -> {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
WebView webView = (WebView) v;
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webView.canGoBack()) {
webView.goBack();
return true;
}
break;
}
}
return false;
});
}
private void setupWebSettings() {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
}
#Override
public void onDialogPositiveClick(DialogFragment fragment) {
fragment.dismiss();
finish();
}
#Override
public void finish() {
setResult(RESULT_OK);
super.finish();
}
private class CustomWebview extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
//logging
}
}
}
Here is the crash log:
Crashed: main: 0 0 0x0000000000000000
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:195)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2133)
at android.content.res.Resources.getLayout(Resources.java:1142)
at com.guardsquare.dexguard.CV.getLayout(Unknown Source:94)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:416)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:407)
at org.chromium.content.browser.input.SelectPopupAdapter.getView(SelectPopupAdapter.java:13)
at android.widget.AbsListView.obtainView(AbsListView.java:2372)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1408)
at android.widget.ListView.onMeasure(ListView.java:1315)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at com.android.internal.widget.AlertDialogLayout.tryOnMeasure(AlertDialogLayout.java:144)
at com.android.internal.widget.AlertDialogLayout.onMeasure(AlertDialogLayout.java:69)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:721)
at android.view.View.measure(View.java:21998)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2410)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1471)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1751)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
--
Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:195)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2133)
at android.content.res.Resources.getLayout(Resources.java:1142)
at com.guardsquare.dexguard.CV.getLayout(Unknown Source:94)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:416)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:407)
at org.chromium.content.browser.input.SelectPopupAdapter.getView(SelectPopupAdapter.java:13)
at android.widget.AbsListView.obtainView(AbsListView.java:2372)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1408)
at android.widget.ListView.onMeasure(ListView.java:1315)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at com.android.internal.widget.AlertDialogLayout.tryOnMeasure(AlertDialogLayout.java:144)
at com.android.internal.widget.AlertDialogLayout.onMeasure(AlertDialogLayout.java:69)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:21998)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:721)
at android.view.View.measure(View.java:21998)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2410)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1471)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1751)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Related

App crashing when switching fragments,an error at selectedItemView

Error :
In total, there are three fragments.
The error occurs after going from my third fragment to my first fragment. When going from the second fragment to the fist fragment, my app does not crash.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.direct.indianpeople, PID: 20204
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter selectedItemView
at com.example.senthil.kotlin_tablayout.Fragment.nameFrag$onViewCreated$1.onItemSelected(Unknown Source:2)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:944)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:933)
at android.widget.AdapterView.selectionChanged(AdapterView.java:922)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:1105)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:1081)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:191)
at android.widget.Spinner.onMeasure(Spinner.java:602)
at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:428)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1326)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:355)
at android.view.View.measure(View.java:23355)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1638)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
at android.view.View.measure(View.java:23355)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2919)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1749)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2042)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1637)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7797)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1172)
at android.view.Choreographer.doCallbacks(Choreographer.java:984)
at android.view.Choreographer.doFrame(Choreographer.java:809)
E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.direct.indianpeople, PID: 20204
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter selectedItemView
at com.example.senthil.kotlin_tablayout.Fragment.nameFrag$onViewCreated$1.onItemSelected(Unknown Source:2)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:944)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:933)
at android.widget.AdapterView.selectionChanged(AdapterView.java:922)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:1105)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:1081)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:191)
at android.widget.Spinner.onMeasure(Spinner.java:602)
at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:428)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1326)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:355)
at android.view.View.measure(View.java:23355)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1638)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
at android.view.View.measure(View.java:23355)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2919)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1749)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2042)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1637)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7797)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1172)
at android.view.Choreographer.doCallbacks(Choreographer.java:984)
at android.view.Choreographer.doFrame(Choreographer.java:809)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Code :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
for (state in 0..user.StateName_.size-1){
state_name.add(user.StateName_[state])
state_id.add(user.StateId_[state])
}
spinnerTemp.adapter = ArrayAdapter(this.context!!, android.R.layout.simple_spinner_dropdown_item,state_name)
spinnerTemp.setOnItemSelectedListener(object : OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long){
city_name.clear()
city_state_id.clear()
city_id.clear()
for (state in 0..user.CityName_.size - 1) {
city_state_id.add(user.CityStateId_[state])
if (state_id[position] == city_state_id[state]) {
city_name.add(user.CityName_[state])
city_id.add(user.CityId_[state])
}
}
spinnerTemp2.adapter = ArrayAdapter(
this#nameFrag.context!!,
android.R.layout.simple_spinner_dropdown_item,
city_name
)
}
override fun onNothingSelected(parentView: AdapterView<*>?) {
Toast.makeText(this#nameFrag.context,"${city_id}",Toast.LENGTH_SHORT).show()
}
})
spinnerTemp2.setOnItemSelectedListener(object : OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long){
}
override fun onNothingSelected(parentView: AdapterView<*>?) {
}
} )
get_name.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int,
count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int,
before: Int, count: Int) {
if(check_pass(s.toString()) == true){
button14.setOnClickListener {
val intent = Intent(this#nameFrag.context, Profile2::class.java)
startActivity(intent)
}
}
else if(check_pass(s.toString()) == false)
button14.setOnClickListener{
Toast.makeText(activity?.applicationContext,"No User Found", Toast.LENGTH_LONG).show()
}
}
})
}
Its a fun bit of code that I just wrote, and I am new to android or programming in general, so I cannot figure out what's wrong.
Any help is appreciated.
I don't know what's causing it.
Try using "selectedItemView: View?" instead of "selectedItemView: View" in your arguments in onItemSelected callbacks and see what happens. The methods expect selectedItemView to have nullable type.

Android crash when adding LiveData observer

I'm trying to get a LiveData Observer to work, and everything was working, but after a week my app keeps crashing when attaching the fragment to my activity with the live data. The fragment is very simple, it has a RecyclerView that displays a list of Bloggers in a grid. The ViewModel is the following:
class SimpleBloggersViewModel : ViewModel() {
var bloggers: MutableLiveData<List<Blogger>> = MutableLiveData()
}
And I initialize it in my fragment using:
private val viewModel: SimpleBloggersViewModel by lazy {
ViewModelProvider(this).get(SimpleBloggersViewModel::class.java)
}
The code that causes the crash is the following:
override fun onAttach(context: Context) {
super.onAttach(context)
try {
viewModel.bloggers.observe(viewLifecycleOwner, Observer { changeObserver })
} catch (e: IllegalStateException) {
Log.e(TAG, "onAttach: Failed to attach BloggersFragment.", e)
}
}
Without the try/catch in the onAttach method, I get the following cryptic exception (and an app crash)
Process: com.mydomain.appname, PID: 31393
java.lang.IllegalStateException: Already attached
at androidx.fragment.app.FragmentManager.attachController(FragmentManager.java:3000)
at androidx.fragment.app.Fragment.performAttach(Fragment.java:2622)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1291)
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1264)
at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1147)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:120)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2369)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2327)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2230)
at androidx.fragment.app.FragmentManager$3.run(FragmentManager.java:414)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
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:857)
After adding the try/catch block you see above, the exception ahs a little bit more info, but I still can't figure out what causes the problem.
java.lang.IllegalStateException: You can consumeRestoredStateForKey only after super.onCreate of corresponding component
at androidx.savedstate.SavedStateRegistry.consumeRestoredStateForKey(SavedStateRegistry.java:77)
at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:65)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:177)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:145)
at com.mydomain.appname.Bloggers.BloggersFragment$viewModel$2.invoke(BloggersFragment.kt:31)
at com.mydomain.appname.Bloggers.BloggersFragment$viewModel$2.invoke(BloggersFragment.kt:28)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.mydomain.appname.Bloggers.BloggersFragment.getViewModel(Unknown Source:7)
at com.mydomain.appname.Bloggers.BloggersFragment.onAttach(BloggersFragment.kt:90)
at androidx.fragment.app.Fragment.performAttach(Fragment.java:2638)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1291)
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1264)
at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1147)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:120)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2369)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2327)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:2199)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:236)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:743)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:815)
at android.view.View.measure(View.java:22238)
at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
2019-09-19 12:18:11.181 31963-31963/com.mydomain.appname E/BloggersFragment: at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22238)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6682)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:725)
at android.view.View.measure(View.java:22238)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2531)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1558)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1826)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1446)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7014)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:916)
at android.view.Choreographer.doCallbacks(Choreographer.java:728)
at android.view.Choreographer.doFrame(Choreographer.java:660)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:902)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
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:857)
Please note that I call super on all of the overriding methods, before doing anything else, so the second exception still doesn't help me figure the bug out. Any help is greatly appreciated. Thank you for your time.

"No view found for id for fragment" error of Nested Viewpager

I'm getting an error in the title. Application I also have a mixed structure and use a few nested structures.
There is a structure like " CategoryFragment -> ViewPager -> RecyclerView inside CategoryDetailsFragment -> ViewPager-> HeadlinePagerFragment"
when changed to CategoryFragment then return to back will be this error.
CategoryFragment
val adapter = CategoriesPagerAdapter(activity?.supportFragmentManager!!,list as List<MutableMap<String,String>>)
vp_categories_pager.adapter = adapter
tl_categories.setupWithViewPager(vp_categories_pager)
CategoryDetailsFragment
This class use recyclerview and usage inside of childview viewpager.
rv_category_details.adapter = ContentAdapter(
context!!,this#CategoryDetailsFragment(usage as fragment),
this#CategoryDetailsFragment)
-> Adapter
vp_headline.adapter =HeadlineAdapter(
fragment?.childFragmentManager!!,
items, itemClickListener)
tl_headline_indicator.setupWithViewPager(vp_headline)
HeadlineAdapter
class HeadlineAdapter(
fragment: FragmentManager,
var list:MutableList<MutableMap<*,*>>,
val itemclickListener:ContentAdapter.Itemclicklistener)
:FragmentPagerAdapter(fragment){
override fun getItem(position: Int): Fragment =
HeadlinePagerFragment(PutData(mutableMapOf(
'm' to list[position],
'l' to itemclickListener
)))
override fun getCount(): Int = list.size
override fun getItemPosition(`object`: Any): Int {
return PagerAdapter.POSITION_NONE
}
}
Return this error
No view found for id 0x7f0901de (com.bursadabugun.android:id/vp_headline) for fragment HeadlinePagerFragment{17872d5 (85c9643d-c164-417e-a428-7105105970a1) id=0x7f0901de android:switcher:2131296734:0}
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:875)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2656)
at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2610)
at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2619)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:904)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:434)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2076)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1866)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1821)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1696)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:299)
at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:230)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:22094)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:22094)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6613)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22094)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6613)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22094)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:22094)
at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
at android.view.View.measure(View.java:22094)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6613)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:22094)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6613)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22094)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6613)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22094)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6613)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22094)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6613)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:724)
at android.view.View.measure(View.java:22094)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2483)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1549)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1806)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1432)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6826)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6543)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
Found the solution
I added getItemId function CategoriesPagerAdapter
override fun getItemId(position: Int): Long = View.generateViewId().toLong()

ScrollView.layoutParam is returning Framelayout.layoutParam

I'm trying to set margin dynamically for a scroll view,
Surprisingly, my code is returning FrameLayout.layoutParam instead of ScrollView.LayoutParam here is my code, which is causing Class Cast Exception
ScrollView.LayoutParams scrollViewParam = new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.MATCH_PARENT);
scrollViewParam.setMargins(0, 0, 0, 500);
scrollView.setLayoutParams(scrollViewParam);
here is the stacktrace
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.constraint.ConstraintLayout$LayoutParams
at android.support.constraint.ConstraintLayout.getViewWidget(ConstraintLayout.java:877)
at android.support.constraint.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:643)
at android.support.constraint.ConstraintLayout.updateHierarchy(ConstraintLayout.java:631)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:971)
at android.view.View.measure(View.java:22071)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
at android.view.View.measure(View.java:22071)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22071)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22071)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22071)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:724)
at android.view.View.measure(View.java:22071)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2422)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1504)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
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)
So, What is wrong with my code?
Every view has layout params associated with it's parent ViewGroup.
In your case, your ScrollView must live inside a ConstraintLayout (or a subclass of it). So, when you try to set it's layout params, it'll be expending an instance of a ConstraintLayout.LayoutParams.
Change your code with this and it should work just fine:
ConstraintLayout.LayoutParams scrollViewParam = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT);
scrollViewParam.setMargins(0, 0, 0, 500);
scrollView.setLayoutParams(scrollViewParam);

RecyclerView can not be created in onCreateView in a class with a Fragment extension

I have a problem with the use of RecyclerView, precise that the problem occurs only in onCreateView of a class with extension Fragment.
public class LiveAction extends Fragment {
...
private List<Live> displayList = new ArrayList<>();
private RecyclerView recyclerView;
private LiveAdapter lAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inflatedView = inflater.inflate(R.layout.content_main, container, false);
...
lAdapter = new LiveAdapter(displayList);
//here the problem:
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(lAdapter);
I've already tried to replace getApplicationContext () with getContext (), getActivity (). GetApplicationContext () and others, at most I get another error (for example using getActivity (). GetApplicationContext ()): "Method invocation get 'getApplicationContext 'may produce' java.lang.NullPointerException '... ".
Where am I wrong?
Logicat Error (tested on S7 Edge)
06-21 22:05:46.015 23990-23990/name.app D/AndroidRuntime: Shutting down VM
06-21 22:05:46.021 23990-23990/name.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: name.app, PID: 23990
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at name.app.LiveAction.onCreateView(LiveAction.java:83)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1428)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2215)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:649)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1238)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1086)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1616)
at android.view.View.measure(View.java:23297)
at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)
at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)
at android.view.View.measure(View.java:23297)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1059)
at android.view.View.measure(View.java:23297)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
at android.view.View.measure(View.java:23297)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:23297)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23297)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:23297)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:899)
at android.view.View.measure(View.java:23297)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2844)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1874)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2129)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1743)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7780)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
06-21 22:05:46.022 23990-23990/name.app E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Categories

Resources