Results 1 to 3 of 3

Thread: Socket program compile error

Hybrid View

  1. #1
    Becoming more Chatty
    Join Date
    Jul 2011
    Location
    Midrand
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    8

    Socket program compile error

    I am failing to understand why I am not able to compile the following program. Someone please help.
    Code:
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.net.Socket;
    import java.net.UnknownHostException;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class AndroidClient extends Activity {
    
    EditText textOut;
    TextView textIn;
    
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
      
         textOut = (EditText)findViewById(R.id.textout);
         Button buttonSend = (Button)findViewById(R.id.send);
         textIn = (TextView)findViewById(R.id.textin);
         buttonSend.setOnClickListener(buttonSendOnClickListener);
     }
    
     Button.OnClickListener buttonSendOnClickListener
     = new Button.OnClickListener(){
    
    @Override
    public void onClick(View arg0) {
     // TODO Auto-generated method stub
     Socket socket = null;
     DataOutputStream dataOutputStream = null;
     DataInputStream dataInputStream = null;
    
     try {
      socket = new Socket("192.168.1.101", 8888);
      dataOutputStream = new DataOutputStream(socket.getOutputStream());
      dataInputStream = new DataInputStream(socket.getInputStream());
      dataOutputStream.writeUTF(textOut.getText().toString());
      textIn.setText(dataInputStream.readUTF());
     } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
     finally{
      if (socket != null){
       try {
        socket.close();
       } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
      }
    
      if (dataOutputStream != null){
       try {
        dataOutputStream.close();
       } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
      }
    
      if (dataInputStream != null){
       try {
        dataInputStream.close();
       } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
      }
     }
    }};
    }
    the main.xml look like
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
    <TextView
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="@+string/hello"
     />
    <EditText
     android:id="@+id/textout"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     />
    <Button
     android:id="@+id/send"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="Send"
     />
    <TextView
     android:id="@+id/textin"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     />
    </LinearLayout>
    and the string.xml look like
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">Main</string>
    </resources>
    and the result of the compile is
    alf@ThinkPad-T500:~/Development/android/AndroidClient$ ant debug
    Buildfile: /home/alf/Development/android/AndroidClient/build.xml
    [setup] Android SDK Tools Revision 10
    [setup] Project Target: Android 2.1-update1
    [setup] API level: 7
    [setup]
    [setup] ------------------
    [setup] Resolving library dependencies:
    [setup] No library dependencies.
    [setup]
    [setup] ------------------
    [setup]
    [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
    [setup]
    [setup] Importing rules file: tools/ant/main_rules.xml

    -debug-obfuscation-check:

    -set-debug-mode:

    -compile-tested-if-test:

    -pre-build:

    -dirs:
    [echo] Creating output directories if needed...

    -aidl:
    [echo] Compiling aidl files into Java classes...

    -renderscript:
    [echo] Compiling RenderScript files into Java classes and RenderScript bytecode...

    -resource-src:
    [echo] Generating R.java / Manifest.java from the resources...

    -pre-compile:

    compile:
    [javac] /home/alf/Development/android/android-sdk-linux_x86/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 2 source files to /home/alf/Development/android/AndroidClient/bin/classes
    [javac] /home/alf/Development/android/AndroidClient/src/za/co/stockton/AndroidClient/AndroidClient.java:23: package R does not exist
    [javac] setContentView(R.layout.main);
    [javac] ^
    [javac] /home/alf/Development/android/AndroidClient/src/za/co/stockton/AndroidClient/AndroidClient.java:25: package R does not exist
    [javac] textOut = (EditText)findViewById(R.id.textout);
    [javac] ^
    [javac] /home/alf/Development/android/AndroidClient/src/za/co/stockton/AndroidClient/AndroidClient.java:26: package R does not exist
    [javac] Button buttonSend = (Button)findViewById(R.id.send);
    [javac] ^
    [javac] /home/alf/Development/android/AndroidClient/src/za/co/stockton/AndroidClient/AndroidClient.java:27: package R does not exist
    [javac] textIn = (TextView)findViewById(R.id.textin);
    [javac] ^
    [javac] 4 errors

    BUILD FAILED
    /home/alf/Development/android/android-sdk-linux_x86/tools/ant/main_rules.xml:384: Compile failed; see the compiler error output for details.

    Total time: 1 second

  2. #2
    Administrator
    Join Date
    Apr 2010
    Location
    Midrand
    Posts
    564
    Thanks
    1
    Thanked 25 Times in 16 Posts
    Rep Power
    16
    You didn't import the generated R class. Go to the class code and press Ctrl+Shift+O to import the required class, if you are using Eclipse. If not, you should be using it to avoid wasting time on errors like these, as it will be immediately highlighted.

    Sent from my GT-P1010 using Tapatalk
    Web: http://tobykurien.com
    Twitter: @tobykurien
    Hire me for Android development: http://tobykurien.com/android-development-south-africa/

  3. #3
    Becoming more Chatty
    Join Date
    Jul 2011
    Location
    Midrand
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    8
    Pity but I am not using Eclipse but rather working from the command line.

Similar Threads

  1. 3D sketch type program for Android wanted
    By jors in forum General Discussions
    Replies: 3
    Last Post: 12-05-2011, 19:14

Visitors found this page by searching for:

error r.id.textout

compile error close socket

r.id.textout error

package r does not exist command line

socket programming in java socket cli=new socket(arg[0] 1010)

programimi me socket

package r does not exist [javac] setcontentview(r.layout.main);

ant debug package r does not exist

package za.co does not exist

android compile sockets

eclipse android dataoutputstream post variables php

package r does not existsetcontentview(r.layout.main);

android findviewbyid package r does not exist

ant eclipse package r setcontentview does not exists

android eeepc datainputstream

android socket program

GT p1010 twlauncher error

renderscript socket io

ant javac android package r does not exist setcontentview(r.layout.main);

error eclipse r.layout.activity no exist

out = (TextView) findViewById(R.id.out); symbol: variable id location: class R 1 error

ant and android error r.id does not exists

android package r does not exist command line

findviewbyid(r.id.button send); ^ symbol: variable buttonsend

package r does not exist ant debug

SEO Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •