Android: java.lang.NullPointerException - android

I am currently have a problem with a buzztouch android app I created the error from google play is
NullPointerException
in BT_viewUtilities.updateBackgroundColorsForScreen()
I have narrowed it down to the following code, does anyone see any kind of error in the code. If you need something else please ask, this would fix quite a few apps. Thank you
//updates a screens background colors and image...
public static void updateBackgroundColorsForScreen(final Activity theActivity, final BT_item theScreenData){
BT_debugger.showIt(objectName + ":updateBackgroundColorsForScreen with nickname: \"" + theScreenData.getItemNickname() + "\"");

Either theScreenData or BT_debugger is null.

I have no idea what your code is doing but the fix is simple:
//updates a screens background colors and image...
public static void updateBackgroundColorsForScreen(final Activity theActivity, final BT_item theScreenData){
if(BT_debugger != null && theScreenData != null){
BT_debugger.showIt(objectName + ":updateBackgroundColorsForScreen with nickname: \"" + theScreenData.getItemNickname() + "\"");
} else {
Log.e("YourApp", "Warning null var, command not completed");
}
}
To debug the error you could do:
//updates a screens background colors and image...
public static void updateBackgroundColorsForScreen(final Activity theActivity, final BT_item theScreenData){
if(BT_debugger != null){
if(theScreenData != null){
BT_debugger.showIt(objectName + ":updateBackgroundColorsForScreen with nickname: \"" + theScreenData.getItemNickname() + "\"");
} else {
Log.e("YourApp", "theScreenData was null, command not completed");
}
} else {
Log.e("YourApp", "BT_debugger was null, command not completed");
}
}

I think this is the line that causes null point exception-theScreenData.getItemNickname()

Related

DLNA/UPNP - Get all non-media files

I am new in working with UpNp and DLNA. I am using cling library and DLNA code from here. In this code, everything working perfectly but my need is something else. It is giving me all media folders(Videos, Audio and Images) from selected device in network. But what I want is non media files from selected device on the network i.e., .docx, .srt, .txt etc.
Here is some code portion:
upnpService.getControlPoint().execute(
new ContentBrowseActionCallback(ContentActivity.this,
service, createRootContainer(service), mContentList,
mHandler));
Root Container:
protected Container createRootContainer(Service service) {
Container rootContainer = new Container();
rootContainer.setId("0");
rootContainer.setTitle("Content Directory on "
+ service.getDevice().getDisplayString());
Log.e("createRootContainer", "service.getDevice().getDisplayString() : " + service.getDevice().getDisplayString());
return rootContainer;
}
ContentBrowseActionCallback:
public class ContentBrowseActionCallback extends Browse {
private static Logger log = Logger
.getLogger(ContentBrowseActionCallback.class.getName());
private Service service;
private Container container;
private ArrayList<ContentItem> list;
private Activity activity;
private Handler handler;
public ContentBrowseActionCallback(Activity activity, Service service,
Container container, ArrayList<ContentItem> list, Handler handler) {
super(service, container.getId(), BrowseFlag.DIRECT_CHILDREN, "*", 0,
null, new SortCriterion(true, "dc:title"));
this.activity = activity;
this.service = service;
this.container = container;
this.list = list;
this.handler = handler;
}
public void received(final ActionInvocation actionInvocation,
final DIDLContent didl) {
log.fine("Received browse action DIDL descriptor, creating tree nodes");
activity.runOnUiThread(new Runnable() {
public void run() {
try {
list.clear();
// Containers first
for (Container childContainer : didl.getContainers()) {
Log.e("Item", "childContainer : " + childContainer.getTitle());
log.fine("add child container "
+ childContainer.getTitle());
list.add(new ContentItem(childContainer, service));
}
// Now items
for (Item childItem : didl.getItems()) {
Log.e("Item", "childItem : " + childItem.getTitle());
log.fine("add child item" + childItem.getTitle());
list.add(new ContentItem(childItem, service));
}
} catch (Exception ex) {
log.fine("Creating DIDL tree nodes failed: " + ex);
actionInvocation.setFailure(new ActionException(
ErrorCode.ACTION_FAILED,
"Can't create list childs: " + ex, ex));
failure(actionInvocation, null);
handler.sendEmptyMessage(ContentActivity.CONTENT_GET_FAIL);
}
ConfigData.listPhotos.clear();
Iterator iterator = didl.getItems().iterator();
while (iterator.hasNext()) {
Item item = (Item) iterator.next();
Log.e("received", "item.getTitle() : " + item.getTitle());
ContentItem contentItem = new ContentItem(item,
ContentBrowseActionCallback.this.service);
if ((contentItem.getItem().getTitle().toString() != null)
&& (contentItem.getItem().getResources() != null)) {
List list = contentItem.getItem().getResources();
if ((list.size() != 0)
&& (((Res) list.get(0)).getProtocolInfo() != null)
&& (((Res) list.get(0)).getProtocolInfo()
.getContentFormat() != null)) {
Log.e("received", "list.get(0).getProtocolInfo() : " + ((Res) list.get(0)).getProtocolInfo());
Log.e("received", "list.get(0).getProtocolInfo().getContentFormat() : " + ((Res) list.get(0)).getProtocolInfo().getContentFormat());
Log.e("received", "list.get(0).getProtocolInfo().getContentFormat().substring() : " + ((Res) list.get(0)).getProtocolInfo().getContentFormat().substring(0,
((Res) list.get(0))
.getProtocolInfo()
.getContentFormat()
.indexOf("/")));
if (((Res) list.get(0))
.getProtocolInfo()
.getContentFormat()
.substring(
0,
((Res) list.get(0))
.getProtocolInfo()
.getContentFormat()
.indexOf("/"))
.equals("image")) {
ConfigData.listPhotos
.add(new ContentItem(
item,
ContentBrowseActionCallback.this.service));
} else if (((Res) list.get(0))
.getProtocolInfo()
.getContentFormat()
.substring(
0,
((Res) list.get(0))
.getProtocolInfo()
.getContentFormat()
.indexOf("/"))
.equals("audio")) {
ConfigData.listAudios
.add(new ContentItem(
item,
ContentBrowseActionCallback.this.service));
} else {
Log.e("received", "item : " + item.getTitle());
ConfigData.listVideos
.add(new ContentItem(
item,
ContentBrowseActionCallback.this.service));
}
}
}
}
handler.sendEmptyMessage(ContentActivity.CONTENT_GET_SUC);
}
});
}
public void updateStatus(final Status status) {
}
#Override
public void failure(ActionInvocation invocation, UpnpResponse operation,
final String defaultMsg) {
}
}
I googled a lot about this point but nothing in hand. I got few ideas about container id and how it works.
Please let me know how to achieve this scenario. I also don't have much idea about how DLNA and UPNP works. Please also help me to understand DLNA and UPNP better.
Thank You!
Ok, After diving into code from more than a week, I got basic idea how DLNA and UPNP works. How callbacks are made and how it fetches media files from device. So, now I am able to answer my own question.
HOW TO GET NON MEDIA FILES:
Whenever discovery service found your own device, it will prepare media server which will fetch all media from your device. First it creates a Node for specific type of media.e.g., Videos, Photos, Audios etc. Here is the code:
ContentNode rootNode = ContentTree.getRootNode();
// Video Container
Container videoContainer = new Container();
videoContainer.setClazz(new DIDLObject.Class("object.container"));
videoContainer.setId(ContentTree.MY_FOLDER_ID);
videoContainer.setParentID(ContentTree.ROOT_ID);
videoContainer.setTitle("My Folder Name");
videoContainer.setRestricted(true);
videoContainer.setWriteStatus(WriteStatus.NOT_WRITABLE);
videoContainer.setChildCount(0);
rootNode.getContainer().addContainer(videoContainer);
rootNode.getContainer().setChildCount(
rootNode.getContainer().getChildCount() + 1);
ContentTree.addNode(ContentTree.MY_FOLDER_ID, new ContentNode(
ContentTree.MY_FOLDER_ID, videoContainer));
This way you can add your own folder.
To fetch files you need to use Cursor to get files from your device. Something like this:
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_NONE;
Uri externalUri = MediaStore.Files.getContentUri("external");
String[] filePathColumn = {MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA};
Cursor cursor = contentResolver.query(externalUri, filePathColumn,
selection, null, null);
cursor.moveToFirst();
do {
String id =
cursor.getString(cursor.getColumnIndex(filePathColumn[0]));
String path =
cursor.getString(cursor.getColumnIndex(filePathColumn[1]));
String serverPath = "http://" + mediaServer.getAddress() + "/"
+path;
} while (cursor.moveToNext());
cursor.close();
Thus, serverPath will become your file path and you can access your file from another device. You can filter your files using file extension.
I must say this is huge project which I am using, so there are many changes I did to achieve my requirement. But, this answer justify my question.
Thank You!

Android Amazon S3 Uploading Crash

I'm trying to figure out what is the cause of this crash when uploading on Amazon S3 bucket.
Log is:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.amazonaws.mobileconnectors.s3.transferutility.TransferService$NetworkInfoReceiver.isNetworkConnected()' on a null object reference
at com.amazonaws.mobileconnectors.s3.transferutility.TransferService.execCommand(TransferService.java:287)
at com.amazonaws.mobileconnectors.s3.transferutility.TransferService$UpdateHandler.handleMessage(TransferService.java:224)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.os.HandlerThread.run(HandlerThread.java:61)
Is there is something wrong on my code?
public AmazonTransferUtility uploadFileToAmazonS3(String data, Date date){
generateTextFileFromString(data, date);
File jsonFile = new File(getDataPath(), textName);
TransferObserver observer = transferUtility.upload(
textBucketName,
mUUID + File.separator + date.getTime() + textName ,
jsonFile
);
mListener.onAsyncStart();
observer.setTransferListener(new TransferListener() {
#Override
public void onStateChanged(int id, TransferState state) {
try {
if (state.toString().equals("COMPLETED")) {
deleteFile(textName);
if (mListener != null) {
JSONObject result = new JSONObject();
result.put("result", state.toString());
mListener.onAsyncSuccess(result);
}
}
else if (state.toString().equals("FAILED") ||
state.toString().equals("UNKNOWN")
){
mListener.onAsyncFail(id, state.toString());
}
else{
Log.i(TAG, "S3 TransferState :" + state.toString());
}
}catch (JSONException e){
Log.e(TAG, e.getLocalizedMessage());
}
}
#Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
if (bytesCurrent == bytesTotal){
Log.i(TAG, "Completed");
}
else{
Log.i(TAG, "Current bytes: " + bytesCurrent + " Of bytesTotal : " + bytesTotal);
}
}
#Override
public void onError(int id, Exception ex) {
mListener.onAsyncFail(id,ex.getMessage());
}
});
return this;
}
And if ever how can I catch this error so that my app stop crashing and just cancel my uploading task.
BTW.
That crash is intermittent and ratio is 1 out of 5 successful sync
This doesn't appear to be something you are doing, it's inside the AWS SDK code. The implication of that NPE is a flaky network. It's been reported to Amazon on github (and confirmed in another ticket) and it appears rolling back one version in the SDK (v2.2.13) may help.
That also makes sense given the changes made in 2.2.14, which are related to S3 transfer and the network.
I'd suggest following those tickets (please don't +1). It's reasonable to expect they will fix it within a week.
Here's a workaround until the bug is fixed, just fire this up in your application's onCreate, or well before any upload activity starts:
/**
* work around for a bug:
* http://stackoverflow.com/questions/36587511/android-amazon-s3-uploading-crash
*/
public static void startupTranferServiceEarlyToAvoidBugs(Context context) {
final TransferUtility tu = new TransferUtility(
new AmazonS3Client((AWSCredentials)null),
context);
tu.cancel(Integer.MAX_VALUE - 1);
}
essentially what this does is tell the TransferService to start up and initialize it's member variables so that it doesn't enter the condition where it tries to service commands before it's ready to.

