gpt4 book ai didi

android - 为什么我经常收到 ActivityNotFound 异常?

转载 作者:行者123 更新时间:2023-11-29 18:24:06 24 4
gpt4 key购买 nike

我是一名 Android 程序员新手,为了帮助我了解 Intents 的真正工作原理,我想将一个小的 Activity 放在一起,让用户可以调用 startActivity() 来调用他们想要的任何操作和数据。我尝试了许多不同的组合,包括“android.intent.action.VIEW”和“http://www.google.com”。无论我使用什么组合,我总是得到一个 ActivityNotFoundException。关于原因有什么想法吗?

我唯一的 Activity 中的代码如下:

public class TestingIntents extends Activity 
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button goButton = (Button) findViewById(R.id.button);

goButton.setOnClickListener(new ClickListener());
}

private class ClickListener implements OnClickListener
{
@Override
public void onClick(View arg0)
{
String id = ((EditText) findViewById(R.id.intent)).getText().toString();
String data = ((EditText) findViewById(R.id.data)).getText().toString();

Builder builder = new Builder();
builder = builder.path(data);

Uri path = builder.build();

Intent i = new Intent(id, path);
startActivity(i);
}
}
}

adb shell logcat 从启动应用程序到触摸“强制关闭”之后的结果如下。

I/ActivityManager( 1086):
Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=tk.h2g2guy.testin
gIntents/.TestingIntents }
I/ActivityManager( 1086): Start proc tk.h2g2guy.testingIntents for activity tk.h
2g2guy.testingIntents/.TestingIntents: pid=4037 uid=10054 gids={}
D/dalvikvm( 1006): GC_EXPLICIT freed 289 objects / 10960 bytes in 98ms
D/dalvikvm( 1006): GC_EXPLICIT freed 47 objects / 2088 bytes in 121ms
D/dalvikvm( 1006): GC_EXPLICIT freed 2 objects / 48 bytes in 109ms
I/ActivityManager( 1086): Displayed activity tk.h2g2guy.testingIntents/.TestingI
ntents: 462 ms (total 462 ms)
D/dalvikvm( 2300): GC_EXPLICIT freed 1226 objects / 61640 bytes in 69ms
I/ActivityManager( 1086): Starting activity: Intent { act=android.intent.action.
VIEW dat=http%3A//www.google.com }
D/AndroidRuntime( 4037): Shutting down VM
W/dalvikvm( 4037): threadid=1: thread exiting with uncaught exception (group=0x4
001d7e0)
E/AndroidRuntime( 4037): FATAL EXCEPTION: main
E/AndroidRuntime( 4037): android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=android.intent.action.VIEW dat=http%3A//www.google.
com }
E/AndroidRuntime( 4037): at android.app.Instrumentation.checkStartActivit
yResult(Instrumentation.java:1408)
E/AndroidRuntime( 4037): at android.app.Instrumentation.execStartActivity
(Instrumentation.java:1378)
E/AndroidRuntime( 4037): at android.app.Activity.startActivityForResult(A
ctivity.java:2817)
E/AndroidRuntime( 4037): at android.app.Activity.startActivity(Activity.j
ava:2923)
E/AndroidRuntime( 4037): at tk.h2g2guy.testingIntents.TestingIntents$Clic
kListener.onClick(TestingIntents.java:41)
E/AndroidRuntime( 4037): at android.view.View.performClick(View.java:2408
)
E/AndroidRuntime( 4037): at android.view.View$PerformClick.run(View.java:
8816)
E/AndroidRuntime( 4037): at android.os.Handler.handleCallback(Handler.jav
a:587)
E/AndroidRuntime( 4037): at android.os.Handler.dispatchMessage(Handler.ja
va:92)
E/AndroidRuntime( 4037): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 4037): at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime( 4037): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 4037): at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime( 4037): at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 4037): at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime( 4037): at dalvik.system.NativeStart.main(Native Method)

W/ActivityManager( 1086): Force finishing activity tk.h2g2guy.testingIntents/.
TestingIntents
W/ActivityManager( 1086): Activity pause timeout for HistoryRecord{449d4518 tk.h
2g2guy.testingIntents/.TestingIntents}
I/Process ( 4037): Sending signal. PID: 4037 SIG: 9
I/ActivityManager( 1086): Process tk.h2g2guy.testingIntents (pid 4037) has died.

I/WindowManager( 1086): WIN DEATH: Window{44bd4120 tk.h2g2guy.testingIntents/tk.
h2g2guy.testingIntents.TestingIntents paused=false}

最佳答案

I tried many different combinations, including "android.intents.action.VIEW" and "html://www.google.com".

android.intents.action.VIEW 不是有效的 Activity 操作。您可能想要删除 s

html://www.google.com 不是有效的 URL。您可能希望将 html:// 替换为 http://

关于android - 为什么我经常收到 ActivityNotFound 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3436733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com