How can I remove my NullPointerException? [duplicate] - android

This question already exists:
Attempt to invoke virtual method on a null object reference -> resolve?
Closed 1 year ago.
I retry to post my question because I don't have receive an answer : my app close itself when i click, an I find as cause that :
Process: fr.amseu.mystretching, PID: 15005
java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.amseu.mystretching/fr.amseu.mystretching.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3556)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3703)
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:2216)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7948)
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:1075)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at fr.amseu.mystretching.MainActivity.onCreate(MainActivity.kt:17)
at android.app.Activity.performCreate(Activity.java:7955)
at android.app.Activity.performCreate(Activity.java:7944)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3531)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3703) 
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:2216) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:237) 
at android.app.ActivityThread.main(ActivityThread.java:7948) 
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:1075) 
As context, I give my Main activity :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val exerciseButton = findViewById<ImageButton>(R.id.imageButton)
exerciseButton.setOnClickListener {
val intent = Intent(this, SecondActivity::class.java)
startActivity(intent)
}
My layout which contain the Image button. It is a part of a recycler view if it change anything ? :
<ImageButton
android:id="#+id/imageButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/lower_legs"
android:contentDescription="#string/home_page_first_button" />
And I have finally my second activity (as a kotlin class file), where the click should redirect me :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_exercices)
}
}
Thanks for any help...

My layout which contain the Image button. It is a part of a recycler view if it change anything ?
It does change a lot. You're trying to find a view that does not exist when onCreate is called because you have not initialized the recycler view or its adapter (as far as the code you showed).
See this post for handling a click on a RecyclerView item: RecyclerView onClick

Related

Error message when testing an app in the Android Studio emulator: 'The app keeps stopping'

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.

Android Studio Fatal Exception: main counter app

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.

Android TextView Showing Fatal Error in Kotlin

I am trying to initialize TextView in Kotlin as following
val textSelectedFood = findViewById<TextView>(R.id.textSelectedFood) as TextView
I also tried this
val textSelectedFood: TextView = findViewById<TextView>(R.id.textSelectedFood) as TextView
And also this
val textSelectedFood: TextView = findViewById(R.id.textSelectedFood) as TextView
And this
val textSelectedFood: TextView = findViewById<TextView>(R.id.textSelectedFood)
But still getting following errors. Don't know why
2021-01-10 23:38:26.640 29636-29636/com.imran.android.dinnerdecider E/d.dinnerdecide: Unknown bits set in runtime_flags: 0x8000
2021-01-10 23:38:27.091 29636-29636/com.imran.android.dinnerdecider E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.imran.android.dinnerdecider, PID: 29636
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.imran.android.dinnerdecider/com.imran.android.dinnerdecider.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
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.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:163)
at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:174)
at android.content.Context.obtainStyledAttributes(Context.java:738)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:839)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:630)
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:223)
at com.imran.android.dinnerdecider.MainActivity.<init>(MainActivity.kt:12)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1243)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3182)
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 got hints from this question.
but the code changed a lot over the year.
That's why I am writing the current solution code in the below which solved my problem.
private lateinit var textSelectedFood: TextView // withoud lateinit code will show error
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textSelectedFood = findViewById(R.id.textSelectedFood)
}
If you do not have to "findViewById" have many better and safer options:
1.synthetic (deprecated)
Call the view directly in your code.
2.view binding
For more information check this link:https://developer.android.com/topic/libraries/view-binding
This technique is old now, just use "View binding".
Or you can just call the view by it's id and that'll be it.
In your case:
textSelectedFood.text = "Example of doing something"

Can't initialise Visualizer on Android using Kotlin

I am currently having trouble while trying to display a "blast" view from the media playing, using this library: https://github.com/gauravk95/audio-visualizer-android
I am working in an activity coded using Kotlin
I did as advised in the readme, but am having an issue when my activity starts:
E/AudioEffect: set(): AudioFlinger could not create effect e46b26a0-dddd-11db-8afd-0002a5d5c51b / `�?�v, status: -1
E/visualizers-JNI: Visualizer initCheck failed -3
E/Visualizer-JAVA: Error code -3 when initializing Visualizer.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.codex_d.dev.android, PID: 31116
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.codex_d.dev.android/com.codex_d.dev.android.runningActivities.AudioPlayerActivity}: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3
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.RuntimeException: Cannot initialize Visualizer engine, error: -3
at android.media.audiofx.Visualizer.<init>(Visualizer.java:221)
at com.gauravk.audiovisualizer.base.BaseVisualizer.setAudioSessionId(BaseVisualizer.java:196)
at com.codex_d.dev.android.runningActivities.AudioPlayerActivity.onCreate(AudioPlayerActivity.kt:26)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
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/Process: Sending signal. PID: 31116 SIG: 9
Process 31116 terminated.
I have declared both RECORD_AUDIO and MODIFY_AUDIO_SETTINGS permissions in the manifest.
Here is my code for the activity:
class AudioPlayerActivity : BaseAdventureActivity(R.layout.activity_audio_player, true) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val dataLocation = intent.getSerializableExtra(EXTRA_LOCATION) as DataLocation
val path = "sample_audio_happy"
var mediaPlayer = MediaPlayer.create(this, dataLocation.getUri(path, this, adventure))
mediaPlayer.start()
if (mediaPlayer.audioSessionId != -1) blast.setAudioSessionId(mediaPlayer.audioSessionId)
}
override fun onDestroy() {
super.onDestroy()
blast.release()
}
When I comment the line with setAudioSessionId everything works fine (but of course without showing the visualisation).
Would anyone know where this error could come from?
Indeed, #Tenfour04 is right. Here are the two lines of code that were required:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, Array(1){Manifest.permission.RECORD_AUDIO}, 0)
}
Just add before stting audioSessionId, and it should work.
Thanks for your help!

How to deal with about invoke virtual method 'void android.view.View.setBackground(Drawable)' on a null object reference [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
This is my source code,it seams the program throw exception at line 41.
public class LaunchActivity extends ACtivity{
//Drawable
private ColorDrawable mBgDrawable;
#Override
protected int getContentLayoutId() {
return R.layout.activity_launch;
}
#Override
protected void initWidows() {
super.initWidows();
//拿到根布局
View root = findViewById(R.id.activity_launch);
//获取颜色
int color = UiCompat.getColor(getResources(),R.color.colorPrimary);
//创建一个Drawable
ColorDrawable drawable = new ColorDrawable(color);
//设置给背景
root.setBackground(drawable); **//line 41**
mBgDrawable = drawable;
}
the layout source code (activity_launch.xml)
<?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:id="#+id/activity_launch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:orientation="vertical"
tools:context="net.qiujuer.italker.push.LaunchActivity">
.....
and this is the error information.
(Does it means the View ('root') I get is a null object ?)
FATAL EXCEPTION: main
Process: net.qiujuer.italker.push, PID: 3046
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.qiujuer.italker.push/net.qiujuer.italker.push.LaunchActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackground(android.graphics.drawable.Drawable)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
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:826)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setBackground(android.graphics.drawable.Drawable)' on a null object reference
at net.qiujuer.italker.push.LaunchActivity.initWidows(LaunchActivity.java:41)
at net.qiujuer.italker.common.app.ACtivity.onCreate(ACtivity.java:16)
at android.app.Activity.performCreate(Activity.java:7130)
at android.app.Activity.performCreate(Activity.java:7121)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6649) 
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:826) 
This is my first attempt to ask questions on stack overflow. Thank you for your help.
Seems that you have declared layout name in root-view so view is not initialized.
Please check findViewById(R.id.activity_launch) for rootview and updated accordingly.

Categories

Resources