I am going through the android studio 3.0 development essentials Kotlin edition book and am having a problem.
The app crashes and inside the logcat it is saying "Unknown scene name: transitionManager"
I simply don't understand simple errors like this yet since I am new, hopefully someone can help me solve this error.
I am following every step in the book and double checked, so I am guessing this is a error inside the book? or the book is getting old
package com.ebookfrenzy.scenetransitions
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.transition.Scene
import android.view.View
import android.transition.TransitionManager
import android.transition.TransitionInflater
import android.transition.Transition
import kotlinx.android.synthetic.main.activity_scene_transitions.*
class SceneTransitionsActivity : AppCompatActivity() {
var scene1: Scene? = null
var scene2: Scene? = null
var transitionMgr: Transition? = null
#RequiresApi(Build.VERSION_CODES.KITKAT)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scene_transitions)
transitionMgr = TransitionInflater.from(this)
.inflateTransition(R.transition.transition)
scene1 = Scene.getSceneForLayout(rootContainer,
R.layout.scene1_layout, this)
scene2 = Scene.getSceneForLayout(rootContainer,
R.layout.scene2_layout, this)
scene1?.enter()
}
fun goToScene2(view: View) {
TransitionManager.go(scene2, transitionMgr)
}
fun goToScene1(view: View) {
TransitionManager.go(scene1, transitionMgr)
}
}
Logcat
08-14 14:18:25.920 30350-30350/com.ebookfrenzy.scenetransitions E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ebookfrenzy.scenetransitions, PID: 30350
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebookfrenzy.scenetransitions/com.ebookfrenzy.scenetransitions.SceneTransitionsActivity}: java.lang.RuntimeException: Unknown scene name: transitionManager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
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)
Caused by: java.lang.RuntimeException: Unknown scene name: transitionManager
at android.transition.TransitionInflater.createTransitionFromXml(TransitionInflater.java:181)
at android.transition.TransitionInflater.inflateTransition(TransitionInflater.java:79)
at com.ebookfrenzy.scenetransitions.SceneTransitionsActivity.onCreate(SceneTransitionsActivity.kt:27)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
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)
08-14 14:18:25.994 30350-30406/com.ebookfrenzy.scenetransitions I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/egl/libGLESv2_adreno.so from the current namespace instead.
08-14 14:18:25.999 30350-30406/com.ebookfrenzy.scenetransitions D/libEGL: loaded /vendor/lib64/egl/libGLESv2_adreno.so
Project XML's
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rootContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ebookfrenzy.scenetransitions.SceneTransitionsActivity">
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:onClick="goToScene2"
android:text="#string/one"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:onClick="goToScene1"
android:text="#string/two"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/three"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="81dp">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="19dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:onClick="goToScene2"
android:text="#string/one"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="19dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:onClick="goToScene1"
android:text="#string/two"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<transitionManager xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds
android:duration="2000">
</changeBounds>
</transitionManager>
For some reason my XML was:
<?xml version="1.0" encoding="utf-8"?>
<transitionManager xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds
android:duration="2000">
</changeBounds>
</transitionManager>
and was supposed to be
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds
android:duration="2000">
</changeBounds>
</transitionSet>
I don't know why when I created the file the name was "transitionManager", but the change to "transitionSet" is what corrected the problem.
Related
This question already has answers here:
java.lang.RuntimeException: Unable to start activity Componen
(1 answer)
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 1 year ago.
My app is getting crashed on runtime while running this code setupActionBarWithNavController(findNavController(R.id.fragmentContainerView))
I am trying to add a menu bar but the app keeps crashing.
I can't understand the reason here are my files and let me know if any more files need to be added
MainActivity
package com.example.todoappcbpractice2
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.navigation.findNavController
import androidx.navigation.ui.setupActionBarWithNavController
import kotlinx.android.synthetic.main.fragment_list.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupActionBarWithNavController(findNavController(R.id.fragmentContainerView)) //---App crashed here
}
}
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="729dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/my_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/idFragmentList"
android:name="androidx.navigation.fragment.my_nav"
tools:context=".fragments.list.ListFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="#layout/item_todo" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:src="#drawable/ic_baseline_add_24" />
</RelativeLayout>
Error Log
2021-05-21 17:39:35.550 9535-9535/com.example.todoappcbpractice2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.todoappcbpractice2, PID: 9535
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.todoappcbpractice2/com.example.todoappcbpractice2.MainActivity}: java.lang.IllegalStateException: Activity com.example.todoappcbpractice2.MainActivity#8b7265a does not have a NavController set on 2131230896
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3310)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3459)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2046)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.IllegalStateException: Activity com.example.todoappcbpractice2.MainActivity#8b7265a does not have a NavController set on 2131230896
at androidx.navigation.Navigation.findNavController(Navigation.java:61)
at androidx.navigation.ActivityKt.findNavController(Activity.kt:30)
at com.example.todoappcbpractice2.MainActivity.onCreate(MainActivity.kt:17)
at android.app.Activity.performCreate(Activity.java:7916)
at android.app.Activity.performCreate(Activity.java:7903)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3285)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3459)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2046)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
I am new in Kotlin Android Dev so let me know any improvements advice.
enter image description hereI`m new in programming and i checked every q\a i could, but didnt find a working solution for my issue :(
Whenever i start an app, it immediately crashes with a message "Appname keeps stopping". I got ClassNotFoundException and InflateException, all dependencies in gradle are installed correctly, the path to the file is correct as well (at least i think so). It is an educational project, part of it was predownloaded. There is single activity with a single fragment in it, which should be active upon app launch.
Screenshots with current path:
1
2
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.unscramble, PID: 7717
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.unscramble/com.example.android.unscramble.MainActivity}: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class androidx.fragment.app.FragmentContainerView
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: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.android.unscramble.ui.game.GameFragment: make sure class name exists
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:97)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:611)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:171)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:52)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:319)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:298)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
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 androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:302)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:115)
at com.example.android.unscramble.MainActivity.onCreate(MainActivity.kt:28)
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.ClassNotFoundException: com.example.android.unscramble.ui.game.GameFragment
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at androidx.fragment.app.FragmentFactory.loadClass(FragmentFactory.java:53)
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:94)
... 34 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.unscramble.ui.game.GameFragment" on path: DexPathList[[zip file "/data/app/com.example.android.unscramble-SMPtJZpeKsSBNf3fCMLZeg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.unscramble-SMPtJZpeKsSBNf3fCMLZeg==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 38 more
The only line, that seems weird to me is this one. However, i dont know what to do with it.
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.unscramble.ui.game.GameFragment" on path: DexPathList[[zip file "/data/app/com.example.android.unscramble-SMPtJZpeKsSBNf3fCMLZeg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.unscramble-SMPtJZpeKsSBNf3fCMLZeg==/lib/x86, /system/lib, /vendor/lib]]
Here are code snippets:
GameFragment.kt
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.example.android.unscramble.R
import com.example.android.unscramble.databinding.GameFragmentBinding
import com.example.android.unscramble.ui.game.MAX_NO_OF_WORDS
import com.example.android.unscramble.ui.game.allWordsList
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class GameFragment : Fragment(R.layout.game_fragment) {
private val viewModel: GameViewModel by viewModels()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
// Inflate the layout XML file and return a binding object instance
binding = GameFragmentBinding.inflate(inflater, container, false)
Log.d("GameFragment", "GameFragment created/re-created!")
Log.d("GameFragment", "Word: ${viewModel.currentScrambledWord} " +
"Score: ${viewModel.score} WordCount: ${viewModel.currentWordCount}")
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.submit.setOnClickListener { onSubmitWord() }
binding.skip.setOnClickListener { onSkipWord() }
updateNextWordOnScreen()
binding.score.text = getString(R.string.score, 0)
binding.wordCount.text = getString(
R.string.word_count, 0, MAX_NO_OF_WORDS)
}
MainActivity.kt
package com.example.android.unscramble
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity(R.layout.main_activity) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
}
}
main_activity.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/game_fragment"
android:name="com.example.android.unscramble.ui.game.GameFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
game_fragment.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/default_padding"
tools:context=".ui.game.GameFragment">
<Button
android:id="#+id/skip"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/default_padding"
android:layout_marginEnd="#dimen/default_padding"
android:text="#string/skip"
app:layout_constraintBaseline_toBaselineOf="#+id/submit"
app:layout_constraintEnd_toStartOf="#+id/submit"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/submit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_margin"
android:text="#string/submit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/skip"
app:layout_constraintTop_toBottomOf="#+id/textField" />
<TextView
android:id="#+id/textView_instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/instructions"
android:textSize="17sp"
app:layout_constraintBottom_toTopOf="#+id/textField"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_unscrambled_word" />
<TextView
android:id="#+id/textView_unscrambled_word"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_margin"
android:layout_marginBottom="#dimen/default_margin"
android:textAppearance="#style/TextAppearance.MaterialComponents.Headline3"
app:layout_constraintBottom_toTopOf="#+id/textView_instructions"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/word_count"
tools:text="Scramble word" />
<TextView
android:id="#+id/word_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/word_count"
android:textAppearance="#style/TextAppearance.MaterialComponents.Headline6"
app:layout_constraintBottom_toTopOf="#+id/textView_unscrambled_word"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="3 of 10 words" />
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/score"
android:textAllCaps="true"
android:textAppearance="#style/TextAppearance.MaterialComponents.Headline6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Score: 20" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textField"
style="#style/Widget.Unscramble.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/default_margin"
android:hint="#string/enter_your_word"
app:errorIconDrawable="#drawable/ic_error"
app:helperTextTextAppearance="#style/TextAppearance.MaterialComponents.Subtitle1"
app:layout_constraintBottom_toTopOf="#+id/submit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_instructions">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/text_input_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPersonName|textNoSuggestions"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
My best guess is that the package line at the top of your GameFragment file does not match the directory in which you have the file. Kotlin allows you to do that, though you should be getting a warning about it in the IDE. So, while the file is positioned in the correct place, the package line says what package Kotlin will use for the class. If the package line has something else — or is missing entirely — that would explain your error.
Ideally, Kotlin source follows the Java rule: the package and the directory are in alignment, using the same segments in each. In your case, that would mean that the package line at the top of GameFragment.kt should be:
package com.example.android.unscramble.ui.game
Try to inflate Game Fragment dynamically by doing this:
in main_activity.xml place:
<FrameLayout
android:id="#+id/fragmentContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
Instead of
<androidx.fragment.app.FragmentContainerView
android:id="#+id/game_fragment"
android:name="com.example.android.unscramble.ui.game.GameFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
Then in Main Activity's onCreate call this:
supportFragmentManager.beginTransaction().replace(R.id.fragmentContainer, GameFragment()).commit()
i'm making my first app.
it is a simple application with a splash screen and the main activity and now with flavours i have two build variants:
Free Version: With Admob banner on bottom of the activity
Paid Version: The app don't show admob banner on the bottom but replace it with a Bottom Navigation View for switch activity ( i will add another activity for this).
I tell you that before i add this Bottom Navigation View all part of application work properly, include Build variants.
This is what i did for add Botttom Navigation Menu:
First i put the Bottom Navigation View on the bottom of the xml activity file:
valutausato.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="8dp"
android:layout_centerHorizontal="true">
<TextView
android:id="#+id/TitoloText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="VALUTA IL TUO USATO"
android:textSize="32dp"
android:textAlignment="center"
android:textColor="#color/colorPrimaryDark"
android:fontFamily="sans-serif-condensed"
android:layout_weight="1"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginTop="70dp"
android:layout_marginHorizontal="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Prezzo In Negozio:"
android:fontFamily="sans-serif"
android:textStyle="bold|italic"
android:textColor="#111"
android:textSize="22dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_centerHorizontal="true">
<EditText
android:id="#+id/ProdottoNuovoTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="2dp"
android:layout_weight="1"
android:inputType="numberDecimal"
android:digits="0123456789."
android:maxLength="30"
android:text="Inserisci qui il prezzo.."
android:textSize="22dp"
android:fontFamily="sans-serif-condensed"
android:textColor="#color/colorPrimary"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In Garanzia"
android:layout_marginRight="0dp"
android:textSize="17dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Condizioni prodotto"
android:fontFamily="sans-serif"
android:textColor="#111"
android:textStyle="bold|italic"
android:textSize="22dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="250dp"
android:layout_centerHorizontal="true"
android:layout_marginHorizontal="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<Spinner
android:id="#+id/ProdottoDanneggiatospn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginRight="0dp"
android:textColor="#color/colorPrimary"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="290dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accessori"
android:layout_weight="1"
android:fontFamily="sans-serif"
android:textStyle="bold|italic"
android:textColor="#111"
android:textSize="22dp"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="340dp"
android:layout_centerHorizontal="true"
android:layout_marginHorizontal="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Spinner
android:id="#+id/PartiMancantispn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginRight="0dp"
android:textColor="#color/colorPrimary"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="400dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/BtnCalcola"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calcola"
android:background="#color/ColorButton"
android:layout_weight="1"
android:fontFamily="sans-serif-smallcaps"
android:textStyle="bold|italic"
android:textSize="17dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="470dp"
android:layout_weight="1">
<TextView
android:id="#+id/FormPrezzoFinale"
android:textSize="22dp"
android:fontFamily="sans-serif-condensed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#002F80"
android:layout_weight="1"
android:text="prova"/>
</LinearLayout>
<android.support.design.internal.BottomNavigationView
android:id="#+id/MenuBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#drawable/background_menu_color"
app:itemTextColor="#drawable/background_menu_color"
app:menu="#menu/background_menu_main"/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/SmartBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="60dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
After this i setup my app.build.gradle file with correct dependencies
app.build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.viniusapp.value"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "version"
productFlavors {
freeVersion {
dimension "version"
applicationId "com.viniusapp.value.lite"
versionName = "1.0-lite"
}
paidVersion {
dimension "version"
applicationId "com.viniusapp.value.premium"
versionName = "1.0-premium"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile 'com.android.support:design:26.1.0'
}
Later i create in the drawable folder the file for the bottom navigation view
background_menu_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorPrimaryDark" android:state_enabled="true"/>
<item android:color="#color/colorPrimary" android:state_enabled="true"/>
</selector>
And finally i create "menu"folder in the main res folder and create the xml file for menu item and create two image assets for this two actions.
background_menu_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/Action_Value"
android:enabled="true"
android:icon="#drawable/ic_value"
android:title="Valuta"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/Action_Search"
android:enabled="true"
android:icon="#drawable/ic_search"
android:title="Cerca Sul Web"
app:showAsAction="ifRoom"
/>
</menu>
The last thing i did is add BottomNavigation view in java file (I remove all the rest of the code that was useless for this problem)
package com.vkapp.valutatoreusato;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.internal.BottomNavigationMenuView;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import junit.runner.Version;
import java.lang.reflect.Type;
public class ValutaUsato extends Activity {
int Iva = 22;
double PriceProductNew;
double SalePriceOfProduct = 0;
boolean FirstLaunch = true;
int NumeroUtilizziTotali = 0;
Button BtnCalcola = null;
EditText PriceProductNewTxt = null;
TextView SalePriceText = null;
Spinner DamageProductState = null;
Spinner MissPartProductState = null;
InterstitialAd mInterstitialAd;
AdView SmartBanner;
BottomNavigationMenuView BottomNavigationMenuMoveForMove = null;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
BtnCalcola = (Button) findViewById(R.id.BtnCalcola);
BtnCalcola.setEnabled(false);
PriceProductNewTxt = (EditText) findViewById(R.id.ProdottoNuovoTxt);
SalePriceText = (TextView) findViewById(R.id.FormPrezzoFinale);
DamageProductState = (Spinner) findViewById(R.id.ProdottoDanneggiatospn);
MissPartProductState = (Spinner) findViewById(R.id.PartiMancantispn);
BottomNavigationMenuMoveForMove = (BottomNavigationMenuView) findViewById(R.id.MenuBottom);
BottomNavigationMenuMoveForMove.setEnabled(false);
super.onCreate(savedInstanceState);
setContentView(R.layout.valutausato);
if (BuildConfig.FLAVOR.equals("freeVersion")) {
Log.d("TAG", "Free Version running");
Log.d("TAG", BuildConfig.APPLICATION_ID);
Log.d("TAG", BuildConfig.VERSION_NAME);
MobileAds.initialize(this, "ca-app-pub-3526806334939799/1381568933");
SmartBanner = findViewById(R.id.SmartBanner);
AdRequest adRequest = new AdRequest.Builder().build();
SmartBanner.loadAd(adRequest);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
;
}
if (BuildConfig.FLAVOR.equals("paidVersion")) {
Log.d("TAG", "Paid Version running");
BottomNavigationMenuMoveForMove.setEnabled(true);
Log.d("TAG", BuildConfig.APPLICATION_ID);
Log.d("TAG", BuildConfig.VERSION_NAME);
}
}
}
After that my project look like this:
Project Structure
Preview of main activity
But now when i deubg/run the app the splash screen work good but when the main activity start the app crash with this errors:
01-11 18:07:54.000 7279-7279/com.viniusapp.value.lite E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.viniusapp.value.lite, PID: 7279
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.viniusapp.value.lite/com.vkapp.valutatoreusato.ValutaUsato}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.internal.BottomNavigationView
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: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.internal.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.design.internal.BottomNavigationView
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.internal.BottomNavigationView" on path: DexPathList[[zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/base.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.viniusapp.value.lite-yk6VQ4PuiYd-h1puOhz6iA==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:419)
at android.app.Activity.setContentView(Activity.java:2669)
at com.vkapp.valutatoreusato.ValutaUsato.onCreate(ValutaUsato.java:66)
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)
I see that this error
at com.vkapp.valutatoreusato.ValutaUsato.onCreate(ValutaUsato.java:66)
link me this statement
BottomNavigationMenuMoveForMove = (BottomNavigationMenuView) findViewById(R.id.MenuBottom);
I hope this is all clear for you.
Thanks for any help
You are using wrong class in your xml code. It should be:
<android.support.design.widget.BottomNavigationView
instead of
<android.support.design.internal.BottomNavigationView
Difference is in keywords: internal and widget.
Next inside your Activity change BottomNavigationMenuView to BottomNavigationView. Also make sure that
super.onCreate(savedInstanceState);
setContentView(R.layout.valutausato)
code is on top of onCreate not after connecting with IDs.
Copy all drawables from "drawable-v21" folder to "drawable".
You are using the wrong class. You have BottomNavigationMenuView object in the code but your actual view is BottomNavigationView.
Change your code to this instead:
BottomNavigationView bottomNavView = (BottomNavigationView) findViewById(R.id.MenuBottom);
add the following lines in proguard-rules.pro file:
-dontwarn org.xmlpull.v1.XmlPullParser
-dontwarn org.xmlpull.v1.XmlSerializer
-keep class org.xmlpull.v1.* {*;}
So I think I'm having some scoping issues.
I'm trying to use the function setZipEdit to set the R.id.zipHolder editText in my activity. I'm just having issues in setting up the code to be able to do this. Below is what I have which isn't currently working. mZipHold is coming back as not initialized which I though it was in the override
UPDATED
class SecondActivity : AppCompatActivity() {
lateinit var townInfo:JsonArray<JsonObject>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity2)
SET_TOWN.setOnClickListener {v -> setTowns()}
GET_TOWNS.setOnClickListener {v -> retrieveTowns()}
}
fun setZipEdit(zipEdit:String){
Log.d("SZE",zipEdit)
zipHolder.setText(zipEdit)
//mZipHold.setText(zipEdit,TextView.BufferType.EDITABLE)
}
java.lang.NullPointerException: Attempt to invoke virtual method
'android.view.Window$Callback android.view.Window.getCallback()' on a
null object reference
at
android.support.v7.app.AppCompatDelegateImplBase.(AppCompatDelegateImplBase.java:117)
at
android.support.v7.app.AppCompatDelegateImplV9.(AppCompatDelegateImplV9.java:149)
at
android.support.v7.app.AppCompatDelegateImplV11.(AppCompatDelegateImplV11.java:29)
at
android.support.v7.app.AppCompatDelegateImplV14.(AppCompatDelegateImplV14.java:54)
at
android.support.v7.app.AppCompatDelegateImplV23.(AppCompatDelegateImplV23.java:31)
at
android.support.v7.app.AppCompatDelegateImplN.(AppCompatDelegateImplN.java:31)
at
android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:198)
at
android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
at
android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at
android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at
com.example.sdfsdf.listview.SecondActivity._$_findCachedViewById(SecondActivity.kt:0)
at
com.example.sdfsdf.listview.SecondActivity.setZipEdit(SecondActivity.kt:44)
at
com.example.sdfsdf.listview.SecondActivity$MyCustomAdapter$onCreateViewHolder$1.onClick(SecondActivity.kt:124)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24697)
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(Native Method)
at
com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="25dp">
<ImageView
android:id="#+id/returnimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="8dp"
android:layout_marginTop="20dp"
android:contentDescription="logoforZip"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_new_icon_plain" />
<EditText
android:id="#+id/zipHolder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="8dp"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="number"
android:text="ZIP HERE"
android:textAlignment="center"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/returnimage"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/SET_TOWN"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:text="SET TOWN"
app:layout_constraintEnd_toEndOf="#+id/zipHolder"
app:layout_constraintStart_toStartOf="#+id/zipHolder"
app:layout_constraintTop_toBottomOf="#+id/zipHolder" />
<Button
android:id="#+id/GET_TOWNS"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:text="LIST NEARBY TOWNS"
app:layout_constraintEnd_toEndOf="#+id/SET_TOWN"
app:layout_constraintStart_toStartOf="#+id/SET_TOWN"
app:layout_constraintTop_toBottomOf="#+id/SET_TOWN" />
<View
android:id="#+id/splitbar"
android:layout_width="fill_parent"
android:layout_height="6dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="#c0c0c0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/GET_TOWNS" />
<android.support.v7.widget.RecyclerView
android:id="#+id/zipList"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#222222"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/splitbar" />
</android.support.constraint.ConstraintLayout>
Ok, But using kotlinextension is a better way to do this, I think you need to do 2 things may solve your problem
first
import kotlinx.android.synthetic.main.activity_main2.*
I think which you have already done
second instead of initializing your Editext by findViewById direct use as
fun setZipEdit(zipEdit:String){
Log.d("SZE",zipEdit)
Log.d("mzh",mZipHold.toString())
zipHolder.setText(zipEdit)
//mZipHold.setText(zipEdit,TextView.BufferType.EDITABLE)
}
you can access your views by only use their id. Let try this and let me know if works
I'm using the following library: https://github.com/deano2390/MaterialShowcaseView
I've been trying to find a way (for 2 days straight!) to always position the "GOT IT" button on the bottom left corner of the screen. How do I achieve that simply and effectively?
I will immediately accept the working answer. As you can see, I have a history of always accepting answers.
With Osama's answer, I get error:
com.example.me.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.me.myapplication, PID: 4445
java.lang.IllegalStateException: Cannot start this animator on a detached view!
at android.view.RenderNode.addAnimator(RenderNode.java:812)
at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:300)
at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:282)
at android.animation.RevealAnimator.<init>(RevealAnimator.java:37)
at android.view.ViewAnimationUtils.createCircularReveal(ViewAnimationUtils.java:55)
at uk.co.deanwild.materialshowcaseview.CircularRevealAnimationFactory.animateInView(CircularRevealAnimationFactory.java:29)
at uk.co.deanwild.materialshowcaseview.MaterialShowcaseView.animateIn(MaterialShowcaseView.java:825)
at uk.co.deanwild.materialshowcaseview.MaterialShowcaseView$1.run(MaterialShowcaseView.java:794)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
MainActivity:
package com.example.me.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// single example
new MaterialShowcaseView.Builder(this)
.setTarget(findViewById(R.id.hi))
.setDismissText("GOT IT")
.setContentText("This is some amazing feature you should know about! Indeed, this is just an example of a bug that can be easily fixed!")
.show();
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.me.myapplication.MainActivity">
<TextView
android:id="#+id/hi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.419" />
</android.support.constraint.ConstraintLayout>
This lib is based on ShowcaseView, take a look at it.
You can also go to the showcase_content.xml at the library module and put the tv_dismiss that is the "GOT IT" TextView into a RelativeLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_box"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:weightSum="1">
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:paddingLeft="5dp"
android:textColor="#android:color/white"
android:textSize="30dp" />
<TextView
android:id="#+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textColor="#android:color/white"
android:textSize="20dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tv_dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_alignParentBottom="true"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="10dp"
android:textColor="#android:color/white"
android:textSize="22dp"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
Go to MaterialShowcaseView.java and empty the applyLayoutParams() method and update the setDelay to 1000
Within the builder, add the following code.
mDismissButton.setGravity(Gravity.BOTTOM);