0

In Kotlin, in loginButton.setOnClickListener function, the following codes can start ProfileActivity;

  val intent=Intent(this@LoginActivity, ProfileActivity::class.java)
                            startActivity(intent)
                            finish()

From the ProfileActivity, the following codes can start TestActivity;

 val intent=Intent(this@ProfileActivity, TestActivity::class.java)
                            startActivity(intent)
                            finish()

However, I want to start the TestActivity from the LoginActivity. So, I updated the codes by changing only the activity name and the codes are below:

 val intent=Intent(this@LoginActivity, TestActivity::class.java)
                            startActivity(intent)
                            finish()

But, the app crashes before loading activity_test.xml. Why ?

The class in the ProfileActivity.kt is;

class profileActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_profile)

    }
}

The class in the TestActivity.kt is;

class TestActivity : AppCompatActivity() {

    private val QUANT = false
    private val LABEL_PATH = "labels.txt"
    private val INPUT_SIZE = 224 
 
    @RequiresApi(Build.VERSION_CODES.O)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (savedInstanceState != null) {  
            var strResultUri: String? = null
            strResultUri = savedInstanceState.getString(strResultUri)  
          } else { 

            setContentView(R.layout.activity_test) 

            textViewResult = findViewById(R.id.textViewResult)
            textViewResult?.setMovementMethod(ScrollingMovementMethod())
        }
}
}
Ryan M
  • 18,333
  • 31
  • 67
  • 74
Member
  • 87
  • 2
  • 9
  • 3
    Please add crash report too to your question. – JunaidKhan Jul 27 '20 at 13:50
  • Does this answer your question? [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – a_local_nobody Jul 27 '20 at 13:51
  • make sure that TestActivity is registered in manifest . – Mohamed AbdelraZek Jul 27 '20 at 13:54
  • It's very difficult to debug a crash without a stack trace. See [Unfortunately MyApp has stopped. How can I solve this?](/q/23353173) for Android-specific advice, and [What is a stack trace, and how can I use it to debug my application errors?](/q/3988788) for advice on what to do once you have the stack trace. If you still need help, edit your question to include the **complete stack trace**, as well as **which line of your code** the stack trace points to. – Ryan M Jul 27 '20 at 22:31

2 Answers2

0

Most probabely your these lines cause issue:

var strResultUri: String? = null
strResultUri = savedInstanceState.getString(strResultUri)

Because you are passing strResultUri null value as parameter to getString method It should be like this:

strResultUri = savedInstanceState.getString("yourKey")
JunaidKhan
  • 654
  • 7
  • 15
0
var strResultUri: String? = null
strResultUri = savedInstanceState.getString(strResultUri)

What exactly you do here? Passing null inside savedInstanceState.getString() method?

Also, what do you mean by changing only the name? You mean you just changed the context in the following code?

val intent=Intent(this@LoginActivity, TestActivity::class.java)
startActivity(intent)
finish()

That code would work inside login activity for sure.

Also, is that a typing mistake. profileActivity. That's camel case (Not an accepted convention), and you call ProfileActivity::class.java. This shouldn't work. If it's just a typo, ignore it.

JunaidKhan
  • 654
  • 7
  • 15
Mustaqode
  • 453
  • 1
  • 4
  • 14