“Unfortunately, … has stopped” when Downloading file in Android

后端 未结 1 1870
野的像风
野的像风 2021-01-26 13:43

I\'m trying to make an app in Android Studio which requires you to download a file to the sdcard/Download/ folder on the users device. The problem is that when I enter the URL t

1条回答
  •  自闭症患者
    2021-01-26 14:19

    Since you said it's in AndroidFileDownload, I'd suggest you to do as follows:

    @Override
    public void onClick(View view)
         // you need to get the id of the clicked view:
        if(view.getId() == R.id.download_button) {
            EditText urlInputField = (EditText) thisActivity.findViewById(R.id.url_input);
            String urlInput = urlInputField.getText().toString();
            downloaderThread = new DownloaderThread(thisActivity, urlInput);
            downloaderThread.start();
        }
    }
    

    This is the cause of: NoSuchMethodException: onClick [class android.view.View]. It means that your onClick method cannot find your button (id) where you did set an onClickListener method.

    And then, in the future, I think the problem will be that AndroidFileDownload is not declared in your Manifest file. You should add it as follows:

    
        
            
                
    
                
            
        
        // add every activity in your app like this below
        
      
    

    0 讨论(0)
提交回复
热议问题