Showing posts with label nullpointerexception. Show all posts
Showing posts with label nullpointerexception. Show all posts

11 December 2012

Android development crusade part 15: What to do ?

Crash report gave an awesome information sometimes:
What i know is :

exception:  java.lang.NullPointerException
happen  in: TextView.IsEndHandleVisible()
on mobile:  Samsung  SCH-I405


Stack Trace:
 java.lang.NullPointerException
at android.widget.TextView.IsEndHandleVisible(TextView.java:9130)
at android.widget.TextView$CursorControllerMenu.showCursorControllerMenu(TextView.java:9597)
at android.widget.TextView.onTextContextMenuItem(TextView.java:7807)
at android.widget.TextView$MenuHandler.onMenuItemClick(TextView.java:7765)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:137)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:143)
at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:917)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1980)
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:3689)
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)

Now i have a tiny problem.
 I don't have  a ListView with TextView inside !

 I go thru all layouts and I found, that i  have 2 ListViews (ListView in camera,gps) but both of them doesn't have TextView and I using another dynamicaly clreate ListView in camera.

I have no clue where problem is at the moment
SCH-I405 is a CDMA only phone,so i expected that TelephonyInfo will be response for that but it doesn't use ListView at all.

It is very unlikely that somebody use camera as is hidden in settings.


13 December 2011

Why findViewById(R.id.cozyUIElement) is null,even if i am DAMN SURE that i defined in xml file for UI ???

Case:
so you create your awesome UI in xml like and then in activity file you code that should change your progress bar and your program crashed and IDE said that

Error message looks like:
findViewById(R.id.cozyUIElement) is null

What went wrong ?
You need set content view before you can match them with your  class from view

Right way to do it is:

setContentView(R.layout.cozy);   <--- THIS MUST BE FIRST
cozyProgressBar = (ProgressBar) findViewById(R.id.cozyUIElement  ); <--THIS method need appear after setContentView(...)!

So check your onCreate() method and look are you using any  findViewById() method before  setContentView(R.layout.cozy)  if you found any,then you found your problem :)

Example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >

<ProgressBar
  android:id="@+id/cozyUIElement"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:max="100"
android:visibility="visible" />

</LinearLayout>


and then in your activity file

package ,imports and other spam
(...)
public class CozyActivity extends Activity{
    ProgressBar cozyProgressBar;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.cozy);  
cozyProgressBar = (ProgressBar) findViewById(R.id.cozyUIElement  );
   cozyProgressBar.setProgress(20);
 }