java.lang.NullPointerException: on a null object reference - android

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).

Related

java.lang.NullPointerException: null cannot be cast to non-null type

I am trying to write a Flutter package that uses platform specific native code. I aimed to use rtt scanning, android.net.wifi.rtt.WifiRttManager for an indoor localization & positioning project. Neither such package for flutter is not exists nor I didn't see it. Also I am planning to publish this on pub.dev. On the kotlin side this is my code and when I run app from main.dart Error occurs:
package com.example.wifi_positioning
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel
import android.net.wifi.rtt.WifiRttManager
import android.os.Build
import androidx.annotation.RequiresApi
class MainActivity: FlutterActivity() {
private val METHOD_CHANNEL_NAME = "com.baranacikgoz.wifi_positioning/method"
private val RTT_STATE_CHANNEL = "com.baranacikgoz.wifi_positioning/rtt_state_channel"
#RequiresApi(Build.VERSION_CODES.P)
private lateinit var wifiRttManager: WifiRttManager
private var methodChannel: MethodChannel? = null
#RequiresApi(Build.VERSION_CODES.P)
override fun configureFlutterEngine(#NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
//Setup Channels
setupChannels(this, flutterEngine.dartExecutor.binaryMessenger)
}
override fun onDestroy() {
super.onDestroy()
}
#RequiresApi(Build.VERSION_CODES.P)
private fun setupChannels(context: Context, messenger: BinaryMessenger){
wifiRttManager = context.getSystemService(Context.WIFI_RTT_RANGING_SERVICE) as WifiRttManager
methodChannel = MethodChannel(messenger, METHOD_CHANNEL_NAME)
methodChannel!!.setMethodCallHandler{
call, result ->
when (call.method) {
"supportsRtt" -> {
result.success(context.packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT))
}
"isRttAvailable" -> {
result.success(wifiRttManager.isAvailable)
}
else -> {
result.notImplemented()
}
}
}
}
private fun teardownChannels(){
methodChannel!!.setMethodCallHandler(null)
}
}
And this is the debug console:
E/AndroidRuntime(15624): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wifi_positioning/com.example.wifi_positioning.MainActivity}: java.lang.NullPointerException: null cannot be cast to non-null type android.net.wifi.rtt.WifiRttManager
E/AndroidRuntime(15624): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3190)
E/AndroidRuntime(15624): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
E/AndroidRuntime(15624): at android.app.ActivityThread.access$1000(ActivityThread.java:211)
E/AndroidRuntime(15624): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
E/AndroidRuntime(15624): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(15624): at android.os.Looper.loop(Looper.java:145)
E/AndroidRuntime(15624): at android.app.ActivityThread.main(ActivityThread.java:6946)
E/AndroidRuntime(15624): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(15624): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(15624): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
E/AndroidRuntime(15624): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
E/AndroidRuntime(15624): Caused by: java.lang.NullPointerException: null cannot be cast to non-null type android.net.wifi.rtt.WifiRttManager
E/AndroidRuntime(15624): at com.example.wifi_positioning.MainActivity.setupChannels(MainActivity.kt:38)
E/AndroidRuntime(15624): at com.example.wifi_positioning.MainActivity.configureFlutterEngine(MainActivity.kt:29)
E/AndroidRuntime(15624): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:199)
E/AndroidRuntime(15624): at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:459)
E/AndroidRuntime(15624): at android.app.Activity.performCreate(Activity.java:6575)
E/AndroidRuntime(15624): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
E/AndroidRuntime(15624): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
E/AndroidRuntime(15624): ... 10 more
E/AndroidRuntime(17077): FATAL EXCEPTION: main
E/AndroidRuntime(17077): Process: com.example.wifi_positioning, PID: 17077
E/AndroidRuntime(17077): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.wifi_positioning/com.example.wifi_positioning.MainActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
E/AndroidRuntime(17077): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3029)
E/AndroidRuntime(17077): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
E/AndroidRuntime(17077): at android.app.ActivityThread.access$1000(ActivityThread.java:211)
E/AndroidRuntime(17077): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
E/AndroidRuntime(17077): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(17077): at android.os.Looper.loop(Looper.java:145)
E/AndroidRuntime(17077): at android.app.ActivityThread.main(ActivityThread.java:6946)
E/AndroidRuntime(17077): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17077): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(17077): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
E/AndroidRuntime(17077): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
This line:
wifiRttManager = context.getSystemService(Context.WIFI_RTT_RANGING_SERVICE) as WifiRttManager
Seems WifiRttManager is not available on this device?

How to use logger with Koin?

Koin version: 2.1.5
Instructions are missing from documentation here.
This is what I have:
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
// use AndroidLogger as Koin Logger - default Level.INFO
androidLogger()
// use the Android context given there
androidContext(this#MyApp)
// module list
modules(emptyList())
}
}
}
class MainActivity : AppCompatActivity() {
private val logger : Logger by inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
logger.debug("onCreate")
}
}
And looks like there is no instance of Logger in the dependency graph:
04-26 12:02:03.781 4672-4672/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 4672
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'org.koin.core.logger.Logger'. Check your definitions!
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: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'org.koin.core.logger.Logger'. Check your definitions!
at org.koin.core.scope.Scope.throwDefinitionNotFound(Scope.kt:247)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:216)
at org.koin.core.scope.Scope.get(Scope.kt:181)
at com.example.myapplication.MainActivity$$special$$inlined$inject$1.invoke(ComponentCallbackExt.kt:51)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at com.example.myapplication.MainActivity.getLogger(MainActivity.kt)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:17)
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) 
Why?
My understanding: this logger is used for internal Koin logging. I came to the conclusion by looking into source code. This logger can be used outside of Koin itself getKoin()._logger.info("hello world") but I doubt it was the library creator's intention.

