不幸的是,当点击按钮时App停止了

时间:2017-11-26 09:07:49

标签: android

我用mp3 / mp4按钮创建了一个应用程序。当我点击按钮时,应用程序不幸停止。

我搜索了很多,但没有找到任何解决方案。我也使用了Button onClick监听器,它没有用。

这是XML布局:

package vk.com.downloadtosd;

public class SharedActivity extends AppCompatActivity {
WebView shared;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
                setContentView(R.layout.shared);
                setTitle("Youtube Downloader");
                Toast.makeText(this,"Welcome to App",Toast.LENGTH_LONG).show();
            }

        }
    }

    public void mp3(View view,Intent intent) {
        setContentView(R.layout.shared);
        setTitle("Youtube Downloader");
        shared=(WebView) findViewById(R.id.shared);
        String link=intent.getStringExtra(Intent.EXTRA_TEXT);
        if(link!=null){
            startWebView( "https://google.com/controller.php?type=mp3&urlid="+link);
            Toast.makeText(this,"Processing...Please Wait",Toast.LENGTH_LONG).show();

        }

    }


    public void mp4(View view,Intent intent) {
        setContentView(R.layout.shared);
        setTitle("Youtube Downloader");
        shared=(WebView) findViewById(R.id.shared);
        String link=intent.getStringExtra(Intent.EXTRA_TEXT);
        if(link!=null){
            startWebView( "https://www.google.com/controller.php?type=mp4&urlid="+link);
            Toast.makeText(this,"Processing ..Please Wait",Toast.LENGTH_LONG).show();

        }
    }

    public void about(View view) {
        Toast.makeText(this,"About me",Toast.LENGTH_LONG).show();
    }

    private void startWebView(String s) {
        shared.setWebViewClient( new
                                         WebViewClient() {
                                             ProgressDialog progressDialog;
                                             public void onReceivedError
                                                     ( WebView view, int errorCode,
                                                       String description, String failingUrl) {
                                                 view.loadUrl( "file:///android_asset/error.html" );
                                             }

                                             //If you will not use this method url links are opeen in new brower not in webview
                                             //  public boolean shouldOverrideUrlLoading(WebView view, String url) {
                                             //    view.loadUrl(url);
                                             // return true ;
                                             //}
                                             @Override
                                             public boolean shouldOverrideUrlLoading(WebView view, String url) {
                                                 if (view.getUrl().equals("www.google.com")) {
                                                     // This is my web site, so do not override; let my WebView load the page
                                                     return false;
                                                 }
                                                 // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
                                                 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                                                 startActivity(intent);
                                                 return true;
                                             }
                                             //Show loader on url load
                                             public void onLoadResource (WebView view, String url) {
                                                 if (progressDialog == null ) {
// in standard case YourActivity.this
                                                     progressDialog = new ProgressDialog(SharedActivity.this );
                                                     progressDialog.setMessage( "Processing video..." );
                                                     progressDialog.show();
                                                 }
                                             }
                                             public void onPageFinished(WebView view, String url) {
                                                 try {
                                                     if (progressDialog.isShowing()) {
                                                         progressDialog.dismiss();
                                                         progressDialog = null;
                                                     }
                                                 } catch(Exception exception){
                                                     exception.printStackTrace();
                                                 }
                                             }
                                         });

        shared.getSettings().setJavaScriptEnabled( true );

        shared.loadUrl(s);
    }

}//last

这是我的主要Java代码:

{{1}}

1 个答案:

答案 0 :(得分:0)

您应该替换它以侦听XML文件上标记的onClick事件:

public void mp3(View view, Intent intent) {

public void mp3(View view) {

和mp4相同。

请永远不要使用" Don`t标记为重复或其他任何内容的短语。",主持人应该可以自由决定他们想要的任何内容。