为什么我会不断得到ActivityNotFound异常? [英] Why do I constantly get ActivityNotFound exceptions?
问题描述
我唯一的活动中的代码如下:
public class TestingIntents extends Activity
{
/ **首次创建活动时调用。 * /
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
按钮goButton =(Button)findViewById(R.id.button);
goButton.setOnClickListener(new ClickListener());
}
私有类ClickListener实现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):
开始活动:Intent {act = android.intent.action。
MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10200000 cmp = tk.h2g2guy.testin
gIntents / .TestingIntents}
I / ActivityManager(1086):启动proc tk。 h2g2guy.testing活动tk.h
2g2guy.testingIntents / .TestingIntents:pid = 4037 uid = 10054 gids = {}
D / dalvikvm(1006):GC_EXPLICIT在98ms $中释放289个对象/ 10960个字节
D / dalvikvm(1006):GC_EXPLICIT在121ms中释放47个对象/ 2088个字节
D / dalvikvm(1006):GC_EXPLICIT在109ms中释放2个对象/ 48个字节
I / ActivityManager(1086)显示的活动tk.h2g2guy.testingIntents / .TestingI
ntents:462 ms(总共462 ms)
D / dalvikvm(2300):GC_EXPLICIT在69ms中释放1226个对象/ 61640个字节
I / ActivityManager (1086):开始活动:Intent {act = android.intent.action。
VIEW dat = http%3A // www.google.com}
D / AndroidRuntime(4037):关闭VM
W / dalvikvm(4037):threadid = 1:线程退出未捕获的异常(组= 0x4
001d7e0)
E / AndroidRuntime(4037):FATAL EXCEPTION:main
E / AndroidRuntime(4037):android.content.ActivityNotFoundException:No Activity
发现处理Intent {act = android.intent.action.VIEW dat = http%3A // www.google。
com}
E / AndroidRuntime(4037):在android.app.Instrumentation.checkStartActivit
yResult(Instrumentation.java:1408)
E / AndroidRuntime(4037):在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):在android.os.Handler.handleCallback(Handler.jav
a:587)
E / AndroidRuntime(4037):在android.os.Handler.dispatchMessage(Handler.ja
va:92)
E / Android运行时(4037):在android.os.Looper.loop(Looper.java:123)
E / AndroidRuntime(4037):在android.app.ActivityThread.main(ActivityThrea
d.java:4627 )
E / AndroidRuntime(4037):在java.lang.reflect.Method.invokeNative(Native
方法)
E / AndroidRuntime(4037):在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):强制整理活动tk.h2g2guy.testingIntents /。
TestingIntents
W / ActivityManager(1086):HistoryRecord的活动暂停超时{449d4518 tk.h
2g2guy.testingIntents / .TestingIntents}
I / Process(4037):发送信号。 PID:4037 SIG:9
I / ActivityManager(1086):进程tk.h2g2guy.testingIntents(pid 4037)已经死亡。
I / WindowManager(1086):WIN DEATH:Window {44bd4120 tk.h2g2guy.testingIntents / tk。
h2g2guy.testingIntents.TestingIntents paused = false}
我尝试了许多不同的组合,
包括
android.intents.action.VIEW和
html://www.google.com。
android.intents.action.VIEW
不是有效的活动动作。你可能要删除 s
。
html://www.google。 com
不是有效的网址。你可能要用 http://
替换 html://
。
I'm a novice Android programmer, and to help me understand how Intents really work, I wanted to put together a small Activity which would let the user call startActivity() with any action and data they want. I tried many different combinations, including "android.intent.action.VIEW" and "http://www.google.com". No matter what combinations I use, I always get an ActivityNotFoundException. Any ideas as to why?
The code in my only Activity is below:
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);
}
}
}
The results of adb shell logcat from the time of starting the app to just after touching 'Force close' are below.
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
is not a valid activity action. You probably want to drop the s
.
html://www.google.com
is not a valid URL. You probably want to replace the html://
with http://
.
这篇关于为什么我会不断得到ActivityNotFound异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!