【问题标题】:Android Activitynotfound error?Android Activitynotfound 错误?
【发布时间】:2011-07-13 02:41:39
【问题描述】:

我正在尝试在我的 android 模拟器 (2.3.3) 上创建一个 pdf 打开器,但是每次我运行它时它都会返回一个 Activitynotfound 异常。我检查了包名和类名,它是正确的。我对 Android 开发也很陌生。这是代码!

公共类 PdfViewerActivity 扩展 Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView tv = new TextView(this);


    File file = new File("mnt/sdcard/proposal.pdf");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri path2 = Uri.fromFile(file);
    intent.setDataAndType(path2, "application/pdf");    

    try 
    { 
         startActivity(intent);
    } 
    catch(ActivityNotFoundException e ) 
    { 
        tv.setText("What the hell is going on O_O" + "\n" + e);
        setContentView(tv);  
    } 


}

}

===========

清单

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".PdfViewerActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

【问题讨论】:

    标签: java android exception android-activity


    【解决方案1】:

    您的手机上没有安装 PDF 查看器应用程序。这就是这里的启动活动代码失败的原因。 PDF 打开器到底是什么意思?

    【讨论】:

      【解决方案2】:

      当您启动 ACTION_VIEW 的 Intent 时,是否有“捕捉”它的 Activity?

      【讨论】:

      • 我很抱歉我是新手。 “抓住它”是什么意思?我所有的代码都在 qn 上,所以如果它不在那里,我可能没有;没有
      • 道歉,我可能措辞不正确。当您进行 startActivity(intent) 调用时,您将根据您的意图中的任何请求启动一个新活动。您希望从通话开始什么活动?您的手机/模拟器中是否已经有一个可以满足查看 PDF 的应用程序?
      • 不,我需要打开存储在 sdcard 中的 pdf 文件。这不就是打开方式吗?我知道 android 无法原生打开 .pdf 文件
      • 没错。您的 SD 卡中有 PDF 文件,但您的操作系统中没有打开 PDF 文件的应用程序。就像您有一台没有 Adob​​e Reader 或任何 PDF 查看器(包括浏览器)的 PC,然后您尝试打开一个文件。它给你一个弹出窗口说它不知道使用什么程序对吗?在您的应用程序中,您会收到未找到活动异常,因为您的手机中目前没有可以打开 PDF 文件的应用程序。希望这能解释它并祝你好运!
      【解决方案3】:

      您正在使用模拟器阅读 PDF,阅读 PDF 的方式是 Intent.ACTION_VIEW 为此,您需要在模拟器中安装一个 Pdf 阅读应用程序。

      如果你想阅读 Pdf,你可以通过其他方式阅读

      Android - Load PDF / PDF Viewer

      您也可以制作自己的 PDF 查看器

      【讨论】:

      • Thnx,我需要什么来制作我自己的 PDF 查看器?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      相关资源
      最近更新 更多