0

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

 public class UITerminal extends EditText implements Terminal

我也在课堂上试过这个

 Terminal terminal;
 public void init()
 {
      terminal = new Terminal()
      {
         //implemented methods
      }
 }

这两种解决方案在打开时都崩溃了。关于我应该如何做到这一点的任何建议?提前致谢。这是我的第一次安卓体验。

编辑

我点击该应用程序,它显示“不幸的是 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
4

2 回答 2

0

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

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

于 2013-10-12T14:03:53.943 回答
0

这是前一阵子,但我试图使用 Java 1.7 库。Android 只支持最高 1.6 我希望错误只是说:)

于 2013-12-15T05:42:26.363 回答