Hello everyone i've got this error a nullPointerException error after i tried to integrate the android-page-transition and i couldn't find it's cause
this is the code where the error is shown PS: it's the same exact caude in the library i just integrated the code into mywork
/**
* Réglage Menu immersive title
*/
private void dealStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int statusBarHeight = getStatusBarHeight();
ViewGroup.LayoutParams lp = positionView.getLayoutParams();
lp.height = statusBarHeight;
positionView.setLayoutParams(lp);
}
}
this is the error i get when i run
11-19 12:11:30.781 16089-16089/mobile.esprit.tn.mobileteam E/AndroidRuntime: FATAL EXCEPTION: main
Process: mobile.esprit.tn.mobileteam, PID: 16089
java.lang.RuntimeException: Unable to start activity ComponentInfo{mobile.esprit.tn.mobileteam/mobile.esprit.tn.mobileteam.Activities.Project.PrjectsCardViews}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
at mobile.esprit.tn.mobileteam.Activities.Project.PrjectsCardViews.dealStatusBar(PrjectsCardViews.java:129)
at mobile.esprit.tn.mobileteam.Activities.Project.PrjectsCardViews.onCreate(PrjectsCardViews.java:54)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
the PrjectsCardViews.java:129 is the code i posted above
ok i found the problem it was a dump fault caused by the copy and paste , i dident refere the oncreate to the necessary activity layout
You might have copied the projet but you may forgotten to change
<com.stone.transition.DragLayout
android:id="#+id/drag_layout" when you merged the code in your project check this out it will work
Related
I want to get the primary text on my clipboard and would like to know how to do that in newer android versions.
This code works perfectly when I tested it in an emulator running Android Pie, but the app crashes when I use it on my Phone running android 12.1.
please help me with this.
clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard.hasPrimaryClip())
clipItem = clipboard.getPrimaryClip().getItemAt(0);
clipText = clipItem.getText().toString();
Details.setText(clipItem.getText().toString());
Here's the Error I got from Logcat
2022-10-01 19:23:27.595 1349-5125 ClipboardService pid-1349 E Denying clipboard access to com.jery.tachisyrpc, the application is not in focus nor is it a system service for user 0
2022-10-01 19:23:27.595 8222-8222 AndroidRuntime com.jery.tachisyrpc D Shutting down VM
2022-10-01 19:23:27.596 8222-8222 AndroidRuntime com.jery.tachisyrpc E FATAL EXCEPTION: main
Process: com.jery.tachisyrpc, PID: 8222
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jery.tachisyrpc/com.jery.tachisyrpc.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.ClipData$Item.getText()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4111) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)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:2443) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.ClipData$Item.getText()' on a null object reference
at com.jery.tachisyrpc.MainActivity.onCreate(MainActivity.java:55)
at android.app.Activity.performCreate(Activity.java:8290)
at android.app.Activity.performCreate(Activity.java:8270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4085)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
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:2443)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
First Activity of my Application starts a STICKY sevice that I'm using for creating notifications. Recently I've noticed a bug on Android O devices: when user starts an Application and then after a few seconds application was in background state the user gets this excpetion:
FATAL EXCEPTION: main
Process: com.callcatcher.callcatcher, PID: 27566
java.lang.RuntimeException: Unable to stop service callcatcher.call.com.callcatcher.NotificationService#e5b03d1: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Looper.quit()' on a null object reference
at android.app.ActivityThread.handleStopService(ActivityThread.java:3563)
at android.app.ActivityThread.-wrap26(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:6633)
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:823)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.Looper.quit()' on a null object reference
at android.app.IntentService.onDestroy(IntentService.java:147)
at callcatcher.call.com.callcatcher.NotificationService.onDestroy(NotificationService.java:94)
at android.app.ActivityThread.handleStopService(ActivityThread.java:3541)
at android.app.ActivityThread.-wrap26(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:171)
at android.app.ActivityThread.main(ActivityThread.java:6633)
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:823)
Still not sure about the reason of exception, but I just switched from IntentService to Service and now it works fine.
I tried to follow the example from a Youtuber named Pixel_95 about read and write file. It uses permission to write to external device.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Then
public String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/readWriteTutorial";
This creates a path as "/storage/emulated/0/readWriteTutorial". In onCreate(). I put
File dir = new File(path);
dir.mkdirs();
However, there is no such a folder on my device. There is no /storage/emulated anywhere using the File Manager app from my Samsung S7. So when it tries to run:
FileOutputStream fos = null;
fos = new FileOutputStream(file);
in a Save() method. Exception is caught.
FATAL EXCEPTION: main
Process: com.example.jiajunyang.readwrite, PID: 1170
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:6213)
at android.widget.TextView.performClick(TextView.java:11074)
at android.view.View$PerformClick.run(View.java:23645)
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:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
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:6213)
at android.widget.TextView.performClick(TextView.java:11074)
at android.view.View$PerformClick.run(View.java:23645)
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:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.FileOutputStream.close()' on a null object reference
at com.example.jiajunyang.readwrite.MainActivity.Save(MainActivity.java:161)
at com.example.jiajunyang.readwrite.MainActivity.onSaveClicked(MainActivity.java:111)
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:6213)
at android.widget.TextView.performClick(TextView.java:11074)
at android.view.View$PerformClick.run(View.java:23645)
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:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Mainly this:
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.FileOutputStream.close()' on a null object reference
So what is the solution to this? I couldn't seems to get a correct path to make a directory. Many thanks for your help.
Using Context.getExternalFilesDirs(null), you will be able to retrieve which external directory exist on your device. You will then be able to check if "storage/emulated/0" appears in the list.
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
Hey guys so when I hit this particular button it is supposed to take me to the another layout. However everytime i hit it, the entire app crashes. Here is the onCreate method for that page im trying to get to:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bench_data_entry);
//opens the database
openDB();
//Initializes and declares the sensors, and accelerometer
mInitialized = false;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
// tv.setText("Aasfdaf");
}
Here is the onClick for the button I am pressing:
public void onClick_Bench(View v){
//Intent to create a new activity
Intent intent = new Intent(MainMenuActivity.this, BenchDataEntry.class);
//Goes to the Data Entry Screen
startActivity(intent);
}
and here is the error log I am getting when I press the button:
08-08 17:30:30.785 31113-31113/com.example.jacob.repcapture E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.jacob.repcapture, PID: 31113
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.jacob.repcapture/com.example.jacob.repcapture.BenchDataEntry}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2096)
at com.example.jacob.repcapture.BenchDataEntry.<init>(BenchDataEntry.java:49)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I think error not in these code blocks logcat about android.view.View android.view.Window.findViewById(int)' on a null object reference
First - do clean project under build-menu, and restart the emulator. After that the exception went away in my situation.
Second - check FindviewById items You need to initialize them in the onCreate too.
Using
wifiManager.startScan();
ScanResultsList scanresultsList = wifiManager.getScanResults();
I obtain a list of scan results defined by ScanResult objects.
Problem:
Refering to scanResult.channelWidth I am presented with an error:
scanResult.channelWidth = No such instance field: 'channelWidth'
and
Exception
java.lang.NoSuchFieldError: No instance field channelWidth of type I
in class Landroid/net/wifi/ScanResult; or its superclasses
(declaration of 'android.net.wifi.ScanResult' appears in
/system/framework/framework.jar)
Stacktrace:
06-14 02:57:19.732 27116-27116/com.cynetstudios.frequencyselector E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cynetstudios.frequencyselector, PID: 27116
java.lang.NoSuchFieldError: No instance field channelWidth of type I in class Landroid/net/wifi/ScanResult; or its superclasses (declaration of 'android.net.wifi.ScanResult' appears in /system/framework/framework.jar)
at com.cynetstudios.frequencyselector.main.initWiFiArrays(main.java:161)
at com.cynetstudios.frequencyselector.main.access$000(main.java:35)
at com.cynetstudios.frequencyselector.main$1$1.run(main.java:115)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5291)
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:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
I require this int value for further processing,
what is causing this no instance field?
This may be useful,check this link
https://developer.android.com/reference/android/net/wifi/ScanResult.html>