Bluetooth App Crashes with error FATAL EXCEPTION: main - android

My Bluetooth application's can already auto request to enable bluetooth but when I did some functionality on my option menu the application will crash right after the bluetooth was turned on.
These were the messages found in the LogCat:
12-21 15:20:08.531: D/BluetoothCommandService(1203): start
12-21 15:20:08.531: D/BluetoothCommandService(1203): setState() 0 -> 1
12-21 15:20:08.581: W/dalvikvm(1203): threadid=1: thread exiting with uncaught exception (group=0x40028870)
12-21 15:20:08.851: E/AndroidRuntime(1203): FATAL EXCEPTION: main
12-21 15:20:08.851: E/AndroidRuntime(1203): java.lang.NullPointerException
12-21 15:20:08.851: E/AndroidRuntime(1203): at com.example.javac101.MainActivity$1.handleMessage(MainActivity.java:171)
12-21 15:20:08.851: E/AndroidRuntime(1203): at android.os.Handler.dispatchMessage(Handler.java:95)
12-21 15:20:08.851: E/AndroidRuntime(1203): at android.os.Looper.loop(Looper.java:123)
12-21 15:20:08.851: E/AndroidRuntime(1203): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-21 15:20:08.851: E/AndroidRuntime(1203): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:20:08.851: E/AndroidRuntime(1203): at java.lang.reflect.Method.invoke(Method.java:521)
12-21 15:20:08.851: E/AndroidRuntime(1203): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-21 15:20:08.851: E/AndroidRuntime(1203): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-21 15:20:08.851: E/AndroidRuntime(1203): at dalvik.system.NativeStart.main(Native Method)
What would be the possible main cause of this errors?

title might be null here.
Also change
title.setText(R.string.title_notConnected);
to
title.setText(getString(R.string.title_notConnected));

Related

Zbar : startPreview failed in galaxy S3

I have used ZBAR library to scan bar code in my Application.
And I got this error log while opening camera on Samsung Galaxy S3 :
java.lang.RuntimeException: startPreview failed
at android.hardware.Camera.startPreview(Native Method)
at com.SGID.MainApp.ScanningFragment.engageCamera(ScanningFragment.java:184)
at com.SGID.MainApp.ScanningFragment.access$10(ScanningFragment.java:154)
at com.SGID.MainApp.ScanningFragment$4.run(ScanningFragment.java:111)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.SGID.MainApp/com.SGID.MainApp.AllTabsActivity}
: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.SGID.MainApp.ParametersFragment.onCreateView(ParametersFragment.java:78)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1167)
at android.app.Activity.performStart(Activity.java:5216)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
... 11 more
EDIT :
Getting error at this line :
CameraPreview mPreview = new CameraPreview(getActivity(), mCamera, previewCb,
autoFocusCB);
Can Anyone help me to resolve this error??
Thanks in advance..

Selecting an item in ListFragment list programmatically

I've made my Android app tablet optimized and I followed the tutorial here:
Everything is great, but I am trying to select an item (say, the 1st item) with a button in the ActionBar.
I tried this answer to use performItemClick but on I've got error reports of java.lang.IllegalStateException
in android.support.v4.app.ListFragment.ensureList, java.lang.IllegalStateException: Content view not yet created, and java.lang.NullPointerException
in android.content.ComponentName.<init>
I've tried checking if the ListView is null and still get the error reports on the Play Store. How do I properly select an item in my list programmatically?
Update to add logcat and the code is virtually identical to the tutorials in the links:
Logcat A:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:69)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2606)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1045)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:592)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:149)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17273)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Logcat B:
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2874)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:86)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:779)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Update 2
And here is the code that is causing the problem:
if (mListFragment.listView != null) {
mListFragment.listView.performItemClick(mListFragment.listView.getAdapter().getView(position, null, null), position, mListFragment.listView.getAdapter().getItemId(position));
}

How to disable a tab bar item in android?

