package com.example.myapplication
import android.app.Activity
import android.content.Context
import android.os.*
import android.util.Log
import android.view.DragEvent
import android.view.MotionEvent
import android.view.ScaleGestureDetector
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintSet
import androidx.wear.widget.SwipeDismissFrameLayout
class MetroMapActivity : Activity()
{
private lateinit var image:ImageView
private var gesture:ScaleGestureDetector? = null
private var scaleFactor = 1.0f
private lateinit var swipeview:SwipeDismissFrameLayout
private lateinit var toast: Toast
private lateinit var buttonone:Button
private lateinit var vibratorManager: VibratorManager
private lateinit var vibrator: Vibrator
#RequiresApi(Build.VERSION_CODES.S)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_metro_map)
swipeview = findViewById(R.id.swipe)
toast = Toast.makeText(this,"a",Toast.LENGTH_SHORT)
image = findViewById(R.id.metromap)
buttonone = findViewById<Button>(R.id.button)
gesture = ScaleGestureDetector(this, ScaleListener())
swipeview.setOnTouchListener(swipetouch())
buttonone.setOnTouchListener(buttontouch())
vibratorManager = this.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
//vibrator = vibratorManager.defaultVibrator
//vibrator.vibrate(VibrationEffect.createOneShot(100, 30))
//image.setOnTouchListener(imagetouch())
}
i'm making wearOS applincation.
when i call getSystemService() i get NullPointerException. it seems getSystemService() keep returns null but i don't know why.
i also wrote <uses-permission android:name="android.permission.VIBRATE"/ > in AndroidManifest.xml.
i can't even get clue. please help...please....
i once wrote getSystemService() at OnResume() because someone told me that it
something is not initialized yet(?) but it also was not working.
this is stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 27345
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.NullPointerException: null cannot be cast to non-null type android.os.VibratorManager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3456)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3612)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
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:2073)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:7690)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
Caused by: java.lang.NullPointerException: null cannot be cast to non-null type android.os.VibratorManager
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:31)
at android.app.Activity.performCreate(Activity.java:8009)
at android.app.Activity.performCreate(Activity.java:7993)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3429)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3612)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
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:2073)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:7690)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
I/Process: Sending signal. PID: 27345 SIG: 9
VIBRATOR_MANAGER_SERVICE was added in API level 31 (Android 12) and devices running on lower API levels know nothing about it.
On older API levels you can use VIBRATOR_SERVICE instead to retrieve a Vibrator (rather than a VibratorManager).
Related
I'm just starting with the Mapbox implementation in a native Android app and I just can't get it done.
The most basic thing (instantiating a MapboxNavigation can not be done). I get this error and the app closes:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.testemapbox, PID: 29380
java.lang.NoSuchMethodError: No static method getInstance()Lcom/mapbox/common/LogConfiguration; in class Lcom/mapbox/common/LogConfiguration; or its super classes (declaration of 'com.mapbox.common.LogConfiguration' appears in /data/app/~~CoIOdGRtIbaTlwz2rI-MFg==/com.example.testemapbox-_1CkcSTRk6UI5QXFz-w_6g==/base.apk)
at com.mapbox.navigation.utils.internal.LoggerProvider.initialize(LoggerProvider.kt:23)
at com.mapbox.navigation.core.MapboxNavigation.<init>(MapboxNavigation.kt:396)
at com.mapbox.navigation.core.MapboxNavigation.<init>(MapboxNavigation.kt:223)
at com.mapbox.navigation.core.MapboxNavigationProvider.create(MapboxNavigationProvider.kt:23)
at com.example.testemapbox.MainActivity.onCreate(MainActivity.kt:20)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
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:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
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)
And here is the snippet of my code:
package com.example.testemapbox
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.mapbox.navigation.base.options.NavigationOptions
import com.mapbox.navigation.base.trip.model.RouteProgress
import com.mapbox.navigation.core.MapboxNavigationProvider
import com.mapbox.navigation.core.trip.session.RouteProgressObserver
class MainActivity : AppCompatActivity(), RouteProgressObserver {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navigationOptions = NavigationOptions.Builder(this)
.accessToken(getString(R.string.mapbox_access_token))
.build()
val mapboxNavigation = MapboxNavigationProvider.create(navigationOptions)
}
}
I need to know if I'm doing something wrong. I know the code isn't useful (just don't do anything) but I suppose that I should have to be able to do something like that.
When I try an app I was developing in the Android Studio emulator, the following message appears: 'App keeps stopping' and it doesn't open.
This is the code for the MainActivity:
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import com.example.bookapplication.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val navController = findNavController(R.id.nav_host_fragment_content_main)
appBarConfiguration = AppBarConfiguration(navController.graph)
setupActionBarWithNavController(navController, appBarConfiguration)
binding.libroLeidos.setOnClickListener { Toast.makeText(this, "Entrando en Libros Leídos", Toast.LENGTH_LONG).show()
val primerIntent = Intent(this, librosLeidos::class.java)
startActivity(primerIntent)
}
binding.libroPendiente.setOnClickListener { Toast.makeText(this, "Entrando en Libros Pendientes", Toast.LENGTH_LONG).show()
val segundoIntent = Intent(this, librosPendientes::class.java)
startActivity(segundoIntent)
}
}}
On the other hand, in the LogCat, I get this message:
Process: com.example.bookapplication, PID: 14919
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bookapplication/com.example.bookapplication.MainActivity}: java.lang.IllegalArgumentException: ID does not reference a View inside this Activity
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: java.lang.IllegalArgumentException: ID does not reference a View inside this Activity
at android.app.Activity.requireViewById(Activity.java:3231)
at androidx.core.app.ActivityCompat.requireViewById(ActivityCompat.java:368)
at androidx.navigation.Navigation.findNavController(Navigation.java:58)
at androidx.navigation.ActivityKt.findNavController(Activity.kt:30)
at com.example.bookapplication.MainActivity.onCreate(MainActivity.kt:24)
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)
The problem is that I don't know where to go to fix it. I am new to this and there are many things that are beyond me. I have found other similar questions but I have not understood well how to proceed.
Thank you very much.
The stacktrace from logcat points you to the call to findNavController (which appears to be on line 24 in your source code), where it says that it can't find the id R.id.nav_host_fragment_content_main in your view.
Is R.id.nav_host_fragment_content_main defined in activity_main.xml? If so, the second call to setContentView() is replacing that view with whatever is in binding.root. In that case, removing the second call could fix your issue.
If R.id.nav_host_fragment_content_main is supposed to be defined in binding.root, I think you'll need to include the implementation of com.example.bookapplication.databinding.ActivityMainBinding in your question so we can better understand what' going on.
In any case, you shouldn't call setContentView() twice, as #TylerV said.
Hey guys I wanted to build a counter app. But this error pops up when I want to test it:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.change, PID: 7804
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.change/com.example.change.MainActivity}: kotlin.UninitializedPropertyAccessException: lateinit property fighter1 has not been initialized
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: kotlin.UninitializedPropertyAccessException: lateinit property fighter1 has not been initialized
at com.example.change.MainActivity.onCreate(MainActivity.kt:21)
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)
I don't know if I have coded everything correctly because I just started learning Android Studio, so I still don't know a lot about it. This is my code (I'm new to Kotlin):
package com.example.change
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
class MainActivity : AppCompatActivity() {
private var counter1 = 0;
private lateinit var counterRed1: TextView
private lateinit var fighter1: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
counterRed1 = findViewById(R.id.counterRed1);
fighter1.setOnClickListener {
counter1 ++
counterRed1.text = (Integer.toString(counter1))
}
}
}
You have missed initializing your fighter1 button field. You need to initialize it just like you've initialized the counterRed1 text field.
counterRed1 = findViewById(R.id.counterRed1);
fighter1 = findViewById(R.id.fighter1);
Also make sure your activity_main layout file has a Button with the id fighter1.
I'm having problems with a function of showing a list of variables added through an insert. The error that is constantly showing in my logcat is the next one:No adapter attached; skipping layout : RecyclerView.
Here´s my adapter´s code.
package com.example.conexionbd
import android.app.Activity
import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.conexionbd.data.Cultivo
import kotlinx.android.synthetic.main.list_item_cultivo.view.*
import java.lang.reflect.Type
import java.text.FieldPosition
class CultivosAdapter(val cultivos: List<Cultivo>, val activity: Activity): RecyclerView.Adapter<CultivosAdapter.CultivoViewHolder>() {
class CultivoViewHolder(itemView : View): RecyclerView.ViewHolder(itemView){
fun bindCultivo(cultivo: Cultivo, activity: Activity){
itemView.setOnClickListener {
val intent = Intent(itemView.context, InsertEditActivity::class.java)
intent.putExtra(Constants.ID, cultivo.id)
intent.putExtra(Constants.NOMBRE, cultivo.name)
intent.putExtra(Constants.PLAGA, cultivo.plaga)
intent.putExtra(Constants.NUEVO_CULTIVO, Constants.NO)
itemView.context.startActivity(intent)
activity.finish()
}
itemView.litNombre.text = cultivo.name
itemView.litPlaga.text = cultivo.plaga
}
}
override fun onCreateViewHolder (parent: ViewGroup, viewType: Int): CultivoViewHolder {
var layoutInflate = LayoutInflater.from(parent.context)
.inflate(R.layout.list_item_cultivo, parent, false)
return CultivoViewHolder(layoutInflate)
}
override fun getItemCount(): Int {
return cultivos.size
}
override fun onBindViewHolder(holder: CultivoViewHolder, position: Int) {
val cultivo = cultivos[position]
holder.bindCultivo(cultivo, activity)
}
}
And the code of the activity where the RecyclerView is called
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.example.conexionbd.data.Cultivo
import com.example.conexionbd.data.CultivoDB
import kotlinx.android.synthetic.main.activity_cultivos.*
class CultivosActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_cultivos)
var cultivos: List<Cultivo> = CultivoDB.getDatabase(applicationContext).cultivoDAO().getAllCultivos()
taRv.layoutManager = LinearLayoutManager(this)
taRv.adapter = CultivosAdapter(cultivos, this)
}
}
I´ve been searching and I haven´t solved my problem.
Edit
This is my stack Trace? I´m a complete beginner at Android Studio.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.conexionbd, PID: 19984
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.conexionbd/com.example.conexionbd.CultivosActivity}: java.lang.RuntimeException: cannot find implementation for com.example.conexionbd.data.CultivoDB. CultivoDB_Impl does not exist
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Caused by: java.lang.RuntimeException: cannot find implementation for com.example.conexionbd.data.CultivoDB. CultivoDB_Impl does not exist
at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:93)
at android.arch.persistence.room.RoomDatabase$Builder.build(RoomDatabase.java:630)
at com.example.conexionbd.data.CultivoDB$Companion$database$2.invoke(CultivoDB.kt:18)
at com.example.conexionbd.data.CultivoDB$Companion$database$2.invoke(CultivoDB.kt:13)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.example.conexionbd.data.CultivoDB$Companion.getDatabase(Unknown Source:6)
at com.example.conexionbd.data.CultivoDB$Companion.getDatabase(CultivoDB.kt:22)
at com.example.conexionbd.CultivosActivity.onCreate(CultivosActivity.kt:16)
at android.app.Activity.performCreate(Activity.java:7148)
at android.app.Activity.performCreate(Activity.java:7139)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1293)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
You should replace this line
var cultivos: List<Cultivo> = CultivoDB.getDatabase(applicationContext).cultivoDAO().getAllCultivos()
with this following line:
var cultivos: List<Cultivo> = CultivoDB.getDatabase(this#CultivosActivity).cultivoDAO().getAllCultivos()
package com.example.testapp
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hanks.passcodeview.PasscodeView
class Main2Activity : AppCompatActivity() {
var EXTRA_TEXT ="fintech"
private var PRIVATE_MODE = 0
private val PREF_NAME = "myref"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val sharedPref: SharedPreferences = getSharedPreferences(PREF_NAME, PRIVATE_MODE)
var passcodeView=findViewById<PasscodeView>(R.id.passcodeView)
passcodeView.setPasscodeLength(4).listener = object :
PasscodeView.PasscodeViewListener{
override fun onSuccess(number: String?) {
if (sharedPref.getBoolean(PREF_NAME, false)) {
val homeIntent = Intent(applicationContext, AfterloginActivity::class.java)
homeIntent.putExtra("fintech",number)
startActivity(homeIntent)
finish()
} else {
setContentView(R.layout.activity_main2)
val editor = sharedPref.edit()
editor.putBoolean(PREF_NAME, true)
editor.apply()
}
}
override fun onFail() {
Toast.makeText(this#Main2Activity,"wrong",Toast.LENGTH_SHORT).show()
}
}
}
}
this my source code and i get this error:
Process: com.example.testapp, PID: 11939
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testapp/com.example.testapp.Main2Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.hanks.passcodeview.PasscodeView com.hanks.passcodeview.PasscodeView.setPasscodeLength(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.hanks.passcodeview.PasscodeView com.hanks.passcodeview.PasscodeView.setPasscodeLength(int)' on a null object reference
at com.example.testapp.Main2Activity.onCreate(Main2Activity.kt:46)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-02 14:39:57.454 11939-11939/? I/Process: Sending signal. PID: 11939 SIG: 9
if i put "setContentView(R.layout.activity_main2)" below oncreate its work but i want to make it onetime login only so i put it under and then i got this error "java.lang.NullPointerException: Attempt to invoke virtual method 'com.hanks.passcodeview.PasscodeView com.hanks.passcodeview.PasscodeView.setPasscodeLength(int)' on a null object reference"
Thanks
Your error is caused by this line:
var passcodeView=findViewById<PasscodeView>(R.id.passcodeView)
You are trying to find a view when you have not setContentView for the activity.
If you don't call setContentView() all calls to findViewById() will return null. passcodeView being null is the reason for your NullPointerException.
There is no way to start the AfterloginActivity before setContentView() because you rely on passCodeView to add something to the Intent when you do homeIntent.putExtra("fintech",number).