没有插入整个项目代码如何从一个项目调用类到android中的另一个项目

时间:2013-01-28 05:41:29

标签: android

01-28 13:51:17.332: D/AndroidRuntime(766): Shutting down VM
01-28 13:51:17.332: W/dalvikvm(766): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-28 13:51:17.522: E/AndroidRuntime(766): FATAL EXCEPTION: main
01-28 13:51:17.522: E/AndroidRuntime(766): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.canadaqbank.usmle/com.canadaqbank.usmle.USMLEActivity}: java.lang.ClassNotFoundException: com.canadaqbank.usmle.USMLEActivity in loader dalvik.system.PathClassLoader[/data/app/com.canadaqbank.usmle-1.apk]
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.os.Looper.loop(Looper.java:123)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-28 13:51:17.522: E/AndroidRuntime(766):  at java.lang.reflect.Method.invokeNative(Native Method)
01-28 13:51:17.522: E/AndroidRuntime(766):  at java.lang.reflect.Method.invoke(Method.java:521)
01-28 13:51:17.522: E/AndroidRuntime(766):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-28 13:51:17.522: E/AndroidRuntime(766):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-28 13:51:17.522: E/AndroidRuntime(766):  at dalvik.system.NativeStart.main(Native Method)
01-28 13:51:17.522: E/AndroidRuntime(766): Caused by: java.lang.ClassNotFoundException: com.canadaqbank.usmle.USMLEActivity in loader dalvik.system.PathClassLoader[/data/app/com.canadaqbank.usmle-1.apk]
01-28 13:51:17.522: E/AndroidRuntime(766):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-28 13:51:17.522: E/AndroidRuntime(766):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-28 13:51:17.522: E/AndroidRuntime(766):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-28 13:51:17.522: E/AndroidRuntime(766):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-28 13:51:17.522: E/AndroidRuntime(766):  ... 11 more

我想将一个项目类调用到另一个项目而不保留此项目中的所有代码,我在构建路径中添加它并在清单文件中声明该类但是当我调用它时给了我{{1 }}

android.view.InflateException: Binary XML file line #8: Error inflating class . I am calling it from intent

更新: - 新的logcat错误

android.view.InflateException: Binary XML file line #8: Error inflating class com.bank.Header
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.os.Looper.loop(Looper.java:123)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-28 10:42:57.503: E/AndroidRuntime(309):  at java.lang.reflect.Method.invokeNative(Native Method)
01-28 10:42:57.503: E/AndroidRuntime(309):  at java.lang.reflect.Method.invoke(Method.java:521)
01-28 10:42:57.503: E/AndroidRuntime(309):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-28 10:42:57.503: E/AndroidRuntime(309):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-28 10:42:57.503: E/AndroidRuntime(309):  at dalvik.system.NativeStart.main(Native Method)
01-28 10:42:57.503: E/AndroidRuntime(309): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.bank.Header
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-28 10:42:57.503: E/AndroidRuntime(309):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.Activity.setContentView(Activity.java:1647)
01-28 10:42:57.503: E/AndroidRuntime(309):  at com.bank.us.USActivity.onCreate(USActivity.java:25)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-28 10:42:57.503: E/AndroidRuntime(309):  ... 11 more
01-28 10:42:57.503: E/AndroidRuntime(309): Caused by: java.lang.reflect.InvocationTargetException
01-28 10:42:57.503: E/AndroidRuntime(309):  at com.bank.Header.<init>(Header.java:223)
01-28 10:42:57.503: E/AndroidRuntime(309):  at java.lang.reflect.Constructor.constructNative(Native Method)
01-28 10:42:57.503: E/AndroidRuntime(309):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-28 10:42:57.503: E/AndroidRuntime(309):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
01-28 10:42:57.503: E/AndroidRuntime(309):  ... 21 more
01-28 10:42:57.503: E/AndroidRuntime(309): Caused by: java.lang.NullPointerException
01-28 10:42:57.503: E/AndroidRuntime(309):  ... 25 more

1 个答案:

答案 0 :(得分:0)

如果您正在开始另一个项目的活动,那么您可以这样做:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(
                "com.abc.def.packname",
                "com.abc.def.packname.MyActivity"));

startActivity(intent);