如何从editText获取和共享字符串?

时间:2016-11-09 00:46:16

标签: android browser android-edittext

我有一个EditText和一个按钮。当我按下按钮时,我希望按钮从EditText获取文本并在浏览器应用程序上共享。我尝试了一切,但它给了我一个例外 -

    EditText searchbox;

     ...

    searchbox = (EditText) findViewById(R.id.editText1);

     ...

public void searchbtn(View view) {
    String search = searchbox.getText().toString();
    String search1 = "m.youtube.com/watch?v=" + search.replace(" ", "+");

    Intent browserIntent = new Intent(Intent.ACTION_VIEW);
    browserIntent.setData(Uri.parse(search1));
    Intent.createChooser(browserIntent, "dialog title");
    startActivity(browserIntent);
}

这里我附上了我的日志 -

11-08 19:43:39.632: E/AndroidRuntime(7991): FATAL EXCEPTION: main
11-08 19:43:39.632: E/AndroidRuntime(7991): Process: com.example.avdx, PID: 7991
11-08 19:43:39.632: E/AndroidRuntime(7991): java.lang.IllegalStateException: Could not execute method for android:onClick
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.view.View$DeclaredOnClickListener.onClick(View.java:4740)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.view.View.performClick(View.java:5697)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.widget.TextView.performClick(TextView.java:10814)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.view.View$PerformClick.run(View.java:22526)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.os.Handler.handleCallback(Handler.java:739)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.os.Handler.dispatchMessage(Handler.java:95)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.os.Looper.loop(Looper.java:158)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.app.ActivityThread.main(ActivityThread.java:7229)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at java.lang.reflect.Method.invoke(Native Method)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
11-08 19:43:39.632: E/AndroidRuntime(7991): Caused by: java.lang.reflect.InvocationTargetException
11-08 19:43:39.632: E/AndroidRuntime(7991):     at java.lang.reflect.Method.invoke(Native Method)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.view.View$DeclaredOnClickListener.onClick(View.java:4735)
11-08 19:43:39.632: E/AndroidRuntime(7991):     ... 10 more
11-08 19:43:39.632: E/AndroidRuntime(7991): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=m.youtube.com/watch?v= VirtualScreenParam=Params{mDisplayId=-1, null, mFlags=0x00000000)} }
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1878)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1545)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.app.Activity.startActivityForResult(Activity.java:4283)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.app.Activity.startActivityForResult(Activity.java:4230)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.app.Activity.startActivity(Activity.java:4567)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at android.app.Activity.startActivity(Activity.java:4535)
11-08 19:43:39.632: E/AndroidRuntime(7991):     at com.example.avdx.MainActivity.searchbtn(MainActivity.java:80)
11-08 19:43:39.632: E/AndroidRuntime(7991):     ... 12 more

0 个答案:

没有答案