为什么我不断地得到ActivityNotFound例外? [英] Why do I constantly get ActivityNotFound exceptions?

查看:201
本文介绍了为什么我不断地得到ActivityNotFound例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手的Andr​​oid程序员,并帮助我了解如何意图真正的工作,我希望把一个小活动这将让用户调用startActivity()提供他们想要的任何操作和数据。我尝试了许多不同的组合,其中包括android.intent.action.VIEW和http://www.google.com。不管我用什么组合,我总是得到一个ActivityNotFoundException。任何想法,为什么?

在code。在我唯一的活动是如下:

 公共类TestingIntents扩展活动
{
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        按钮goButton =(按钮)findViewById(R.id.button);

        goButton.setOnClickListener(新ClickListener());
    }

    私有类ClickListener实现OnClickListener
    {
        @覆盖
        公共无效的onClick(查看arg0中)
        {
            字符串ID =((的EditText)findViewById(R.id.intent))的getText()的toString()。
            字符串数据=((的EditText)findViewById(R.id.data))的getText()的toString()。

            建设者建设者=新生成器();
            建设者= builder.path(数据);

            URI路径= builder.build();

            意图I =新的意图(ID,路径);
            startActivity(ⅰ);
        }
    }
}
 

亚行壳的logcat刚刚接触强制关闭后,结果从开始应用到的时间如下。

  I / ActivityManager(1086):
 启动活动:意向{行为= android.intent.action。
主要猫= [android.intent.category.LAUNCHER] FLG = 0x10200000 CMP = tk.h2g2guy.testin
gIntents / .TestingIntents}
I / ActivityManager(1086):开始PROC tk.h2g2guy.testingIntents的活动tk.h
2g2guy.testingIntents / .TestingIntents:PID = 4037的uid = 10054导报= {}
D / dalvikvm(1006):GC_EXPLICIT释放289对象/ 10960字节98ms
D / dalvikvm(1006):GC_EXPLICIT释放47的对象/ 2088字节121ms
D / dalvikvm(1006):GC_EXPLICIT释放2个对象/ 48字节109ms
I / ActivityManager(1086):显示活动tk.h2g2guy.testingIntents / .TestingI
ntents:462毫秒(总462毫秒)
D / dalvikvm(2300):GC_EXPLICIT释放1226对象/在69ms 61640字节
I / ActivityManager(1086):启动活动:意向{行为= android.intent.action。
查看DAT =的http%3A // www.google.com}
D / AndroidRuntime(4037):关闭虚拟机
W / dalvikvm(4037):主题ID = 1:螺纹退出与未捕获的异常(组=为0x4
001d7e0)
E / AndroidRuntime(4037):致命异常:主要
E / AndroidRuntime(4037):android.content.ActivityNotFoundException:无活动
发现处理意向{行为= 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):在android.app.Activity.startActivityForResult(A
ctivity.java:2817)
E / AndroidRuntime(4037):在android.app.Activity.startActivity(Activity.j
AVA:2923)
E / AndroidRuntime(4037):在tk.h2g2guy.testingIntents.TestingIntents $社区法网
kListener.onClick(TestingIntents.java:41)
E / AndroidRuntime(4037):在android.view.View.performClick(View.java:2408
)
E / AndroidRuntime(4037):在android.view.View $ PerformClick.run(View.java:
8816)
E / AndroidRuntime(4037):在android.os.Handler.handleCallback(Handler.jav
答:587)
E / AndroidRuntime(4037):在android.os.Handler.dispatchMessage(Handler.ja
VA:92)
E / AndroidRuntime(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(母语
方法)
E / AndroidRuntime(4037):在java.lang.reflect.Method.invoke(Method.java:5
21)
E / AndroidRuntime(4037):在com.android.internal.os.ZygoteInit $ MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E / AndroidRuntime(4037):在com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E / AndroidRuntime(4037):在dalvik.system.NativeStart.main(本机方法)

W / ActivityManager(1086):强制完成活动tk.h2g2guy.testingIntents /。
TestingIntents
W / ActivityManager(1086):活动暂停超时HistoryRecord {449d4518 tk.h
2g2guy.testingIntents / .TestingIntents}
I /过程(4037):发送信号。 PID:4037 SIG:9
I / ActivityManager(1086):过程tk.h2g2guy.testingIntents(PID 4037)已死亡。

I /窗口管理器(1086):WIN死亡:窗口{44bd4120 tk.h2g2guy.testingIntents / TK。
h2g2guy.testingIntents.TestingIntents暂停= FALSE}
 

解决方案
  

我尝试了许多不同的组合,   包含   android.intents.action.VIEW和   HTML://www.google.com。

android.intents.action.VIEW 不是一个有效的活动操作。你可能想删除取值

HTML://www.google.com 不是一个有效的URL。你可能想替换 HTML:以// 的http://

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