Crash on super.onCreate(savedInstanceState) after recreate activity - android-studio

I have two activities in my project ActivityOne and MainActivity.
I start MainActivity using intent from ActivityOne then I toggle dark mode switch in the MainActivity and call recreate() on the activity.
but MainActivity crashes on super.onCreate(savedInstanceState) line when it recreated.
androidx fragment version: 1.2.5
lifecycle version: 2.2.0
MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
val userInterfaceMode = when (UIMode.currentUIMode) {
is UIMode.DarkMode -> AppCompatDelegate.MODE_NIGHT_YES
is UIMode.LightMode -> AppCompatDelegate.MODE_NIGHT_NO
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
AppCompatDelegate.setDefaultNightMode(userInterfaceMode)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
overridePendingTransition(
R.anim.enter_activity_fade_in_anim,
R.anim.enter_activity_fade_out_anim
)
if (savedInstanceState == null){
setupNavigation()
}
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
setupNavigation()
}
private fun setupNavigation(){
if (supportFragmentManager.findFragmentByTag(NAV_HOST_TAG) != null){
val host = supportFragmentManager
.findFragmentByTag(NAV_HOST_TAG) as NavHostFragment
supportFragmentManager
.beginTransaction()
.attach(host)
.setPrimaryNavigationFragment(host)
.commit()
}else{
val host = NavHostFragment.create(R.navigation.navigation_graph)
supportFragmentManager
.beginTransaction()
.add(
R.id.mainActivityRoot, host,
NAV_HOST_TAG
)
.setPrimaryNavigationFragment(host)
.commit()
}
}
Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: me.pitok.goodnews, PID: 6173
java.lang.RuntimeException: Unable to start activity ComponentInfo{MainActivity}: java.lang.IllegalArgumentException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4886)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4795)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:55)
at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:4845)
at android.app.ActivityThread.access$3300(ActivityThread.java:201)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6864)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.IllegalArgumentException
at androidx.lifecycle.LifecycleRegistry.downEvent(LifecycleRegistry.java:263)
at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:314)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:334)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:145)
at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:118)
at androidx.navigation.NavBackStackEntry.updateState(NavBackStackEntry.java:150)
at androidx.navigation.NavBackStackEntry.setMaxLifecycle(NavBackStackEntry.java:130)
at androidx.navigation.NavController.popBackStackInternal(NavController.java:325)
at androidx.navigation.NavController.dispatchOnDestinationChanged(NavController.java:426)
at androidx.navigation.NavController.onGraphCreated(NavController.java:636)
at androidx.navigation.NavController.setGraph(NavController.java:586)
at androidx.navigation.NavController.setGraph(NavController.java:551)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:247)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2685)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1509)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2637)
at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:2583)
at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:236)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:315)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:115)
at me.pitok.goodnews.appMain.MainActivity.onCreate(MainActivity.kt:24)
at android.app.Activity.performCreate(Activity.java:7232)
at android.app.Activity.performCreate(Activity.java:7221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119) 
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:4886) 
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4795) 
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:55) 
at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:4845) 
at android.app.ActivityThread.access$3300(ActivityThread.java:201) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:201) 
at android.app.ActivityThread.main(ActivityThread.java:6864) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 

Seems to be an issue using the same id for the navigation graph and the destination.
https://issuetracker.google.com/issues/161825212
We had a very similar crash and solved it by using a unique id for the navigation graph.

Related

lateinit property mAdapter has not been initialized. How to solve this problem?

