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.
Related
The start of the activity is causing my app to crash. It isn't the firts OnClick on the app.
NOT WORKING
public void start_motora(View view){
Intent intent = new Intent(getApplicationContext(), MotorActivity.class);
startActivity(intent);
}
WORKING
public void start_app(View view){
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
NOT WORKING 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"
android:orientation="vertical"
android:background="#android:color/white">
<ImageButton
android:onClick="start_motora"
android:id="#+id/motor"
android:layout_width="0dp"
android:layout_height="54dp"
android:layout_marginStart="44dp"
android:layout_marginTop="32dp"
android:background="#drawable/purplebutton"
android:src="#drawable/ic_face_white"
app:layout_constraintEnd_toStartOf="#+id/alfabeto"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text11" />
</androidx.constraintlayout.widget.ConstraintLayout>
WORKING 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=".HomeActivity"
android:background="#ffd500">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logo_sam"
android:onClick="start_app"
android:outlineAmbientShadowColor="#color/yellow"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.494"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="?android:attr/borderlessButtonStyle"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Console Error
The error. I've changed the onClick name and the Activity name, but it's the same problem.
2021-11-03 14:34:03.659 29506-29506/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 29506
java.lang.IllegalStateException: Could not find method teste(View) in a parent or ancestor Context for android:onClick attribute defined on view class androidx.appcompat.widget.AppCompatButton with id 'button2'
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:447)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:405)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Help please. The error does not link to some error in my code, i'm so confused
You must register your MotorActivity activity in your manifest.
<activity android:name=".MotorActivity" />
As i can see the above code,
if you are using Activity then you don't
need to use getApplicationContext() instead
of this you should use this.ActivityName or only this
because Context is define for their specific reason like
example if you are using fragment then you can use context
from onAttach and for Apdater you can use application context.
Please share your error without error i am not sure what is the reason of crash in your app.
for reference check this answer : Android button onClick changing activity cause app to crash
and for context description :- https://medium.com/#banmarkovic/what-is-context-in-android-and-which-one-should-you-use-e1a8c6529652
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 am very new to Android development and I am having an issue with an onClick function in my app. I have five buttons on one activity, and all of them are using the exact same code:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book 2"
android:layout_weight="1"
android:onClick="openBook2"/>
They're obviously adjusted according to the different java functions, which all look like this:
public void openBook2(View view) {
Intent i = new Intent(this, Real2.class);
startActivity(i);
}
The other four functions work perfectly, without error. For some reason, only this function causes a crash. Like I said, I'm new to this so I don't really understand what is going wrong here (or how to properly debug). I ran breakpoints on the openBook2 function and it came back with this in AppCompatViewInflater.java:
#Override
public void onClick(#NonNull View v) {
if (mResolvedMethod == null) {
resolveMethod(mHostView.getContext(), mMethodName);
}
try {
mResolvedMethod.invoke(mResolvedContext, v);
} catch (IllegalAccessException e) {
throw new IllegalStateException(
"Could not execute non-public method for android:onClick", e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(
"Could not execute method for android:onClick", e);
}
}
I don't know what this means. I also know that I should be using a click listener because having the onClick directly in the xml is bad but I have tried to understand click listeners and I truly do not. And, the onClick has been working perfectly fine for me about a hundred other times in the app so I don't see a problem with it (especially since my app is only buttons and TextViews).
If you need any additional information, please let me know!
Logcat error:
2020-04-24 23:37:07.198 19688-19688/co.hyperstudios.elderscrollslibrary E/AndroidRuntime: FATAL EXCEPTION: main
Process: co.hyperstudios.elderscrollslibrary, PID: 19688
java.lang.RuntimeException: Unable to start activity ComponentInfo{co.hyperstudios.elderscrollslibrary/co.hyperstudios.elderscrollslibrary.Real2}: android.view.InflateException: Binary XML file line #75 in co.hyperstudios.elderscrollslibrary:layout/activity_real2: Binary XML file line #75 in co.hyperstudios.elderscrollslibrary:layout/activity_real2: Error inflating class TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #75 in co.hyperstudios.elderscrollslibrary:layout/activity_real2: Binary XML file line #75 in co.hyperstudios.elderscrollslibrary:layout/activity_real2: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #75 in co.hyperstudios.elderscrollslibrary:layout/activity_real2: Error inflating class TextView
Caused by: java.lang.IndexOutOfBoundsException: setSpan (5851 ... 5857) ends beyond length 16
at android.text.SpannableStringInternal.checkRange(SpannableStringInternal.java:490)
at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:196)
at android.text.SpannableStringInternal.setSpan(SpannableStringInternal.java:183)
at android.text.SpannableString.setSpan(SpannableString.java:60)
at android.content.res.StringBlock.applyStyles(StringBlock.java:217)
at android.content.res.StringBlock.get(StringBlock.java:161)
at android.content.res.ApkAssets.getStringFromPool(ApkAssets.java:140)
at android.content.res.AssetManager.getPooledStringForCookie(AssetManager.java:787)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1375)
at android.content.res.TypedArray.getText(TypedArray.java:233)
at android.widget.TextView.<init>(TextView.java:1214)
at android.widget.TextView.<init>(TextView.java:968)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:99)
at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:95)
at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1061)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
2020-04-24 23:37:07.198 19688-19688/co.hyperstudios.elderscrollslibrary E/AndroidRuntime: at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at co.hyperstudios.elderscrollslibrary.Real2.onCreate(Real2.java:14)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
activity_real2 TextView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Real2"
android:orientation="vertical">
<!--Title and author-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginTop="16dp"
android:textColor="#android:color/black"
android:text="The Real Barenziah"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Plitinius Mero" />
<!--Buttons for different parts of the book-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="8dp"
android:paddingTop="8dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book 1"
android:layout_weight="1"
android:onClick="openBook1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book 2"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book 3"
android:layout_weight="1"
android:onClick="openBook3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book 4"
android:layout_weight="1"
android:onClick="openBook4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book 5"
android:layout_weight="1"
android:onClick="openBook5"/>
</LinearLayout>
<!--Book text-->
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/real2"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:paddingRight="16dp"
android:layout_gravity=""
android:textSize="15sp" />
</ScrollView>
</LinearLayout>
Yes, your problem is exactly the ScrollView. ScrollView doesn't work like that it has to have a layout on it to be used. so just add simply a layout on your ScrollView and put your TextView on that layout.
ScrollView > LinearLayout > TextView
(You can change LinearLayout to any ViewGroup type)just like this:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation:"vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/real2"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:paddingRight="16dp"
android:layout_gravity=""
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
Edit:
The Second problem and main problem of your code is probably the long String you had set for TextView just try to reduce the text.
I've updated my android app to use androidx support libs, when running locally everything works fine, runnings automatic tests with google also works.
The problems started to happen when users updated in google play that it just keeps crashing. Uninstalling and reinstalling the app solves the problem.
I have also had a hard time reproducing this locally but I have access to a phone that keeps crashing with the updated version from google play.
From what I can tell the problem has to do with inflating a view
2019-03-27 09:58:58.667 1975-1975/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.android, PID: 1975
android.view.InflateException: Binary XML file line #17: Binary XML file line #1: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #1: 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:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:64)
at com.android.internal.policy.HwPhoneLayoutInflater.onCreateView(HwPhoneLayoutInflater.java:107)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:731)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:799)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:976)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:974)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
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.f.b(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.c.setContentView(AppCompatActivity.java:141)
at com.myapp.android.ui.main.MainActivity.G(MainActivity.java:1224)
at com.myapp.android.ui.main.MainActivity.a(MainActivity.java:106)
at com.myapp.android.ui.main.MainActivity$2.a(MainActivity.java:291)
at com.myapp.android.ui.main.MainActivity$2.onChanged(MainActivity.java:283)
at androidx.lifecycle.LiveData.b(LiveData.java:113)
at androidx.lifecycle.LiveData.a(LiveData.java:131)
at androidx.lifecycle.LiveData.b(LiveData.java:289)
at androidx.lifecycle.p.b(MutableLiveData.java:33)
at androidx.lifecycle.LiveData$1.run(LiveData.java:91)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0400b4 a=-1}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:996)
at android.content.res.TypedArray.getDrawable(TypedArray.java:980)
at android.view.View.<init>(View.java:4746)
at android.view.ViewGroup.<init>(ViewGroup.java:597)
at android.widget.LinearLayout.<init>(LinearLayout.java:237)
at android.widget.LinearLayout.<init>(LinearLayout.java:233)
at android.widget.LinearLayout.<init>(LinearLayout.java:229)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:64)
at com.android.internal.policy.HwPhoneLayoutInflater.onCreateView(HwPhoneLayoutInflater.java:107)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:731)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:799)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:976)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:974)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
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.f.b(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.c.setContentView(AppCompatActivity.java:141)
at com.myapp.android.ui.main.MainActivity.G(MainActivity.java:1224)
at com.myapp.android.ui.main.MainActivity.a(MainActivity.java:106)
at com.myapp.android.ui.main.MainActivity$2.a(MainActivity.java:291)
at com.myapp.android.ui.main.MainActivity$2.onChanged(MainActivity.java:283)
at androidx.lifecycle.LiveData.b(LiveData.java:113)
at androidx.lifecycle.LiveData.a(LiveData.java:131)
at androidx.lifecycle.LiveData.b(LiveData.java:289)
at androidx.lifecycle.p.b(MutableLiveData.java:33)
at androidx.lifecycle.LiveData$1.run(LiveData.java:91)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
I'm not sure if the lines is correct but the error happens here
private void initMainActivity() {
setContentView(R.layout.activity_main);
I've tried to really go through the app to make sure that we are not referencing any old support libs.
Also have set
android.useAndroidX=true
android.enableJetifier=true
without any result.
Any ideas since we are getting a bit lost here.
This only happens when updating to this version from google play, not when testing the app locally och by doing a clean install, confirmed on several devices and os versions.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.myapp.android.ui.main.MainActivity">
<include layout="#layout/activity_top_section" />
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:animateLayoutChanges="true"
android:clipToPadding="false"
android:elevation="-1dp"
android:orientation="vertical"
android:paddingBottom="#dimen/bottom_bar_height"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<include
android:id="#+id/activity_bottom_section"
layout="#layout/activity_bottom_section" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
activity_top_section.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingTop="#dimen/appbar_padding_top"
android:stateListAnimator="#null"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:layout_weight="1"
android:gravity="center"
android:minHeight="#dimen/toolbar_height"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
<include
android:id="#+id/activity_top_section_toolbar_search"
layout="#layout/activity_top_section_toolbar_search" />
<FrameLayout
android:id="#+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layout_scrollFlags="scroll|enterAlways" />
<ImageView
android:id="#+id/toolbar_image"
android:layout_width="#dimen/search_image_view_width"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="#string/image_view_content"
android:src="#drawable/logo_black"
android:visibility="gone" />
<TextView
android:id="#+id/toolbar_title"
style="#style/FontText.Large"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:visibility="gone" />
</androidx.appcompat.widget.Toolbar>
<FrameLayout
android:id="#+id/appbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
app:layout_scrollFlags="scroll|enterAlways" />
</com.google.android.material.appbar.AppBarLayout>
activity_bottom_section.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="#+id/bottom_navigation_view"
android:layout_width="wrap_content"
android:layout_height="#dimen/bottom_bar_parent_height"
android:layout_gravity="bottom">
<View
android:id="#+id/shadow_view"
android:layout_width="match_parent"
android:layout_height="#dimen/default_margin_extra_large"
android:layout_gravity="top"
android:background="#drawable/shadow" />
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="#dimen/bottom_bar_height"
android:layout_gravity="bottom"
android:background="?attr/colorBgLight"
app:itemIconTint="#drawable/navigation_icon_color"
app:menu="#menu/navigation_menu" />
</FrameLayout>
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.