2011-06-04 12 views
5

Uygulamamda bir sorunum var. Bazı listelerim var ve her birinin bir randevusu var. Bir listenin tarihi bugün yapılmış ise bir Bildirim yaptım ve bildirimimde öğeleri o listeden koydum. Sorun şu ki, eğer listem boşsa, güç alıyorum. Bildirimi yalnızca imleç null değilse bildirim yapmak için koydum, ama bu işe yaramaz gibi görünüyor. Sorunun nerede olduğunu bulmama yardım edebilir misin?Android'de boş imleç

cr = db.fetchListId(id); 
startManagingCursor(cr); 

s = new StringBuilder(100); 
if (cr != null) { 
    do { 
    String myList = ""; 
    myList += cr.getString(2) + " " + cr.getString(3) 
     + cr.getString(4) + "," + "\n"; 
    s.append(myList); 

    } while (cr.moveToNext()); 
    s.append('.'); 
    System.out.println("!!heyeheeye!" + s + "!!!!"); 
    hey(list); 
} 

where hey(list) is a function where is made the notification. 

    private void hey(String list) { 
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    CharSequence NotificationTicket = "Hey"; 

    long when = System.currentTimeMillis(); 

    Notification notification = new Notification(R.drawable.icon, 
               NotificationTicket, when); 

    RemoteViews contentView = new RemoteViews(getPackageName(), 
              R.layout.proba); 
    contentView.setImageViewResource(R.id.image, R.drawable.icon); 
    contentView.setTextViewText(R.id.notif, 
           "Today,you must go for shopping for your list '" + list + "'. " 
           + "Don't forget!!!" + "\n" + "You must buy :" + "\n" 
           + s.toString() + "\n"); 
    notification.contentView = contentView; 


    Context context = getApplicationContext(); 

    Intent notifyIntent = new Intent(context, Lists.class); 

    Intent notificationIntent = new Intent(this, Lists.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
                  notificationIntent, 0); 
    notification.contentIntent = contentIntent; 

    notificationManager.notify(ID_NOTIFICATION, notification); 
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 


       | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
} 

cevap

6

imleç herhangi bir sonuç olup olmadığını görmek için aşağıdaki onay ekleyin: Sen moveToFirst gerek

if (cr != null && cr.moveToFirst()) { 
    // ... 
} 

() verileri almadan önce Burada

kod parçasıdır. Çünkü bir şey kullanıyorsunuz ... while() yerine, imleci düzgün bir şekilde başlatmıyorsunuz.

+0

Teşekkürler. Haklısın, şimdi işe yarıyor .. – Gaby