Android在引用/实现接口时崩溃

时间:2013-10-12 13:50:18

标签: java android

我是来自Java背景的Android新手。如果这是一个非常简单的解决方案,请原谅。我在java中创建了一个机器模拟器,我想在Android上使用简单的UI运行它。问题是,当我这样做时它会崩溃

 public class UITerminal extends EditText implements Terminal

我也在课堂上试过这个

 Terminal terminal;
 public void init()
 {
      terminal = new Terminal()
      {
         //implemented methods
      }
 }
这两种解决方案在打开时都崩溃了。关于我应该怎么做的任何建议?提前致谢。这是我的第一次Android体验。

修改

我点击该应用程序,它显示“不幸MyTronEmulator已停止工作”

10-12 09:27:58.187: I/dalvikvm(964): Failed resolving Ldavis/mytronemulator/UITerminal; interface 635 'Ldavis/lib/mytronemulator/Terminal;'
10-12 09:27:58.187: W/dalvikvm(964): Link of class 'Ldavis/mytronemulator/UITerminal;' failed
10-12 09:27:58.227: D/AndroidRuntime(964): Shutting down VM
10-12 09:27:58.227: W/dalvikvm(964): threadid=1: thread exiting with uncaught exception (group=0x41465700)
10-12 09:27:58.347: E/AndroidRuntime(964): FATAL EXCEPTION: main
10-12 09:27:58.347: E/AndroidRuntime(964): java.lang.RuntimeException: Unable to start activity ComponentInfo{davis.mytronemulator/davis.mytronemulator.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class davis.mytronemulator.UITerminal
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.os.Looper.loop(Looper.java:137)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.ActivityThread.main(ActivityThread.java:5103)
10-12 09:27:58.347: E/AndroidRuntime(964):  at java.lang.reflect.Method.invokeNative(Native Method)
10-12 09:27:58.347: E/AndroidRuntime(964):  at java.lang.reflect.Method.invoke(Method.java:525)
10-12 09:27:58.347: E/AndroidRuntime(964):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-12 09:27:58.347: E/AndroidRuntime(964):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-12 09:27:58.347: E/AndroidRuntime(964):  at dalvik.system.NativeStart.main(Native Method)
10-12 09:27:58.347: E/AndroidRuntime(964): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class davis.mytronemulator.UITerminal
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-12 09:27:58.347: E/AndroidRuntime(964):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.Activity.setContentView(Activity.java:1895)
10-12 09:27:58.347: E/AndroidRuntime(964):  at davis.mytronemulator.MainActivity.onCreate(MainActivity.java:13)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.Activity.performCreate(Activity.java:5133)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-12 09:27:58.347: E/AndroidRuntime(964):  ... 11 more
10-12 09:27:58.347: E/AndroidRuntime(964): Caused by: java.lang.ClassNotFoundException: Didn't find class "davis.mytronemulator.UITerminal" on path: DexPathList[[zip file "/data/app/davis.mytronemulator-2.apk"],nativeLibraryDirectories=[/data/app-lib/davis.mytronemulator-2, /system/lib]]
10-12 09:27:58.347: E/AndroidRuntime(964):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
10-12 09:27:58.347: E/AndroidRuntime(964):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-12 09:27:58.347: E/AndroidRuntime(964):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.view.LayoutInflater.createView(LayoutInflater.java:559)
10-12 09:27:58.347: E/AndroidRuntime(964):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
10-12 09:27:58.347: E/AndroidRuntime(964):  ... 21 more

2 个答案:

答案 0 :(得分:0)

除了将其添加为库之外,您还必须确保IDE正在导出.jar文件。否则,假设它已经在电话/模拟器上。

在eclipse中,您可以通过右键单击项目来确保完成此操作 - >构建路径 - >配置构建路径 - >订单和出口 - >检查图书馆。

答案 1 :(得分:0)

这是一段时间了,但我试图使用Java 1.7 lib。 Android仅支持1.6 我希望错误只会说:)