0

I have been trying to run my client/server android program. But whenever I run the client part on android it gives an error Unfortunately your applicatiopn has stopped running. I have tried reading the logcat but havent been able to fix the problem. below is my code... I have been trying from 3 days. Need help with the project

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_new_main_activity.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>

new_main_activity.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();
    }


   }
  });

 }
}
ham-sandwich
  • 3,975
  • 10
  • 34
  • 46
san1234
  • 11
  • 6

1 Answers1

6

In a layout file, it appears that you have a <linearlayout> tag. Please use a <LinearLayout> tag instead. Case is important here.

UPDATE: The original question had the layout files, but I missed them due to the formatting. As Squonk notes, all elements need to be in proper case.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    @san1234 : Just because you fixed linearlayout by changing case to LinearLayout doesn't mean you've fixed your problem totally. Had it occured to you that button should be Button and textview should be TextView? Case-sensitivity applies to all widgets used in layout files as well as other XML files as it does with Java code files. – Squonk Dec 06 '14 at 21:46
  • @san1234: Then, by definition, you are crashing someplace else. Use LogCat to examine your **new** Java stack trace, and continue your debugging efforts. – CommonsWare Dec 06 '14 at 21:56
  • @san1234 : I just noticed this... `` - even if you changed case, that is wrong. The closing element of XML should be immediately after the main body of the element (unless nesting elements). You should put ` after the `` definition and attributes and `` after the `` *IS* allowed however as a `LinearLayout` is a `ViewGroup` and allows multiple widgets. – Squonk Dec 06 '14 at 22:01