I am making my first android app. I want to disable a tab bat item in my android app. I searched and found the following way to do that:
tabHost = (TabHost)findViewById(R.id.tabhost);
tabHost.getTabWidget().getChildTabViewAt(your_index).setEnabled(false);
but its not working and i am getting following error:
06-11 16:53:15.927: D/AndroidRuntime(8466): Shutting down VM
06-11 16:53:15.927: W/dalvikvm(8466): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
06-11 16:53:16.037: D/dalvikvm(8466): GC_FOR_MALLOC freed 5350 objects / 347632 bytes in 98ms
06-11 16:53:16.047: E/AndroidRuntime(8466): FATAL EXCEPTION: main
06-11 16:53:16.047: E/AndroidRuntime(8466): java.lang.IllegalStateException: Could not execute method of the activity
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View$1.onClick(View.java:2072)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View.performClick(View.java:2408)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View$PerformClick.run(View.java:8817)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.os.Handler.handleCallback(Handler.java:587)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.os.Handler.dispatchMessage(Handler.java:92)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.os.Looper.loop(Looper.java:143)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.app.ActivityThread.main(ActivityThread.java:4914)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invoke(Method.java:521)
06-11 16:53:16.047: E/AndroidRuntime(8466): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-11 16:53:16.047: E/AndroidRuntime(8466): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-11 16:53:16.047: E/AndroidRuntime(8466): at dalvik.system.NativeStart.main(Native Method)
06-11 16:53:16.047: E/AndroidRuntime(8466): Caused by: java.lang.reflect.InvocationTargetException
06-11 16:53:16.047: E/AndroidRuntime(8466): at com.eplinovo.runnoandroid.ActivityViewActivity.startClick(ActivityViewActivity.java:40)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 16:53:16.047: E/AndroidRuntime(8466): at java.lang.reflect.Method.invoke(Method.java:521)
06-11 16:53:16.047: E/AndroidRuntime(8466): at android.view.View$1.onClick(View.java:2067)
06-11 16:53:16.047: E/AndroidRuntime(8466): ... 11 more
06-11 16:53:16.047: E/AndroidRuntime(8466): Caused by: java.lang.NullPointerException
06-11 16:53:16.047: E/AndroidRuntime(8466): ... 15 more
Why am i getting that? Thanks in advance.
Ok. Go to the top of the error in logcat, which is ActivityViewActivity.startClick. Go ahead and click on this line. It will take you to some line in startClick method where there is a null pointer exeption. Tell us what is on that line. It might be the line above. If it is than for example
tabHost might be null. Check this separately.
tabHost.getWidget()
tagHost.getWidget().getChildTabViewAt(your_index) // I bet its this one thats null.
if any of the above are null you will get that exception assumming that the line causing the problem. If not its something similar on another line.
So divide and conquer. Find the line. Split it up to find what might be null. Then set a breakpoint before the line runs, and step one line at a time. Hover over to see what is null at each step. Thats how you can solve any null pointer in android.
I was not getting tabhost in right way.
tabHost = (TabHost)findViewById(R.id.tabhost);
Following is the right way to get tabhost from child activity:
tabHost = (TabHost)getParent().findViewById(android.R.id.tabhost);

Adding googlecalendar events in an android application

