0

我是android应用程序开发的新手。我正在尝试将演示 android 应用程序链接到托管在 apache tomcat 服务器上的 java servlet。

我相应地遵循了教程的步骤,但是我似乎无法让我的 android 应用程序正常运行。当我在模拟器上启动它时它一直停止

我已按照本教程 http://veereshr.com/Android/AndroidToServlet中的说明进行操作

以下是来自 logcat 的日志、我的 Android 清单文件和源代码

DoubleMeActivity.java

public class DoubleMeActivity extends Activity implements OnClickListener {

EditText inputValue=null;
Integer doubledValue =0;
Button doubleMe;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_double_me);

    inputValue = (EditText) findViewById(R.id.inputNum);
    doubleMe = (Button) findViewById(R.id.doubleme);

    doubleMe.setOnClickListener(this);
}

@Override
public void onClick(View v) {

    switch (v.getId()){
    case R.id.doubleme:

          new Thread(new Runnable() {
                public void run() {

                    try{
                        URL url = new URL("http://localhost:8000/MyServletProject/DoubleMeServlet");
                        URLConnection connection = url.openConnection();

                        String inputString = inputValue.getText().toString();
                        //inputString = URLEncoder.encode(inputString, "UTF-8");

                        Log.d("inputString", inputString);

                        connection.setDoOutput(true);
                        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
                        out.write(inputString);
                        out.close();

                        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

                        String returnString="";
                        doubledValue =0;

                        while ((returnString = in.readLine()) != null) 
                        {
                            doubledValue= Integer.parseInt(returnString);
                        }
                        in.close();


                        runOnUiThread(new Runnable() {
                             public void run() {

                                 inputValue.setText(doubledValue.toString());

                            }
                        });

                        }catch(Exception e)
                        {
                            Log.d("Exception",e.toString());
                        }

                }
              }).start();

        break;
        }
    }

}

日志猫

07-09 11:42:28.967: E/AndroidRuntime(713):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-09 11:42:28.967: E/AndroidRuntime(713):  at dalvik.system.NativeStart.main(Native Method)
07-09 11:42:28.967: E/AndroidRuntime(713): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class linearlayout
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-09 11:42:28.967: E/AndroidRuntime(713):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.app.Activity.setContentView(Activity.java:1867)
07-09 11:42:28.967: E/AndroidRuntime(713):  at com.app.myapp.DoubleMeActivity.onCreate(DoubleMeActivity.java:25)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.app.Activity.performCreate(Activity.java:5008)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
07-09 11:42:28.967: E/AndroidRuntime(713):  ... 11 more
07-09 11:42:28.967: E/AndroidRuntime(713): Caused by: java.lang.ClassNotFoundException: android.view.linearlayout
07-09 11:42:28.967: E/AndroidRuntime(713):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-09 11:42:28.967: E/AndroidRuntime(713):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-09 11:42:28.967: E/AndroidRuntime(713):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
07-09 11:42:28.967: E/AndroidRuntime(713):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-09 11:42:28.967: E/AndroidRuntime(713):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
07-09 11:42:28.967: E/AndroidRuntime(713):  ... 21 more
07-09 11:42:34.808: I/Process(713): Sending signal. PID: 713 SIG: 9
07-09 11:43:39.436: E/Trace(738): error opening trace file: No such file or directory (2)
07-09 11:43:40.356: D/AndroidRuntime(738): Shutting down VM
07-09 11:43:40.356: W/dalvikvm(738): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
07-09 11:43:40.376: E/AndroidRuntime(738): FATAL EXCEPTION: main
07-09 11:43:40.376: E/AndroidRuntime(738): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.myapp/com.app.myapp.DoubleMeActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class linearlayout
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.os.Looper.loop(Looper.java:137)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.ActivityThread.main(ActivityThread.java:4745)
07-09 11:43:40.376: E/AndroidRuntime(738):  at java.lang.reflect.Method.invokeNative(Native Method)
07-09 11:43:40.376: E/AndroidRuntime(738):  at java.lang.reflect.Method.invoke(Method.java:511)
07-09 11:43:40.376: E/AndroidRuntime(738):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-09 11:43:40.376: E/AndroidRuntime(738):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-09 11:43:40.376: E/AndroidRuntime(738):  at dalvik.system.NativeStart.main(Native Method)
07-09 11:43:40.376: E/AndroidRuntime(738): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class linearlayout
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-09 11:43:40.376: E/AndroidRuntime(738):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.Activity.setContentView(Activity.java:1867)
07-09 11:43:40.376: E/AndroidRuntime(738):  at com.app.myapp.DoubleMeActivity.onCreate(DoubleMeActivity.java:25)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.Activity.performCreate(Activity.java:5008)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
07-09 11:43:40.376: E/AndroidRuntime(738):  ... 11 more
07-09 11:43:40.376: E/AndroidRuntime(738): Caused by: java.lang.ClassNotFoundException: android.view.linearlayout
07-09 11:43:40.376: E/AndroidRuntime(738):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-09 11:43:40.376: E/AndroidRuntime(738):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-09 11:43:40.376: E/AndroidRuntime(738):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:643)
07-09 11:43:40.376: E/AndroidRuntime(738):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-09 11:43:40.376: E/AndroidRuntime(738):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
07-09 11:43:40.376: E/AndroidRuntime(738):  ... 21 more

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.app.myapp.DoubleMeActivity"
        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> </manifest>

很抱歉文字很长,我希望你们能帮助我解决这个问题。提前致谢!

4

2 回答 2

8

这是问题所在:

java.lang.ClassNotFoundException: android.view.linearlayout

XML 是区分大小写的。确保它在您的activity_double_me.xml文件中正确定义为:

<LinearLayout 

注意大写的“L”

于 2013-07-09T12:25:33.253 回答
1

您应该执行以下步骤:-

  1. 重启日食。
  2. 清理所有工作区,包括您的项目。
  3. 否则你需要创建一个新项目并复制这个新项目中的所有文件。它有时会起作用,因为由于系统配置较低,eclipse有时会卡住。
于 2013-07-09T12:31:42.640 回答