MainActivity.kt
class MainActivity : AppCompatActivity(), NewsItemclicked {
private lateinit var mAdapter: NewsListAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
recyclerView.layoutManager = LinearLayoutManager(this)
fetchData()
val adapter = NewsListAdapter( this)
recyclerView.adapter = mAdapter
}
private fun fetchData(){
val url = "https://saurav.tech/NewsAPI/top-headlines/category/sports/in.json"
val jsonObjectRequest = JsonObjectRequest(
Request.Method.GET,
url,
null,
Response.Listener {
val newsJsonArray = it.getJSONArray("articles")
val newsArray = ArrayList<News>()
for(i in 0 until newsJsonArray.length()){
val newsJsonObject = newsJsonArray.getJSONObject(i)
val news = News(
newsJsonObject.getString("title"),
newsJsonObject.getString("author"),
newsJsonObject.getString("url"),
newsJsonObject.getString("urlToImage")
)
newsArray.add(news)
}
mAdapter.updateNews(newsArray)
},
Response.ErrorListener{
}
)
MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest)
}
override fun onItemClicked(item: News) {
}
}
On the above MainActivity.kt of a News app is given.When I try to run the app the app is crashing. It is showing that lateinit property mAdapter has not been initialized. Please help me to figure out the problem.Please try to explain the simplest way as I am a beginner to Android so it is quite difficult to me to understand it quickly.
Error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.newstoday, PID: 10633
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newstoday/com.example.newstoday.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property mAdapter has not been initialized
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property mAdapter has not been initialized
It seems like you're instantiating your adapter and store the reference in a local variable (adapter) instead of the global one (mAdapter) which you specifically created to update its data once you receive the response from the network request.
If you change your code to:
mAdapter = NewsListAdapter(this)
the crash would be solved.

can't use a toast message in the recyclerview

I am making recyclerview in kotlin in android studio. I'm trying to set up an event listener that puts a button in the recyclerview and outputs a toast message. Even if this#[activity name] is entered instead of this in context, a toast message is not displayed. What went wrong?
The error code is as follows.
Unresolved reference: #UpdateActivity
class UpdateActivity : AppCompatActivity() {
private val vBinding by lazy {ActivityUpdateBinding.inflate(layoutInflater)}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(vBinding.root)
var recyclerViewAdapter = CustomAdapter()
recyclerViewAdapter.listData = arrayListOf<String>("a", "b", "c")
vBinding.uploadedRecyclerView.adapter = recyclerViewAdapter
vBinding.uploadedRecyclerView.layoutManager = LinearLayoutManager(this)
} // onCreate End
class CustomAdapter:RecyclerView.Adapter<CustomAdapter.Holder>(){
var listData = arrayListOf<String>()
class Holder(val vBinding:UploadedRecyclerBinding):RecyclerView.ViewHolder(vBinding.root){
fun setData(name:String){
vBinding.name.text = name
vBinding.getBtn.setOnClickListener {
**Toast.makeText(this#UpdateActivity, "test", Toast.LENGTH_SHORT).show()**
// ↑A compilation error occurs here.**
}
}
} // Holder end
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val vBinding = UploadedRecyclerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return Holder(vBinding)
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val name = listData[position]
holder.setData(name)
}
override fun getItemCount(): Int {
return listData.size
}
} // CustomAdapter end
} // UpdateActivity end
you could try put context into constructor of adapter when you create it, and use this context to show a toast. something like this:
class CustomAdapter(
private val mContext: Context
):RecyclerView.Adapter<CustomAdapter.Holder>(){
and in holder class:
Toast.makeText(mContext, "test", Toast.LENGTH_SHORT).show()
finally, when you create adapter in activity:
var recyclerViewAdapter = CustomAdapter(this)
Normally, we'll create adapter class in another file, so use this#UpdateActivity in adapter is bad idea
Instead of using the local context in Toast, always use applicationContext when showing it. So, you should replace that creation of Toast message as,
Toast.makeText(applicationContext, "test", Toast.LENGTH_SHORT).show()

kotlin app crashes when going one to another activity

i have 3 activitiy when i start my app i can go 1 activity to second but i cant go third it crashes
this is code of my third( last activity )
class thirdActivity3 : AppCompatActivity() {
private lateinit var textView: TextView
private lateinit var textView2: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_third3)
textView = findViewById(R.id.textView)
textView2 = findViewById(R.id.textView2)
val extras = intent.extras
if(extras != null){
textView.text = extras.getString("NAME") //getString("NAME","")
textView2.text = extras.getInt("AGE").toString() //getInt("AGE",0).toString()
}
}
}
and this is my second activity
class secondActivity2 : AppCompatActivity() {
private lateinit var inputTextAge:EditText
private lateinit var finishButton: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second2)
inputTextAge=findViewById(R.id.inputTextAge)
finishButton=findViewById(R.id.finishButton)
val extras = intent.extras
var name = ""
if (extras != null){
name=extras.getString("PERSON_NAME","")
}
finishButton.setOnClickListener {
val age = finishButton.text.toString().toInt()
val intent = Intent(this,thirdActivity3::class.java)
intent.putExtra("NAME",name)
intent.putExtra("AGE",age)
startActivity(intent)
}
}
}
i am trying to make wizard for learning but my code have some problems. i have 3 activitys in kotling but when i go second activity to third it's stopping but its workd when i going first to second
2020-11-27 18:50:41.472 19343-19343/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 19343
java.lang.NumberFormatException: For input string: "Finish"
at java.lang.Integer.parseInt(Integer.java:615)
at java.lang.Integer.parseInt(Integer.java:650)
at com.example.myapplication.secondActivity2$onCreate$1.onClick(secondActivity2.kt:33)
at android.view.View.performClick(View.java:7125)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java: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)
this is from logcat
Looking at the error message, it looks like your problem is this line:
val age = finishButton.text.toString().toInt()
The error is saying that you're trying to parse the string "Finish" as a number. It makes sense from this line that you're doing that. You have a button named "Finish". You get the text from the button and then call toInt() on that text, and you get this error.
What do you expect this line to do? Why do you expect querying a button's text to return an integer that represents age?

