2016-08-19 31 views
2

我正在做一個通知視圖項目。通知欄上會出現通知,當我點擊通知欄時,它會繼續下一個活動,以顯示與通知內容相同的信息。但得到這個錯誤...E /表面:getSlotFromBufferLocked:未知的緩衝區:0xb96ae9c0得到這個錯誤

E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb96ae9c0 

我的代碼是

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    Button view_notifi,btn_time,btn_date; 
    int notificationID,getHour,getMin,getDay,getMonth,getYear; 
    final int dialogTime=0,dialogDate=1; 
    Notification notification; 
    EditText edt_heading,edt_details,edt_details2; 
    String head,details,details2; 
    String Time,setDate; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     edt_heading=(EditText)findViewById(R.id.editText_Heading); 
     edt_details=(EditText)findViewById(R.id.editText_Details); 
     edt_details2=(EditText)findViewById(R.id.editText_details2); 
     notificationID=1; 
     view_notifi=(Button)findViewById(R.id.button_viewN); 
     btn_time=(Button)findViewById(R.id.button_time); 
     btn_date=(Button)findViewById(R.id.button_date); 
     view_notifi.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       head=edt_heading.getText().toString(); 
       details=edt_details.getText().toString(); 
       details2=edt_details2.getText().toString(); 
       displayNotification(head,details,details2); 
       edt_heading.getText().clear(); 
       edt_details.getText().clear(); 
       edt_details2.getText().clear(); 
      } 
     }); 
    } 

    public void getTimeInfo(View view){ 
     showDialog(dialogTime); 
    } 
    public void getDateInfo(View view){ 
     showDialog(dialogDate); 
    } 
    protected Dialog onCreateDialog(int id){ 
     switch (id){ 
      case dialogTime: 
       return new TimePickerDialog(this,mTimeListener,getHour,getMin,false); 
      case dialogDate: 
       DatePickerDialog dialog = new DatePickerDialog(this, mDateListener, getYear, getMonth, getDay); 
       DatePicker datePicker = dialog.getDatePicker(); 
       Calendar calendar = Calendar.getInstance(); 
       datePicker.setMinDate(calendar.getTimeInMillis()); 
       //dialog.getDatePicker().setMinDate(new Date().getTime()); 
       return dialog; 
       //return new DatePickerDialog(this,mDateListener,getYear,getMonth,getDay); 
     } 
     return null; 
    } 

    private TimePickerDialog.OnTimeSetListener mTimeListener=new TimePickerDialog.OnTimeSetListener(){ 
     @Override 
     public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 
      getHour=hourOfDay; getMin=minute; 
      Time=String.valueOf(" "+getHour+":"+getMin); 
      Toast.makeText(getBaseContext(),"Time: "+Time,Toast.LENGTH_SHORT).show(); 
     } 
    }; 
    private DatePickerDialog.OnDateSetListener mDateListener=new DatePickerDialog.OnDateSetListener() { 
     @Override 
     public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 

      getYear=year; getMonth=monthOfYear+1;getDay=dayOfMonth; 
      //getMonth=+1; 
      setDate=String.valueOf(" "+getDay+"/"+getMonth+"/"+getYear); 
      Toast.makeText(getBaseContext(),"Date: "+setDate,Toast.LENGTH_SHORT).show(); 
     } 
    }; 

    public void displayNotification(String str1,String str2,String str3){ 


     Intent intent = new Intent("notify_filter"); 
     Bundle bundle = new Bundle(); 
     bundle.putString("arg1", str1); 
     bundle.putString("arg2", str2); 
     bundle.putString("arg3", str3); 
     bundle.putString("arg4", Time); 
     bundle.putString("arg5", setDate); 
     intent.putExtras(bundle); 
     intent.putExtra("notificationID",notificationID); 

     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); 
     Notification.Builder builder = new Notification.Builder(MainActivity.this); 

     builder.setAutoCancel(true); 
     builder.setTicker("New Alert..."); 
     builder.setSmallIcon(R.mipmap.ic_launcher); 
     builder.setContentTitle(str1); 
     builder.setContentText(str2); 
     builder.setSubText("Time " + Time + " Date:" + setDate); //API level 16 
     builder.setContentIntent(pendingIntent); 
     builder.setOngoing(true); 
     builder.setNumber(100); 
     builder.build(); 


     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

     notification = builder.getNotification(); 
     notification.vibrate = new long[]{100, 250, 100, 400}; 
     notificationManager.notify(notificationID, notification); 

    } 
} 

ViewNotification.java

public class ViewNotification extends AppCompatActivity { 

    TextView head,detail1,detail2,time,date; 
    Bundle bundle; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_view_notification); 

     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     notificationManager.cancel(getIntent().getExtras().getInt("notificationID")); 
     head=(TextView)findViewById(R.id.textView_head); 
     detail1=(TextView)findViewById(R.id.textView_det1); 
     detail2=(TextView)findViewById(R.id.textView_det2); 
     time=(TextView)findViewById(R.id.textView_time); 
     date=(TextView)findViewById(R.id.textView_date); 
     bundle = getIntent().getExtras(); 
     String view1= bundle.getString("arg1"); 
     String view2= bundle.getString("arg2"); 
     String view3= bundle.getString("arg3"); 
     //String view4=bundle.getString("arg4"); 
     //String view5=bundle.getString("arg5"); 
     head.setText(view1); 
     detail1.setText(view2); 
     detail2.setText(view3); 
     time.setText(bundle.getChar("arg4")); 
     date.setText(bundle.getChar("arg5")); 
    } 
} 

回答

0

這種情況發生時,你嘗試設置val將TextView的ue轉換爲整數。

當您爲字符串賦值給TextView時,此錯誤消失。

例如

我已經在xml文件中創建了一個文本視圖。我試圖從java代碼中設置特定文本字段的值。我將整型值設置爲文本視圖,但我收到一個錯誤getSlotFromBufferLocked:未知的緩衝區:0xab7519c0但將值從int更改爲String並從該String中設置TextView後,錯誤消失,應用程序正常工作。

相關問題