App force closes when the database is empty
<p>I have created a custom Cursor Adapter for my list.The list gets some data from a database</p>

<p>My problem is that my app force closes when i try to get to my activity and there is no item in the database to show.I would like to get a toast message if there is no entry in my database and  not crash my app.</p>

<p>This is my logCat :</p>

<pre><code>02-03 15:21:05.710: E/AndroidRuntime(24768): FATAL EXCEPTION: main
02-03 15:21:05.710: E/AndroidRuntime(24768): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.ListView.clearRecycledState(ListView.java:513)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.ListView.resetList(ListView.java:500)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.ListView.layoutChildren(ListView.java:1534)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.AbsListView.onLayout(AbsListView.java:1863)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.View.layout(View.java:11278)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.View.layout(View.java:11278)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.View.layout(View.java:11278)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.View.layout(View.java:11278)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.View.layout(View.java:11278)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.ViewGroup.layout(ViewGroup.java:4224)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.os.Looper.loop(Looper.java:137)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at android.app.ActivityThread.main(ActivityThread.java:4424)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at java.lang.reflect.Method.invokeNative(Native Method)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at java.lang.reflect.Method.invoke(Method.java:511)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
02-03 15:21:05.710: E/AndroidRuntime(24768):    at dalvik.system.NativeStart.main(Native Method)
02-03 15:21:07.007: I/Process(24768): Sending signal. PID: 24768 SIG: 9
</code></pre>

<p>CODE:</p>

<pre><code>public class Adapter extends CursorAdapter{    
     Cursor c;
     LayoutInflater inflater;
     Context context;

        public Adapter(Context context, Cursor c) {
            super(context, c);    
            this.c = c;
            this.context = context;
            inflater = LayoutInflater.from(context);
        }           
        @Override
            public View newView(Context context, Cursor cursor, ViewGroup parent) {
            View v = null;
         try{           
             v = inflater.inflate(R.layout.row, null);}             
             catch (Exception e) {
             e.printStackTrace();
            }
            return v;
        }
            @Override
              public void bindView(View view, final Context context, final Cursor cursor) {    
              final TextView txtName = (TextView) view.findViewById(R.id.textView01);
              txtName.setText(cursor.getString(cursor.getColumnIndex(DBHelper.NAME)));              
              ImageButton button = (ImageButton) view.findViewById(R.id.btn);
              button.setOnClickListener(new OnClickListener() {  

              public void onClick(View arg0) {    
                  Toast.makeText(context,"item Deleted", Toast.LENGTH_SHORT).show();                                   
           }
           });            
        }          
    }
</code></pre>

<p>RR.layout.row</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent" android:layout_height="wrap_content"
   android:background="#ffffff" android:gravity="center_vertical"
   android:orientation="horizontal"&gt;    

    &lt;LinearLayout 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" android:orientation="vertical"
         android:layout_weight="1"  &gt;
    &lt;TextView 
         android:id="@+id/textView01" android:layout_width="wrap_content"
         android:layout_height="wrap_content" android:textColor="#000000"
         android:textSize="16dp" android:textStyle="bold"  /&gt;    
    &lt;ImageButton 
         android:id="@+id/btn"
         android:layout_width="wrap_content" android:layout_height="wrap_content"
         android:background="@drawable/btn_bg" /&gt;
    &lt;/LinearLayout&gt;

&lt;/LinearLayout&gt;
</code></pre>