I'm a newbie to android programming and have been trying to add events to google calendar via an android application. I found a nice example on the web but cannot seem to get the code to run as the application crashes as soon as the emulator launches. I'm emulating the code on the ANDROID DEVICE (Google APIs/API LEVEL 14).Below is the URL of the code;
http://roman10.net/src/calendarops.zip
Here are the errors which I receive in the logcat;
12-21 15:24:16.602: D/AndroidRuntime(675): Shutting down VM
12-21 15:24:16.612: W/dalvikvm(675): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-21 15:24:16.622: E/AndroidRuntime(675): FATAL EXCEPTION: main
12-21 15:24:16.622: E/AndroidRuntime(675): java.lang.RuntimeException: Unable to start activity ComponentInfo{roman10.tutorial.calendarops/roman10.tutorial.calendarops.Main}: android.database.sqlite.SQLiteException: no such column: displayName: , while compiling: SELECT _id, displayName FROM Calendars
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.os.Looper.loop(Looper.java:137)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-21 15:24:16.622: E/AndroidRuntime(675): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:24:16.622: E/AndroidRuntime(675): at java.lang.reflect.Method.invoke(Method.java:511)
12-21 15:24:16.622: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-21 15:24:16.622: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-21 15:24:16.622: E/AndroidRuntime(675): at dalvik.system.NativeStart.main(Native Method)
12-21 15:24:16.622: E/AndroidRuntime(675): Caused by: android.database.sqlite.SQLiteException: no such column: displayName: , while compiling: SELECT _id, displayName FROM Calendars
12-21 15:24:16.622: E/AndroidRuntime(675): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.content.ContentResolver.query(ContentResolver.java:310)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.Activity.managedQuery(Activity.java:1706)
12-21 15:24:16.622: E/AndroidRuntime(675): at roman10.tutorial.calendarops.Main.getCalendars(Main.java:127)
12-21 15:24:16.622: E/AndroidRuntime(675): at roman10.tutorial.calendarops.Main.onCreate(Main.java:50)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.Activity.performCreate(Activity.java:4465)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-21 15:24:16.622: E/AndroidRuntime(675): ... 11 more
Here it is:
android.database.sqlite.SQLiteException: no such column: displayName:
, while compiling: SELECT _id, displayName FROM Calendars
There is no column with the name 'displayName' in your Calendars table.
Since you are using ICS (SDK 14) they have changed the way they handle Calanders and have made a public API. See http://android-developers.blogspot.com/2011/10/ics-and-non-public-apis.html

Difficulty in integrating a separate project into other project

I have a project which has gui consisting of three buttons.Now one of these button is to be associated with other activity.I have developed the code for this activity separately and tested it but now when I'm integrating this in my main gui project it is showing errors.(Clicking on button will get me the current location on google maps).
Here is my log cat :
10-27 01:45:44.533: E/ActivityThread(357): Failed to find provider info for com.google.settings
10-27 01:45:44.563: E/ActivityThread(357): Failed to find provider info for com.google.settings
10-27 01:45:44.633: D/AndroidRuntime(357): Shutting down VM
10-27 01:45:44.633: W/dalvikvm(357): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
10-27 01:45:44.643: E/AndroidRuntime(357): Uncaught handler: thread main exiting due to uncaught exception
10-27 01:45:44.653: E/AndroidRuntime(357): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gui/com.example.gui.LocationActivity}: java.lang.NullPointerException
10-27 01:45:44.653: E/AndroidRuntime(357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.os.Looper.loop(Looper.java:123)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.app.ActivityThread.main(ActivityThread.java:4363)
10-27 01:45:44.653: E/AndroidRuntime(357): at java.lang.reflect.Method.invokeNative(Native Method)
10-27 01:45:44.653: E/AndroidRuntime(357): at java.lang.reflect.Method.invoke(Method.java:521)
10-27 01:45:44.653: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-27 01:45:44.653: E/AndroidRuntime(357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-27 01:45:44.653: E/AndroidRuntime(357): at dalvik.system.NativeStart.main(Native Method)
10-27 01:45:44.653: E/AndroidRuntime(357): Caused by: java.lang.NullPointerException
10-27 01:45:44.653: E/AndroidRuntime(357): at com.example.gui.LocationActivity.onCreate(LocationActivity.java:50)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-27 01:45:44.653: E/AndroidRuntime(357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
10-27 01:45:44.653: E/AndroidRuntime(357): ... 11 more
10-27 01:45:44.693: I/dalvikvm(357): threadid=7: reacting to signal 3
10-27 01:45:44.693: E/dalvikvm(357): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
Can anyone help me to solve this ?
You are getting the error message because at line 50 when you call
map.setBuiltInZoomControls(true);
your map variable is null. Please post your main.xml file as that is where your onCreate method is looking for views when you call findViewById since you called
setContentView(R.layout.main);

Categories

Resources