SVM model fails to load in Android Application

I have a problem with load() method in SVM module. For example if I run code:
try {
Uri uri = Uri.fromFile(new File("file:///android_asset/SVM_Bills.xml"));
mySvm.load(uri.getPath());
int in = mySvm.get_support_vector_count();
if (in != 0) {
Toast.makeText(context,"done loading : " + uri.getPath(), Toast.LENGTH_SHORT).show();
value = (int)mySvm.predict(matOfDescriptor);
}
else {
Toast.makeText(context,"error while loading : " + uri.getPath(), Toast.LENGTH_SHORT).show();
}
It give me the error toast message (i.e it goes to else part and show the toast message).
Of course SVM was previously trained.
Any help please?

Titanium Android : Facebook dialog image URL not properly formatted

I developing an Android application using Titanium Appcelerator. I had tried to Post text and Image via facebook feed dialog
.. But error while load my local image URL..
var fileimg = Titanium.Filesystem.getFile(backupDir.nativePath, "myimg.jpg");
var fb_data1 = {
description : "Some good text",
picture : fileimg.nativePath,
link : "www.googlee.com",
};
facebook_qfav.dialog("feed", fb_data1, showRequestResult);
function showRequestResult(e) {
var s = '';
if (e.success) {
s = "SUCCESS";
if (e.result) {
s += "; " + e.result;
}
if (e.data) {
s += "; " + e.data;
}
if (!e.result && !e.data) {
s = '"success",but no data from FB.I am guessing you cancelled the dialog.';
}
} else if (e.cancelled) {
s = "CANCELLED";
} else {
s = "FAILED ";
if (e.error) {
s += "; " + e.error;
alert("facebook Share " + s);
}
}
}
ERROR: "Image URL not properly formatted"
File path will be like this: file:///storage/sdcard0/myimg.jpg
But if i pass the remote URL to the picture property , the image is shown in the dialog...
what happens to the local URL..?
I think the only issue is that nativepath has capital P in it. so, its : nativePath
so instead of picture : fileimg.nativepath, It Should be picture : fileimg.nativePath,
Documentation.
Hope it helps.

In the Android4.4 hwui, get the opengl error 0x0506

In the Android4.4 hwui, i get the opengl error log:
GL error from OpenGLRenderer: 0x0506
The error is the GL_INVALID_FRAMEBUFFER_OPERATION, i think maybe there is some error in the fbo, but the android hwui code, we did't modify it.
The error will make the Launcher icon draw error, or make the icon is black, but the error is not easy the appear, also I have not idea how the make it reappear, it will appear inadvertently.
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index d212786..239c235 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
## -13152,6 +13152,23 ## public class View implements Drawable.Callback, KeyEvent.Callback,
invalidate(true);
invalidateParentCaches();
+ } else if (info != null && info.mHardwareRenderer != null) {
+ // If fall into this path, means the hardware render has
+ // already been disabled. Destroy it in a safely context
+ // to avoid random UI corruption
+ info.mHardwareRenderer.safelyRun(new Runnable() {
+ #Override
+ public void run() {
+ mHardwareLayer.destroy();
+ mHardwareLayer = null;
+
+ if (mDisplayList != null) {
+ mDisplayList.reset();
+ }
+ invalidate(true);
+ invalidateParentCaches();
+ }
+ });
}
return true;
}
from Android bug——Launcher 0x506.Hope it can lend you a hand. :)

Categories

Resources