java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.e(Log.java:230)
at android.sec.clipboard.data.ClipboardDataMgr.addData(ClipboardDataMgr.java:166)
at com.android.server.sec.InternalClipboardExService.addData(InternalClipboardExService.java:438)
at com.android.server.sec.InternalClipboardExService.access$300(InternalClipboardExService.java:75)
at com.android.server.sec.InternalClipboardExService$1.run(InternalClipboardExService.java:389)
at java.lang.Thread.run(Thread.java:1019)
Seem to be getting this quite often in my crash reporting, i can't for the life of my understand how or why or even where its happening?
The only location im performing anything on the clipboard is to copy data to it, no logging or println of any kind, not to mention i'm choosing the correct methods for the version of OS at runtime so i didnt hit any compat issues.
oh, and the devices range from 2.2 right up to 4.0 OS version
Perhaps relevant code?
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
try {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) acc
.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("", b);
clipboard.setPrimaryClip(clip);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
try {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) acc
.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(b);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
the error means that the second parameter of Log.* can not be null, otherwise a Nenter code herePE is thrown. That could happen, for instance, when you try to print the message returned by an exception (e.getMessage()).
String message = null;
Log.i("TAG", message);
that`s kind of situation are the cause of that exception. A possible workaround
String message = null;
Log.i("TAG", ((message == null) ? "string null" : message));
Anyway, your error is not there: It is not catched by your try...catch because it is happening on another thread as you can see in your stack trace.
According to the developers of Clipper - Clipboard Manager:
SAMSUNG USERS: Some devices have a randomly occurring bug that may cause the clipboard to crash in any application. This is unfortunately out of our control. If you are experiencing this problem with your device, please contact Samsung support for assistance.
This might be also caused (later on since you said up to 4.0) by version 4.3:
Copy crash in Android 4.3 when clipboard listener attached
Also read this guy's post (seems he experienced the issue): http://forum.xda-developers.com/showthread.php?t=2097929
In summary, I do not think this error is your responsibility.
Related
I am using reflection to unlock my device screen setting keyguard as disabled.my android version is 4.4.2.while invoking i get exception as java.lang.reflect.InvocationTargetException and cause as java.lang.SecurityException: LockSettingsWrite: Neither user 10096 nor current process has android.permission.ACCESS_KEYGUARD_SECURE_STORAGE.
i am sharing my code please tell me how to rectify this exception
try{
Class lockPatternUtilsCls = Class.forName("com.android.internal.widget.LockPatternUtils");
Constructor lockPatternUtilsConstructor = lockPatternUtilsCls.getConstructor(new Class[]{Context.class});
Object lockPatternUtils = lockPatternUtilsConstructor.newInstance(ChangeDeviceLockMode.this);
Method clearLockMethod = lockPatternUtils.getClass().getMethod("clearLock", boolean.class);
clearLockMethod.setAccessible(true);
Method setLockScreenDisabledMethod = lockPatternUtils.getClass().getMethod("setLockScreenDisabled", boolean.class);
setLockScreenDisabledMethod.setAccessible(true);
clearLockMethod.invoke(lockPatternUtils, false);
setLockScreenDisabledMethod.invoke(lockPatternUtils, true);
Toast.makeText(ChangeDeviceLockMode.this,"none", Toast.LENGTH_LONG).show();
}catch(Exception e){
System.err.println("An InvocationTargetException was caught!");
Throwable cause = e.getCause();
Toast.makeText(ChangeDeviceLockMode.this,"none"+e, Toast.LENGTH_LONG).show();
}
Toast.makeText(ChangeDeviceLockMode.this,"Yupiee!!! Password changed successfully to swipe", Toast.LENGTH_LONG).show();
}
Why this error Occurs in KitKat:
In KitKat Android moved the security databases away from the application data area (/data/data) to the system data area (/data/system).
Ref
I'm attempting to send notifications to Sony LiveWare devices
I've installed: com.sonyericsson.extras.liveware.extension.notificationsample, but I get errors and exceptions while trying to run it:
Load the preference activity onto the device
Check "Active" on the preferences screen
The following method is called in SampleExtensionService:
private void addData() {
Random rand = new Random();
int index = rand.nextInt(5);
String name = NAMES[index];
String message = MESSAGE[index];
long time = System.currentTimeMillis();
long sourceId = NotificationUtil
.getSourceId(this, EXTENSION_SPECIFIC_ID);
if (sourceId == NotificationUtil.INVALID_ID) {
Log.e(LOG_TAG, "Failed to insert data");
return;
}
String profileImage = ExtensionUtils.getUriString(this,
R.drawable.widget_default_userpic_bg);
ContentValues eventValues = new ContentValues();
eventValues.put(Notification.EventColumns.EVENT_READ_STATUS, false);
eventValues.put(Notification.EventColumns.DISPLAY_NAME, name);
eventValues.put(Notification.EventColumns.MESSAGE, message);
eventValues.put(Notification.EventColumns.PERSONAL, 1);
eventValues.put(Notification.EventColumns.PROFILE_IMAGE_URI, profileImage);
eventValues.put(Notification.EventColumns.PUBLISHED_TIME, time);
eventValues.put(Notification.EventColumns.SOURCE_ID, sourceId);
try {
getContentResolver().insert(Notification.Event.URI, eventValues);
} catch (IllegalArgumentException e) {
Log.e(LOG_TAG, "Failed to insert event", e);
} catch (SecurityException e) {
Log.e(LOG_TAG, "Failed to insert event, is Live Ware Manager installed?", e);
} catch (SQLException e) {
Log.e(LOG_TAG, "Failed to insert event", e);
}
}
The first problem is that "long sourceId = NotificationUtil.getSourceId(this, EXTENSION_SPECIFIC_ID)" returns -1
I'm not sure how to change, but the docs say it is an optional field. So I removed it to see if I could get any further:
When removing the sourceId code I get an exception on the insert call:
"java.lang.SecurityException: You do not have sufficient permission to perform a insert"
My Environment:
HTC One V paired with a LiveView wrist pager
http://www.amazon.co.uk/Sony-Ericsson-0001516170-LIVE-VIEW/dp/B00477X6DA
I've got the followings apps installed
LiveView
SmartConnect(LiveWare Manager)
I'd appreciate any help getting this sample to work or if anyone knows of a more straight forward approach to doing simple text notifications for LiveWare.
EDIT:
Made some progress. Found an emulator here:
android-sdk\add-ons\addon-sony_add-on_sdk_1_0-sony-16\apk_files
I installed that on the phone. The "SampleExtensionService" works fine in the emulator.
My assumption now is that add-on sample is not compatible with the LiveView device.
The LiveView is unfortunately not supported by the SmartExtension APIs. Instead, there is a specific developer kit for the LiveView here.
If you would, in the future, buy a newer wearable device from Sony Mobile, a notification extension based on the Smart Extension APIs would be usable for several devices including SmartWatch, SmartWatch 2, SBH50, SBH52 etc.
I am constantly getting error reports (from users) such as:
Caused by: Status Code: 400, AWS Service: AmazonSimpleDB, AWS Request ID: c5cb109d-bbff-fcea-bc0d-0cb60ff8f6af, AWS Error Code: RequestExpired, AWS Error Message: Request has expired. Timestamp date is 2012-06-06T13:19:59.415Z. Current date is 2012-06-06T14:20:03Z
Apparently this is because the user has the wrong timezone or something set? Regardless, I would like to catch this particular error and post a message to the user asking them to check their timezone settings however I can't find a way to do it. If I catch AmazonServiceException, the error shows up as null.
How can I catch errors based on Status Code or even Error Code? The current code that I tried looks like this:
try {
dostuff()
} catch (IOException e) {
updateAWS("DownloadErrors");
return "filenotfound";
} catch (AmazonServiceException e) {
return "downloadfail";
}
However AmazonServiceException e is always null so I can't pull any information from it.
other code:
private void doStuff() throws IOException, AmazonServiceException{
//code here
}
Apparently this is what I needed. SDb tracks "RequestExpired" and S3 uses "RequestTimeTooSkewed"
Also, this appears to be occurring because the system time is >15 minutes different than the AWS server. I put a note to the user to check their time and use "Automatic" date/time if possible. Tested it myself and reproduced the error as well as the solution.
try {
result = doOperations();
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("RequestExpired") || e.getErrorCode().equals("RequestTimeTooSkewed")) {
result = "timestamp";
}
}
return result;
}
So this is the weirdest thing ever to happen to me during programing. Yes I'm no pro at programing, but I'm learning as I go. I've got an app talking to a server, a socket in the main thread, reading is done in a separate class and thread and writing in a separate class with asynctask.
The problem is LocationManager. I could talk to server and write/read commands just fine, I implemented the LocationManager and its listener.
I then proceeded to implement a method to update my textview with the new coordinates on locatinChanged. So far so good. Thing is when I use the Emulator control in eclipse and send coordinates the app crashed with a stringOutOfBoundsException (I've programed for 3 years now never seen this). I looked at the code stepped through it and so on. Read the stacktrace, logcat, console and everywhere I could think of but it got me nowhere. Until I finally went to the readerthread which looks like this:
public class ReaderThread extends Thread {
public void run() {
new Thread(new Runnable(){
public void run(){
try {
//Establish a bufferedreader to read from the socket/server.
in = new BufferedReader(new InputStreamReader(socket.getInputStream()), 8 * 1024);
}
catch(Exception e) { e.printStackTrace(); }
//As long as connect is true.
while (connected) {
String line;
try {
//Try to read a line from the reader.
line = in.readLine();
System.out.println(in.readLine());
if (in == null) {
//No one has sent a message yet.
System.out.println("No data recieved");
}
else {
int i = 0;
//As long as someone is sending messages.
while((line = in.readLine()) != null ){
//Make a new Message.
Message msg;
msg = new Message();
//Set the object to the input line.
msg.obj = line;
//Set an id so it can be identified in the main class and used in a switch.
msg.what = i;
System.out.println("i is: "+i);
//Send the message to the handler.
Main.this.h.sendMessage(msg);
}
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}).start();
}
The variable i is in an if statement depending on what the server sent but I cut that out as it has nothing to do with this problem.
The problem is the freaking catch. When the catch is IOException, the app crashes. Out of dumb luck I changed this to Exception and printed e.message to catch the error and see what caused it. Thing is this change fixed it. How can switching IOException to just plain Exception fix a problem like this?
Its like with IOException the program says: "hey your not gonna catch the error but there is no error" but with Exception it says "Well now you could catch it so I'll proceed".
My app is working but I just can't grasp this, why and how does this happen?
You're essentially telling the application to catch the base Exception class. This means that any type of error will be caught, since all exception classes descend from that base type. Since StringOutOfBoundsException does not descend from IOException it was not being caught before and the error was not being caught. Instead of catching all exceptions, you might try the following:
try {
// Your code here...
} catch (IOException e) {
Log.e(TAG, "Caught an IOException!", e);
} catch (StringOutOfBoundsException e) {
Log.e(TAG, "Caught a string out of bounds Exception!", e);
}
I'm unable to determine what is actually throwing the StringOutOfBoundsException to begin with. It may be in the if statement that you cut out of your example.
while (connected) {
String line;
try {
//Try to read a line from the reader.
line = in.readLine();
System.out.println(in.readLine());
if (in == null) {
//No one has sent a message yet.
System.out.println("No data recieved");
}
The test for in == null is in a funny location. You should receive a NullPointerException if that test were to ever return true by nature of calling methods on it a few lines earlier. Obviously something is a little funny with this code.
You fail to save the return value from in.readLine() the second time you call it. I hope it did not contain anything useful. (Though, since you print the line, you obviously wanted to know what data it contained.)
Whatever that line was (from the first call to in.readLine()), it gets thrown away; there's nothing else in the loop that uses it before it is over-written on this line:
while((line = in.readLine()) != null ){
At this point, the two lines that you read are gone forever.
I'm not entirely sure what should be done to fix this; if it were me, I'd be sorely tempted to start over with a sheet of paper and sketch out what the method should be doing without looking at the existing code, then compare the sketch against the code to see which cases each one has overlooked.
I've sucessfully compiled jNetPcap as a shared library for Android. I have made a simple application using this code: http://jnetpcap.com/examples/classic to test the API.
The problem is that when I call the method findAllDevs and exception is raised with this message: "Can't read list of devices, error issocket: Permission denied"
I cannot understand the reason, since I have made a call in the first part of my program so as to get root permissions for my application and I test my application to a rooted phone. When I run the application, a pop up is raised with this message:"SnifferApp has been granted Superuser permissions" and then the exception occurs.
Any ideas?
Here is a piece of my code:
Process p = Runtime.getRuntime().exec("su");
/*try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // do nothing for 1000 miliseconds (1 second)
*/
try {
System.loadLibrary(JNETPCAP_LIBRARY_NAME);
}
catch (UnsatisfiedLinkError e) {
System.out.println("Native code library failed to load.\n" + e);
}
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
tv.append("Can't read list of devices, error is" + errbuf
.toString());
setContentView(tv);
return;
}
As far as I understand, you're creating a new process and getting superuser permission, but your app doesn't have them.
Try adding this permission in your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
as I guess findAllDevs is going to open the network devices on the phone.