android - 如何从Android中的其他包中引用类?

标签 android

请问如何在Android中引用我的其他包中的其他类?

我有我的主包。在那之下它有几个子包。 如何将子包下的那些类引用到主包中的主类中?

我所做的是,在主类中,我通过 Intent 调用子包中的类。 到目前为止,这是我尝试过但无济于事的方法:

case 0:
        Intent acorn = new Intent( "com.fps.iHealthFirst.vegetables.AcornSquash.class" );
        //Intent acorn = new Intent( Nutritional_List.this, AcornSquash.class );
        startActivity( acorn );
        break;

我很难做到这一点。感谢您的帮助。

顺便说一句,这是 logcat:

10-22 23:13:03.585: E/AndroidRuntime(395): FATAL EXCEPTION: main
10-22 23:13:03.585: E/AndroidRuntime(395): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.fps.iHealthFirst/com.fps.iHealthFirst.vegetables.AcornSquash}; have you declared this activity in your AndroidManifest.xml?

另外,我在 list 文件中编辑了这个:

    <activity android:exported="false"
        android:name=".vegetables.AcornSquashAcornSquash"
        android:label="@string/inutrition" >
        <intent-filter >
        <action android:name="com.fps.iHealthFirst.vegetables.ACORNSQUASH" />
        </intent-filter>
    </activity>

最佳答案

这是你应该做的:

    import com.fps.iHealthFirst.vegetables.AcornSquash;

    Intent acorn = new Intent(this, AcornSquash.class);
    startActivity(acorn);

更新:

您必须在 Manifest.xml 中声明所有 Activity 。保持简单:

     <activity
        android:name="com.fps.iHealthFirst.vegetables.AcornSquash"
        android:label="@string/some_name" >
    </activity>

最后,确保您的文件夹结构与您的包路径一致,即您的文件 AcornSquash.java 必须位于 src/com/fps/iHealthFirst/vegetables/ 文件夹。

关于android - 如何从Android中的其他包中引用类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13014110/

相关文章:

android - Wifi漫游连接顺序

java - 使用导航切换到另一个 fragment 时保存 fragment 数据

java - 删除多行Edittext android中的下一行可见性

Android ViewPropertyAnimator 和 ValueAnimator : How can I do fast-forward?

android - 当Mediaplayer在Service Class中停止时,应用程序停止工作

java - 单击单选按钮时如何显示微调器

java - 为什么 UML 显示 Android Adapter 接口(interface)有一个 View 和一个 ViewGroup

android - 以编程方式在 android 4.2.1 上安装 USB 存储

javascript - preventDefault() 不会在 Android 上停止 mouseup 事件

android - Activity 生命周期中的小构象