2017-04-02 64 views
-1

我嘗試測試演示上傳錄製的視頻 我得到這個錯誤:ActionBar.setBackgroundDrawable(android.graphics.drawable.Drawable)」空對象引用

ActionBar.setBackgroundDrawable(android.graphics.drawable.Drawable)' on a null object reference 

我用這個演示: uploading-camera-image-video-to-server-with-progress-bar

我可以錄製視頻,但是當我點擊保存去其他活動的Uplading文件,我得到上述

錯誤是由這裏的OnCreate錯誤:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_upload); 
    txtPercentage = (TextView) findViewById(R.id.txtPercentage); 
    btnUpload = (Button) findViewById(R.id.btnUpload); 
    progressBar = (ProgressBar) findViewById(R.id.progressBar); 
    imgPreview = (ImageView) findViewById(R.id.imgPreview); 
    vidPreview = (VideoView) findViewById(R.id.videoPreview); 

    // Changing action bar background color 
    getActionBar().setBackgroundDrawable(
      new ColorDrawable(Color.parseColor(getResources().getString(
        R.color.action_bar)))); 

    // Receiving the data from previous activity 
    Intent i = getIntent(); 

    // image or video path that is captured in previous activity 
    filePath = i.getStringExtra("filePath"); 

    // boolean flag to identify the media type, image or video 
    boolean isImage = i.getBooleanExtra("isImage", true); 

    if (filePath != null) { 
     // Displaying the image or video on the screen 
     previewMedia(isImage); 
    } else { 
     Toast.makeText(getApplicationContext(), 
       "Sorry, file path is missing!", Toast.LENGTH_LONG).show(); 
    } 

    btnUpload.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // uploading the file to server 
      new UploadFileToServer().execute(); 
     } 
    }); 

} 
+0

的可能的複製[什麼是空指針異常,以及如何解決?(http://stackoverflow.com/問題/ 218384 /什麼 - 是 - 一 - NullPointerException異常和知識-DO-I-FIX-IT) –

回答

0

刪除這條線的顏色後,我有固定的錯誤:

//getActionBar().setBackgroundDrawable(
     new ColorDrawable(Color.parseColor(getResources().getString(
       R.color.action_bar))));