login to firebase in kotlin android studio

I'm using firebase in my android project.
But this is what get when user trying to sign up in firebase using my application.
My errors log
09-15 13:54:23.992 2716-2716/com.example.err0r1096.tikteck E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.err0r1096.tikteck, PID: 2716
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637) 
at android.view.View$PerformClick.run(View.java:22429) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Caused by: kotlin.KotlinNullPointerException
at com.example.err0r1096.tikteck.Login.LoginToFireBase(Login.kt:26)
at com.example.err0r1096.tikteck.Login.OneC(Login.kt:20)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:5637) 
at android.view.View$PerformClick.run(View.java:22429) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
and this my code :
package com.example.err0r1096.tikteck
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_login.*
class Login : AppCompatActivity() {
private val mAuth: FirebaseAuth? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
}
fun OneC(view: View){
LoginToFireBase(etEmail.text.toString(),etPassword.text.toString())
}
fun LoginToFireBase(email:String,password:String){
mAuth!!.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this){ task ->
if (task.isSuccessful){
Toast.makeText(applicationContext,"Successful login",Toast.LENGTH_LONG).show()
}
else
{
Toast.makeText(this,"Login UnSuccessful",Toast.LENGTH_LONG).show()
}
}
}
}
My application is crashing when user click on start button .
I think the problem is in my code and not on the firebase.
You can check the official doc:
Kotlin's type system is aimed to eliminate NullPointerException's from our code. The only possible causes of NPE's may be:
An explicit call to throw NullPointerException();
Usage of the !! operator that is described below;
External Java code has caused it;
There's some data inconsistency with regard to initialization (an uninitialized this available in a constructor is used somewhere).
Using: b!! it will return a non-null value of b or throw an NPE if b is null
Check your code (you are using kotlin as java)
mAuth!!.createUserWithEmailAndPassword(email,password)
Did you initialize mAuth anywhere? If not, the mAuth!! will throw a NullPointerException
Try declaring the widgets by,
fun onC (view: View) {
val emailTxt = findViewById<View>(R.id.etEmail) as EditText
val passwordTxt = findViewById<View>(R.id.etPassword) as EditText
val email = emailTxt.text.toString.trim()
val password = passwordTxt.text.toString.trim()
LoginToFireBase (email, password)
}
This may resolve your problem :)

Unable to instantiate activity | Caused by: kotlin.KotlinNullPointerException

I'm getting this error
FATAL EXCEPTION: main
Process: com.demo.gandharv.exkotlin, PID: 7742
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.pantelwar.gandharv.scobokotlin/com.demo.gandharv.exkotlin.RegisterActivity}: kotlin.KotlinNullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3095)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: kotlin.KotlinNullPointerException
at com.demo.gandharv.exkotlin.RegisterActivity.(RegisterActivity.kt:12)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1096)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3085)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351) 
at android.app.ActivityThread.access$1100(ActivityThread.java:222) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7230) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
I have defined the RegisterActivity in my AndroidMenifest.xml.
I have no idea why i'm getting this error.
Here's my LoginActivity.kt
package com.demo.gandharv.exkotlin
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_login.*
class LoginActivity : AppCompatActivity() {
var email: String = ""
var password: String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
loginButton.setOnClickListener {
email = emailEditText.text.toString()
password = passwordEditText.text.toString()
}
registerTextView.setOnClickListener {
val intent = Intent(this#LoginActivity, RegisterActivity::class.java)
startActivity(intent)
}
}
}

When change Activity, application has stopped

package com.example.dh.qrock;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class mainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button goManageList = (Button)findViewById(R.id.goManageList);
goManageList.setOnClickListener(
new Button.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(v.getContext(), managelistActivity.class);
startActivity(myIntent);
finish();
overridePendingTransition(R.xml.madefadein, R.xml.splashfadeout);
}
}
);
}
}
when changing activity, the application has stopped.
I use fade in and fade out.
How to fix that?
If you need another code, please comment here.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dh.qrock, PID: 4356
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dh.qrock/com.example.dh.qrock.managelistActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.dh.qrock.managelistActivity.onCreate(managelistActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)  
here is the log.
It occurs NullPointException in button.
how to fix the NullPointException?
I changed Button.setOnclicklistener to View.onclickListener, But It doesn't work.
Check the id of your Button goManageList if it exists in your R.layout.activity_main
Because you have this error
Attempt to invoke virtual method 'void
android.widget.Button.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
It means that you are setting a setOnClickListener to a null object
this because
overridePendingTransition(R.xml.madefadein, R.xml.splashfadeout);
The problem is you are using the context of the button in the intent like this:
Intent myIntent = new Intent(v.getContext(), managelistActivity.class);
Give the context of the current activity like this:
Intent myIntent = new Intent(mainActivity.this, managelistActivity.class);
change Button.OnClickListener to View.OnClickListener
goManageList.setOnClickListener(
new Button.OnClickListener()
to
goManageList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});

Categories

Resources