E/ModuleIdSetter: exception when setting module id. What does this error mean?

I was building an app on android studio and encountered this error E/ModuleIdSetter: exception when setting module id. I have no idea what this error is about and I would like to know what it is and how to resolve it. The full error is below.
2020-07-21 16:07:06.626 28147-28311/? E/ModuleIdSetter: exception when setting module id
java.lang.IllegalStateException: Unable to get current module info in ModuleManager created with non-module Context
at com.google.android.chimera.config.ModuleManager.getCurrentModule(:com.google.android.gms#202414040#20.24.14 (120700-319035315):2)
at aeua.a(:com.google.android.gms#202414040#20.24.14 (120700-319035315):4)
at aeud.b(:com.google.android.gms#202414040#20.24.14 (120700-319035315):9)
at aeql.a(Unknown Source:0)
at rnb.a(:com.google.android.gms#202414040#20.24.14 (120700-319035315):0)
at rjk.c(:com.google.android.gms#202414040#20.24.14 (120700-319035315):1)
at rji.b(:com.google.android.gms#202414040#20.24.14 (120700-319035315):1)
at rlz.b(:com.google.android.gms#202414040#20.24.14 (120700-319035315):6)
at rlz.c(:com.google.android.gms#202414040#20.24.14 (120700-319035315):6)
at rlz.b(:com.google.android.gms#202414040#20.24.14 (120700-319035315):10)
at rlz.a(:com.google.android.gms#202414040#20.24.14 (120700-319035315):17)
at rlz.g(:com.google.android.gms#202414040#20.24.14 (120700-319035315):3)
at sbg.a(:com.google.android.gms#202414040#20.24.14 (120700-319035315):2)
at sag.a(:com.google.android.gms#202414040#20.24.14 (120700-319035315):10)
at rzx.a(:com.google.android.gms#202414040#20.24.14 (120700-319035315):0)
at saa.handleMessage(:com.google.android.gms#202414040#20.24.14 (120700-319035315):28)
at android.os.Handler.dispatchMessage(Handler.java:107)
at aeiw.a(:com.google.android.gms#202414040#20.24.14 (120700-319035315):2)
at aeiw.dispatchMessage(:com.google.android.gms#202414040#20.24.14 (120700-319035315):14)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:67)
System services not available to Activities before onCreate().
For example
This will throw an exception
private var audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
override fun onCreate(savedInstanceState: Bundle?) {
}
But, this won't
private lateinit var audioManager: AudioManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
}

Android Logcat strange errors

I am new to Android app developing. While running my app on Genymotion (I have tried with multiple devices), the gradle builds without error, but the emulator says "Unfortunately, Fictiopedia has stopped.", and the Logcat shows lots of errors I can't understand. It's an app that creates its own words by randomly displaying meaningful parts of actual English words and their definition accordingly. (I deleted a large part of the code with words and their definition to make it fit in this question box)
Thanks for helping.
Here, what the Logcat displays and my code:
LOGCAT:
12-27 11:09:05.099 1946-1946/? E/libprocessgroup: failed to make and chown /acct/uid_10059: Read-only file system
12-27 11:09:05.099 1946-1946/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
12-27 11:09:05.099 1946-1946/? I/art: Late-enabling -Xcheck:jni
12-27 11:09:05.143 1946-1956/? I/art: Debugger is no longer active
12-27 11:09:05.360 1946-1946/? I/InstantRun: starting instant run server: is main process
12-27 11:09:05.454 1946-1946/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-27 11:09:05.690 1946-1946/? W/ResourceType: Failure getting entry for 0x7f060054 (t=5 e=84) (error -75)
12-27 11:09:05.691 1946-1946/? W/ResourceType: Failure getting entry for 0x7f060054 (t=5 e=84) (error -75)
12-27 11:09:05.692 1946-1946/? D/AndroidRuntime: Shutting down VM
--------- beginning of crash
12-27 11:09:05.693 1946-1946/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lauramessner.fictiopedia, PID: 1946
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lauramessner.fictiopedia/com.example.lauramessner.fictiopedia.MainActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.lauramessner.fictiopedia.MainActivity.onCreate(MainActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f060054
at android.content.res.Resources.getValue(Resources.java:1266)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:330)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:58)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.lauramessner.fictiopedia.MainActivity.onCreate(MainActivity.java:26) 
at android.app.Activity.performCreate(Activity.java:5990) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
12-27 11:09:10.334 1946-1946/? I/Process: Sending signal. PID: 1946 SIG: 9
MY CODE:
package com.example.lauramessner.fictiopedia;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public void happen(View b){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView pref = (TextView) findViewById(R.id.pref);
final TextView root = (TextView) findViewById(R.id.root);
final TextView suff = (TextView) findViewById(R.id.suff);
final TextView predef = (TextView) findViewById(R.id.predef);
final TextView rootdef = (TextView) findViewById(R.id.rootdef);
final TextView suffdef = (TextView) findViewById(R.id.suffdef);
final String[] prefixes = {"", "A", "An", "Ab", "Ad", "Ambi", "Ana", "Ante", "Anti", "Apo", "Auto","Bene"};
final String[] roots = {"", "ami", "ann", "anthrop", "aqua"};
final String[] suffixes = {"", "agog", "agogue", "cide", "ectomy"};
ImageButton pushMe = findViewById(R.id.pushMe);
pushMe.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final int rando = (int) (Math.random());
suff.setText(prefixes[rando]);
root.setText(roots[rando]);
pref.setText(suffixes[rando]);
if (pref.getText().toString().contains("")) {
predef.setText("");
}
if (pref.getText().toString().contains("A")) {
predef.setText("not ");
}
if (pref.getText().toString().contains("An")) {
predef.setText("without ");
}
if (pref.getText().toString().contains("Ab")) {
predef.setText("away from ");
}
if (pref.getText().toString().contains("Ad")) {
predef.setText("toward ");
}
if (pref.getText().toString().contains("Ambi")) {
predef.setText("both ");
}
if (pref.getText().toString().contains("Ana")) {
predef.setText("again ");
}
if (pref.getText().toString().contains("Ante")) {
predef.setText("before ");
}
if (pref.getText().toString().contains("Anti")) {
predef.setText("against ");
}
if (pref.getText().toString().contains("Apo")) {
predef.setText("away from ");
}
if (pref.getText().toString().contains("Auto")) {
predef.setText("self ");
}
if (pref.getText().toString().contains("Bene")) {
predef.setText("good ");
}
if (root.getText().toString().contains("")) {
rootdef.setText("");
}
if (root.getText().toString().contains("ami")) {
rootdef.setText("love");
}
if (root.getText().toString().contains("ann")) {
rootdef.setText("year");
}
if (root.getText().toString().contains("anthrop")) {
rootdef.setText("human");
}
if (root.getText().toString().contains("aqua")) {
rootdef.setText("water");
}
if (suff.getText().toString().contains("")) {
suffdef.setText("");
}
if (suff.getText().toString().contains("agog")) {
suffdef.setText("Leader ");
}
if (suff.getText().toString().contains("agogue")) {
suffdef.setText("Leader ");
}
if (suff.getText().toString().contains("cide")) {
suffdef.setText("Act of killing ");
}
if (suff.getText().toString().contains("ectomy")) {
suffdef.setText("Surgical removal of ");
}
}
});
}
}

Resources