当前位置: 首页 > 知识库问答 >
问题:

Android应用程序不工作

季嘉良
2023-03-14

我一直在尝试运行我的客户端/服务器android程序。但是每当我在android上运行客户端部分时,它都会出错不幸的是,您的应用程序已停止运行。我尝试过阅读logcat,但无法解决问题。下面是我的代码...我从3天开始一直在尝试。需要项目帮助

logcat公司

12-06 21:05:19.948: D/AndroidRuntime(2136): Shutting down VM
12-06 21:05:19.948: W/dalvikvm(2136): threadid=1: thread exiting with uncaught exception (group=0xa4cf8b20)
12-06 21:05:19.980: E/AndroidRuntime(2136): FATAL EXCEPTION: main
12-06 21:05:19.980: E/AndroidRuntime(2136): Process: com.example.simpleclientapp, PID: 2136
12-06 21:05:19.980: E/AndroidRuntime(2136): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.simpleclientapp/com.example.simpleclientapp.New_main_activity}: android.view.InflateException: Binary XML file line #1: Error inflating class linearlayout
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.os.Handler.dispatchMessage(Handler.java:102)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.os.Looper.loop(Looper.java:136)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.ActivityThread.main(ActivityThread.java:5001)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at java.lang.reflect.Method.invokeNative(Native Method)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at java.lang.reflect.Method.invoke(Method.java:515)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at dalvik.system.NativeStart.main(Native Method)
12-06 21:05:19.980: E/AndroidRuntime(2136): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class linearlayout
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.Activity.setContentView(Activity.java:1929)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at com.example.simpleclientapp.New_main_activity.onCreate(New_main_activity.java:33)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.Activity.performCreate(Activity.java:5231)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
12-06 21:05:19.980: E/AndroidRuntime(2136):     ... 11 more
12-06 21:05:19.980: E/AndroidRuntime(2136): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.linearlayout" on path: DexPathList[[zip file "/data/app/com.example.simpleclientapp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.simpleclientapp-2, /system/lib]]
12-06 21:05:19.980: E/AndroidRuntime(2136):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
12-06 21:05:19.980: E/AndroidRuntime(2136):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
12-06 21:05:19.980: E/AndroidRuntime(2136):     ... 20 more`

activity\u new\u main\u活动。xml

   <linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">

    <textview android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge">

    <button android:id="@+id/button1" android:layout_gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Send">


</button></textview></linearlayout>

manifest.xml

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" >
    </uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".New_main_activity"
            android:label="@string/title_activity_new_main_activity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

新建_main_活动。Java语言

package com.example.simpleclientapp;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.lang.*;
import java.lang.annotation.*;
import java.lang.ref.*;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class New_main_activity extends Activity
{
    private Socket client;
    private FileInputStream fileInputStream;
    private BufferedInputStream bufferedInputStream;
    private OutputStream outputStream;
    private Button button;
    private TextView text;

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

    button = (Button) findViewById(R.id.button1);   //reference to the send button
    text = (TextView) findViewById(R.id.textView1);   //reference to the text view

  //Button press event listener
    button.setOnClickListener(new View.OnClickListener() 
    {

        public void onClick(View v)
        {


            File file = new File("/mnt/shared/sharedwithemulatot/numbers.txt"); //create file instance

            try 
            {    
                client = new Socket("127.0.0.1", 6443);

                byte[] mybytearray = new byte[(int) file.length()]; //create a byte array to file

                fileInputStream = new FileInputStream(file);
                bufferedInputStream = new BufferedInputStream(fileInputStream);  

                bufferedInputStream.read(mybytearray, 0, mybytearray.length); //read the file

                outputStream = client.getOutputStream();

                outputStream.write(mybytearray, 0, mybytearray.length); //write file to the output stream byte by byte
                outputStream.flush();
                bufferedInputStream.close();
                outputStream.close();
                client.close();

                text.setText("File Sent");


    } catch (UnknownHostException e) {
     e.printStackTrace();
    } catch (IOException e) {
     e.printStackTrace();
    }


   }
  });

 }
}

共有1个答案

司徒锐进
2023-03-14

在布局文件中,似乎有一个<代码>

更新:原来的问题有布局文件,但由于格式问题,我错过了它们。正如Squonk所指出的,所有元素都需要在适当的情况下。

 类似资料:
  • 演示网站:http://recipe-app.com/recipe/grilled-potato-salad演示应用:http://search-codelabs.appspot.com/codelabs/android-deep-linking 我的测试: 我已经从上面的链接安装了演示应用程序。我用谷歌搜索应用程序搜索了“烤土豆沙拉”,结果发现http://recipe-app.com/reci

  • 我正在创建自己的应用程序。我在AndroidLollipop和Marshmallow上测试了它-一切都很好。但每当我尝试Android Kitkat时,就会发生错误。以下是错误日志: 看起来问题出在“progi”类的第62行,但是——对我来说——一切都很好,尤其是在新的Android版本上运行得很好。 如果有人问“Tabilica从意图中得到了什么?” 任何想法是什么问题?

  • 我用WebView创建了Android应用程序。当尝试用谷歌登录时,它首先询问用户名和密码,然后屏幕显示‘请关闭此窗口’的信息&什么也没有发生。 用户也未登录。 附注。这对我的移动网站来说是非常好的,它本身就被移植到了Android Webview应用程序上。有人能说出为什么那不起作用吗?我对Android是完全陌生的。

  • 在过去的几周里,我花了太多的时间试图让它发挥作用。我的目标是使用烧瓶框架创建一个简单的网络应用程序,但我不断收到错误,几个小时的谷歌搜索和搜索stackoverflow也没有帮助。 我正在学习一个教程,该教程要求我运行:$python3 routes.py 只有我才能得到以下错误: 回溯(最近的最后一次调用):文件“routes.py”,第1行,从flask导入flask中,呈现\u模板导入错误: