android.view.InflateException: Binary XML file line #55 - android

click a button to add Linear Layout within another layout
the on click listener is:
question_next.setOnClickListener {
if(validate()){
question = question_question.text.toString()
marks = question_marks.text.toString()
answer = questions_answer.text.toString()
val questionModel = QuestionModel(question, marks,option_list,null,answer)
question_list.add(questionModel)
CreateAndAppendQuestionListLayout() //62
total_mark += marks.toInt()
total_mark_view.text = "Total marks: "+total_mark.toString()
question_question.text!!.clear()
question_marks.text!!.clear()
questions_answer.text!!.clear()
option_question.removeAllViews()
option_list.clear()
}
}
fun CreateAndAppendQuestionListLayout(){
val finalQuestion = findViewById<LinearLayout>(R.id.final_question)
val layoutInfate = applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
for(i in question_list.indices){
val tempQuestion = layoutInfate.inflate(R.layout.question_,null) //125
val questionNumber = tempQuestion.findViewById<TextView>(R.id.question_layout_number)
val questionStatement = tempQuestion.findViewById<TextView>(R.id.question_layout_question)
val questionMark = tempQuestion.findViewById<TextView>(R.id.question_layout_mark)
val optionView = tempQuestion.findViewById<LinearLayout>(R.id.question_layout_option)
questionNumber.text = (i+1).toString()
questionStatement.text = question_list[i].question.toString()
questionMark.text = question_list[i].mark.toString()
val optionList = question_list[i].option as MutableList
for(j in optionList.indices){
val tempOption = layoutInfate.inflate(R.layout.option_,null)
val optionNumber = tempOption.findViewById<TextView>(R.id.option_no)
val optionText = tempOption.findViewById<TextView>(R.id.option_text)
optionNumber.text = (j+1).toString()
optionText.text = optionList[j]
optionView.addView(tempOption)
}
finalQuestion.addView(tempQuestion)
}
}
whenever i click the button my application is crashed.
Status of logcat is:
2021-05-24 10:39:40.671 6013-6013/com.example.sikyann
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sikyann, PID: 6013
android.view.InflateException: Binary XML file line #55 in com.example.sikyann:layout/question_: Binary XML file line #55 in
com.example.sikyann:layout/question_: Error inflating class
Caused by: android.view.InflateException: Binary XML file line #55 in com.example.sikyann:layout/question_: Error inflating class
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1138)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1099)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at com.example.sikyann.Activity.CreateQuestionPaperActivity.CreateAndAppendQuestionListLayout(CreateQuestionPaperActivity.kt:125)
at com.example.sikyann.Activity.CreateQuestionPaperActivity$onCreate$2.onClick(CreateQuestionPaperActivity.kt:62)
at android.view.View.performClick(View.java:7580)
at android.view.View.performClickInternal(View.java:7531)
at android.view.View.access$3900(View.java:842)
at android.view.View$PerformClick.run(View.java:28871)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:255)
at android.app.ActivityThread.main(ActivityThread.java:8214)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a
descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:221)
at com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:196)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:131)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:110)
at com.google.android.material.textfield.TextInputLayout.(TextInputLayout.java:266)
at com.google.android.material.textfield.TextInputLayout.(TextInputLayout.java:247)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
at android.view.LayoutInflater.createView(LayoutInflater.java:852) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1138) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1099) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:680) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:532) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:479) 
at com.example.sikyann.Activity.CreateQuestionPaperActivity.CreateAndAppendQuestionListLayout(CreateQuestionPaperActivity.kt:125) 
at com.example.sikyann.Activity.CreateQuestionPaperActivity$onCreate$2.onClick(CreateQuestionPaperActivity.kt:62) 
at android.view.View.performClick(View.java:7580) 
at android.view.View.performClickInternal(View.java:7531) 
at android.view.View.access$3900(View.java:842) 
at android.view.View$PerformClick.run(View.java:28871) 
at android.os.Handler.handleCallback(Handler.java:938) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:255) 
at android.app.ActivityThread.main(ActivityThread.java:8214) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
You need to use a theme that is derived from Theme.AppCompat. YOu probably shouldn't be passing in null for the parent view anyway. You're adding it to finalQuestion eventually, just pass finalQuestion in as the parent. That will make it use the theme from finalQuestion, and automatically add it for you.

Related

How to implement library calendar view

I am using this library to make calendar app similar to google calendar week view calendar. I read all documentation and added implementation 'com.jonaswanke.calendar:calendar:0.1.1' in build.gradle, but when I add calendar view to activity_mail.xml
<com.jonaswanke.calendar.CalendarView
android:id="#+id/calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:range="week" />
following exception crashed my app on app start.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 13101
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #9 in com.example.myapplication:layout/activity_main: Binary XML file line #9 in com.example.myapplication:layout/activity_main: Error inflating class com.jonaswanke.calendar.CalendarView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3895)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4074)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8347)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: android.view.InflateException: Binary XML file line #9 in com.example.myapplication:layout/activity_main: Binary XML file line #9 in com.example.myapplication:layout/activity_main: Error inflating class com.jonaswanke.calendar.CalendarView
Caused by: android.view.InflateException: Binary XML file line #9 in com.example.myapplication:layout/activity_main: Error inflating class com.jonaswanke.calendar.CalendarView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:864)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1016)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:971)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1133)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1094)
at android.view.LayoutInflater.inflate(LayoutInflater.java:692)
at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:27)
at android.app.Activity.performCreate(Activity.java:8085)
at android.app.Activity.performCreate(Activity.java:8073)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3868)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4074)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2473)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8347)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/coroutines/experimental/CoroutineDispatcher;
at com.jonaswanke.calendar.CalendarView.<init>(CalendarView.kt:495)
E/AndroidRuntime: at com.jonaswanke.calendar.CalendarView.<init>(CalendarView.kt:32)
at com.jonaswanke.calendar.CalendarView.<init>(Unknown Source:6)
... 28 more
Caused by: java.lang.ClassNotFoundException: kotlinx.coroutines.experimental.CoroutineDispatcher
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 31 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/coroutines/experimental/AbstractCoroutineContextElement;
... 31 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.coroutines.experimental.AbstractCoroutineContextElement" on path: DexPathList[[zip file "/data/app/com.example.myapplication-_1QFEnFxaCJxdEfjNQvp0g==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-_1QFEnFxaCJxdEfjNQvp0g==/lib/arm64, /system/lib64, /hw_product/lib64, /system/product/lib64, /prets/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:209)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 31 more
I/Process: Sending signal. PID: 13101 SIG: 9
In MainActivity.kt file I only added:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
calendar.eventRequestCallback = {
populate(it)
}
}
#Suppress("MagicNumber")
private fun populate(week: Week, force: Boolean = false) {
if (!force && calendar.cachedEvents.contains(week))
return
val events = mutableListOf<Event>()
for (i in 0..15) {
val id = nextId++.toString()
val start = week.start + abs(random.nextLong()) % DateUtils.WEEK_IN_MILLIS
events.add(BaseEvent(
id,
id,
(random.nextInt() or 0xFF000000.toInt()) and 0x00202020.inv(),
start,
start + abs(random.nextLong()) % (DateUtils.DAY_IN_MILLIS / 8)))
}
for (i in 0..3) {
val id = nextId++.toString()
val start = week.start + abs(random.nextLong()) % DateUtils.WEEK_IN_MILLIS
events.add(BaseEvent(
id,
id,
(random.nextInt() or 0xFF000000.toInt()) and 0x00202020.inv(),
start,
start + abs(random.nextLong()) % (DateUtils.DAY_IN_MILLIS * 7),
true))
}
calendar.setEventsForWeek(week, events)
}
But even without this code app still crashes.
This is an old library that was built using experimental Kotlin features. It hasn't been maintained for two years. I tried for 20 minutes to get it to compile. It's just not worth it. I suggest using one of the several other Android CalendarView libraries out there:
https://github.com/search?q=android+calendarview
This one looks particularly promising:
https://github.com/kizitonwose/CalendarView

Android TV player inflating error on PlaybackTransportRowPresenter.createRowViewHolder

I wrote bellow code in fragment that extends 'VideoSupportFragment'
val playerGlue = PlaybackTransportControlGlue(
activity,
MediaPlayerAdapter(activity))
playerGlue.setHost(VideoSupportFragmentGlueHost(this))
playerGlue.addPlayerCallback(object : PlaybackGlue.PlayerCallback() {
override fun onPreparedStateChanged(glue: PlaybackGlue) {
if (glue.isPrepared()) {
//playerGlue.seekProvider = MySeekProvider()
playerGlue.play()
}
}
})
playerGlue.playerAdapter?.setDataSource(Uri.parse("http://techslides.com/demos/sample-videos/small.mp4"))
When setHost is called app crashes and bellow log appears in logcat.
If i comment setHost, just audio get play.
2020-03-15 02:32:15.578 1779-1779/tv.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: tv.debug, PID: 1779
android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #33: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at androidx.leanback.widget.PlaybackTransportRowPresenter.createRowViewHolder(PlaybackTransportRowPresenter.java:684)
at androidx.leanback.widget.RowPresenter.onCreateViewHolder(RowPresenter.java:326)
at androidx.leanback.widget.ItemBridgeAdapter.onCreateViewHolder(ItemBridgeAdapter.java:352)
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at androidx.leanback.widget.GridLayoutManager.getViewForPosition(GridLayoutManager.java:1085)
at androidx.leanback.widget.GridLayoutManager$2.createItem(GridLayoutManager.java:1613)
at androidx.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:113)
at androidx.leanback.widget.Grid.appendOneColumnVisibleItems(Grid.java:389)
at androidx.leanback.widget.GridLayoutManager.appendOneColumnVisibleItems(GridLayoutManager.java:1839)
at androidx.leanback.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:2276)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1897)
at androidx.recyclerview.widget.RecyclerView$1.run(RecyclerView.java:414)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:618)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 68: TypedValue{t=0x2/d=0x7f04005d a=-1}
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:716)
at android.view.View.<init>(View.java:4228)
at android.view.ViewGroup.<init>(ViewGroup.java:579)
at android.widget.LinearLayout.<init>(LinearLayout.java:211)
at android.widget.LinearLayout.<init>(LinearLayout.java:207)
2020-03-15 02:32:15.578 1779-1779/com.shatelland.namava.tv.debug E/AndroidRuntime: at android.widget.LinearLayout.<init>(LinearLayout.java:203)
I don't know why the class is unknown.
i can't find which layout has error because of this.
After long time searching i find the reason.
The Activity that contains the Fragment should set theme to Leanback
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.Theme_Leanback)
}

Instantiating MapBox before inflating the fragment layout cause Exception

I'm following MabBox tutorial at https://docs.mapbox.com/help/tutorials/android-navigation-sdk/ to make a simple navigation fragment that use the basics elements of it.
I already know that MapBox require to instantiate before inflating the View because I made it before on another Fragment to test it out where the fragment is part of a TabLayout component, however, in this one, there's only one Activity that loads the Fragment where I use the SDK and in this case it throws the same error that I fixed previously because I put it afterinflating the layout.
The errore that appears is this one:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.parkingclientapplication, PID: 14257
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.parkingclientapplication/com.example.parkingclientapplication.activities.MapDirectionActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
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:6541)
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: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.mapbox.mapboxsdk.maps.MapView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.parkingclientapplication.activities.MapDirectionActivity.onCreate(MapDirectionActivity.kt:15)
at android.app.Activity.performCreate(Activity.java:6975)
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:6541)
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: com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException:
Using MapView requires calling Mapbox.getInstance(Context context, String accessToken) before inflating or creating the view. The access token parameter is required when using a Mapbox service.
Please see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one.
More information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.
at com.mapbox.mapboxsdk.Mapbox.validateMapbox(Mapbox.java:165)
at com.mapbox.mapboxsdk.Mapbox.getAccessToken(Mapbox.java:77)
at com.mapbox.mapboxsdk.storage.FileSource.<init>(FileSource.java:234)
at com.mapbox.mapboxsdk.storage.FileSource.getInstance(FileSource.java:68)
at com.mapbox.mapboxsdk.maps.renderer.MapRenderer.<init>(MapRenderer.java:34)
E/AndroidRuntime: at com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer.<init>(GLSurfaceViewMapRenderer.java:33)
at com.mapbox.mapboxsdk.maps.MapView$5.<init>(MapView.java:294)
at com.mapbox.mapboxsdk.maps.MapView.initialiseDrawingSurface(MapView.java:294)
at com.mapbox.mapboxsdk.maps.MapView.initialize(MapView.java:137)
at com.mapbox.mapboxsdk.maps.MapView.<init>(MapView.java:100)
... 25 more
The code for the Activity is:
class MapDirectionActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map_direction)
supportFragmentManager.inTransaction {
add(R.id.form_clientNavMenu, MapDirectionFragment())
}
//Logout action on custom toolbar layout
logout.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}
}
The code for the onCreateView method of the Fragment is:
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
Mapbox.getInstance(context!!, getString(R.string.access_token))
val view = inflater.inflate(R.layout.fragment_map_direction, container, false)
mapView = view.findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
// Inflate the layout for this fragment
return view
}
I only wrote onCreateView method because I think the error could be in there instead on the rest of the code which is the same as in the link, but I could be wrong.
Set the method:
Mapbox.getInstance(this,getString(R.string.access_token));
Before the:
setContentView(R.layout.activity_map);
If you having this exception change code structure as follows.
i.e:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this,getString(R.string.access_token));
setContentView(R.layout.activity_map);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
));
}
Thanks #Tobrun for the answer, the problem was not that I missed the accessToken but I mixed activity and fragment layout so the components in one of them should be in the other. However, looking for the accessToken made me realize about other possible ones.

How to use both Kotlin Android Extensions and Databinding at the same time?

I want to make an Android project with Kotlin, so I build it with kotlin and Databinding. It's nothing wrong with it. But when I use Kotlin Android Extensions or Butterknife, the app I built from this project can not be used normally.
Here is my fragment class
class MainFragment: Fragment() {
private var stock: StockQuote? = null
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
val binding: FragmentMainBinding = DataBindingUtil.inflate(inflater!!, R.layout.fragment_main, container, false)
binding.stock = stock
search_et.setOnFocusChangeListener { v, hasFocus ->
if(!hasFocus){
val newStock = ScrapingUtil.getQuote(search_et?.text.toString())
if(newStock != null){
stock?.name = newStock.name
}
}
}
return binding.root
}
}
I tried to use Butterknife at first but it didn't work, the View I want to bind would be null. Then I tried to use Kotlin Android Extensions, it threw an error at runtime
E/AndroidRuntime: FATAL EXCEPTION: main
Process: cn.mister.stockcalculator, PID: 30010
java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.mister.stockcalculator/cn.mister.stockcalculator.MainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2736)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2807)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1604)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:191)
at android.app.ActivityThread.main(ActivityThread.java:6016)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:821)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at cn.mister.stockcalculator.MainActivity.onCreate(MainActivity.kt:10)
at android.app.Activity.performCreate(Activity.java:6370)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2689)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2807) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1604) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:191) 
at android.app.ActivityThread.main(ActivityThread.java:6016) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:821) 
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at cn.mister.stockcalculator.MainActivity.onCreate(MainActivity.kt:10) 
at android.app.Activity.performCreate(Activity.java:6370) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1122) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2689) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2807) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1604) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:191) 
at android.app.ActivityThread.main(ActivityThread.java:6016) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:821) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setOnFocusChangeListener(android.view.View$OnFocusChangeListener)' on a null object reference
at cn.mister.stockcalculator.MainFragment.onCreateView(MainFragment.kt:23)
at android.app.Fragment.performCreateView(Fragment.java:2236)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:962)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1139)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1241)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2236)
at android.app.FragmentController.onCreateView(FragmentController.java:98)
at android.app.Activity.onCreateView(Activity.java:5678)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:41)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
how can I fix it?
I found the answer at Kotlin Android Extensions and Fragments.
DataBinding doesn't matter, you should directly access search_et in the onViewCreated method

Android InflateException caused on Menu Selection

