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

后端 未结 1 1844
野的像风
野的像风 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:

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.NautGames.xecta.app.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        // add every activity in your app like this below
        <activity
            android:name="com.NautGames.xecta.app.AndroidFileDownloader"
            android:label="@string/app_name" />
    </application>  
    
    0 讨论(0)
提交回复
热议问题