I am using a preference fragment, and I get a exception on my XML. It used to work, but I've tweaked something and now it consistently crashes when I press the 3 dots in the top right hand for the menu.
The actual error is:
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.sherman.android.babynme/org.sherman.android.babynme.Activites.SettingsActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
Here is my activity_settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android='http://schemas.android.com/apk/res/android'
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/activity_settings"
android:name="org.sherman.android.babynme.Fragments.SettingsFragment" />
my preferencesXML:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:defaultValue="Name"
android:key="baby_name"
android:title="Baby's Name" />
<EditTextPreference
android:defaultValue="01/01/01"
android:key="baby_dob"
android:title="Baby's Birthday" />
<EditTextPreference
android:numeric="integer"
android:defaultValue="21"
android:key="mum_age"
android:singleLine="true"
android:title="Your age" />
</PreferenceScreen>
My SettingsActivity.kt:
class SettingsActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
val sharedPreferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
val babyName:String = sharedPreferences.getString("baby_name", "Baby")
title = babyName+" 'n Me"
val actionBar = this.supportActionBar
if(actionBar != null){
actionBar.setDisplayHomeAsUpEnabled(true)
}
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
val id = item?.itemId
if(id == android.R.id.home){
NavUtils.navigateUpFromSameTask(this)
}
return super.onOptionsItemSelected(item)
}
}
And the code for the SettingsFragment:
class SettingsFragment: PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener {
val mContext = context
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_baby)
val sharedPreferences: SharedPreferences = android.preference.PreferenceManager.getDefaultSharedPreferences(activity.applicationContext)
onSharedPreferenceChanged(sharedPreferences, "baby_name")
onSharedPreferenceChanged(sharedPreferences, "baby_dob")
onSharedPreferenceChanged(sharedPreferences, "mum_age")
}
override fun onResume() {
super.onResume()
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)
//activity.getSharedPreferences(context.packageName, Context.MODE_PRIVATE).registerOnSharedPreferenceChangeListener(this)
}
override fun onPause() {
super.onPause()
preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
//activity.getSharedPreferences(context.packageName,Context.MODE_PRIVATE).unregisterOnSharedPreferenceChangeListener(this)
}
override fun onSharedPreferenceChanged(p0: SharedPreferences?, key: String?) {
Log.d(DEBUG, "Ospc called")
val pref: Preference = findPreference(key)
val etp: EditTextPreference = pref as EditTextPreference
pref.setSummary(etp.text)
}
Here is the full error log:
--------- beginning of crash
02-12 19:44:06.931 4518-4518/org.sherman.android.babynme E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.sherman.android.babynme, PID: 4518
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.sherman.android.babynme/org.sherman.android.babynme.Activites.SettingsActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
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:6541)
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: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:255)
at android.support.v7.preference.Preference.getPersistedString(Preference.java:1601)
at android.support.v7.preference.EditTextPreference.onSetInitialValue(EditTextPreference.java:92)
at android.support.v7.preference.Preference.dispatchSetInitialValue(Preference.java:1517)
at android.support.v7.preference.Preference.onAttachedToHierarchy(Preference.java:1245)
at android.support.v7.preference.Preference.onAttachedToHierarchy(Preference.java:1257)
at android.support.v7.preference.PreferenceGroup.addPreference(PreferenceGroup.java:194)
at android.support.v7.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:126)
at android.support.v7.preference.PreferenceInflater.rInflate(PreferenceInflater.java:355)
at android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:162)
at android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:112)
at android.support.v7.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:138)
at android.support.v7.preference.PreferenceFragmentCompat.addPreferencesFromResource(PreferenceFragmentCompat.java:432)
at org.sherman.android.babynme.Fragments.SettingsFragment.onCreatePreferences(SettingsFragment.kt:20)
at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:224)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2339)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1377)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1640)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1896)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3673)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:338)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
02-12 19:44:06.933 4518-4518/org.sherman.android.babynme E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at org.sherman.android.babynme.Activites.SettingsActivity.onCreate(SettingsActivity.kt:15)
at android.app.Activity.performCreate(Activity.java:6975)
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:6541)
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)
My Question is what did I change that caused the menu selection to crash now? (Thank You).
The problem is Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
You must have changed the data types somewhere.

Categories

Resources