unhandles exception

Put your problem here if it does not fit any of the other categories.

unhandles exception

Postby Kubax » Tue May 19, 2009 1:37 pm

Hi there,

i'm trying to create a litle Porgram that connects to an TCP Port and Sends Text.

The Text sending works fine after some testing with the TCPClient of this Forum.

Now i'm trying to not let the application connect and send on startup, but on Button click.
So I Added a Button (ImageButton) and tried copying code from AmarokRemote to my Application and change it to fit my application.

But after starting the Aplication my LogCat gives me this:

Code: Select all
05-19 12:31:07.942: ERROR/AndroidRuntime(1291): Uncaught handler: thread main exiting due to uncaught exception
05-19 12:31:07.962: ERROR/AndroidRuntime(1291): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.e2esp.socket.test/com.e2esp.socket.test.SocketTest}: java.lang.NullPointerException
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.os.Looper.loop(Looper.java:123)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.app.ActivityThread.main(ActivityThread.java:3948)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at java.lang.reflect.Method.invokeNative(Native Method)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at java.lang.reflect.Method.invoke(Method.java:521)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at dalvik.system.NativeStart.main(Native Method)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291): Caused by: java.lang.NullPointerException
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at com.e2esp.socket.test.SocketTest.onCreate(SocketTest.java:30)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
05-19 12:31:07.962: ERROR/AndroidRuntime(1291):     ... 11 more


Here is my Code...

SocketTest.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.e2esp.socket.test;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.view.View;
  10.  
  11. import android.view.View.OnClickListener;
  12.  
  13. import android.widget.ImageButton;
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. public class SocketTest extends Activity {
  22.  
  23.     /** Called when the activity is first created. */
  24.  
  25.     //@Override
  26.  
  27.    
  28.  
  29.         public ImageButton Button;
  30.  
  31.  
  32.  
  33.     public void onCreate(Bundle icicle) {
  34.  
  35.         super.onCreate(icicle);
  36.  
  37.         setContentView(R.layout.main);
  38.  
  39.        
  40.  
  41.         //Thread sThread = new Thread(new TCPServer());
  42.  
  43.        
  44.  
  45.        
  46.  
  47.         /*sThread.start();
  48.  
  49.         try {
  50.  
  51.                Thread.sleep(1000);
  52.  
  53.           } catch (InterruptedException e) { }
  54.  
  55.        */
  56.  
  57.        
  58.  
  59.         this.Button.setOnClickListener(new OnClickListener() {
  60.  
  61.                         //@Override
  62.  
  63.                         public void onClick(View v) {
  64.  
  65.                                 Thread cThread = new Thread(new TCPClient());
  66.  
  67.                                 cThread.start();
  68.  
  69.                                
  70.  
  71.                         }
  72.  
  73.         });
  74.  
  75.          
  76.  
  77.     }
  78.  
  79. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


AndroidManifest.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  
  4.  
  5. <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
  6.  
  7. <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button"></ImageButton>
  8.  
  9. </LinearLayout>
  10.  
  11.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


don't know what to do now ^^

P.s.: Yeah, it's my first time in Java AND Android programming...
Kubax
Freshman
Freshman
 
Posts: 2
Joined: Tue May 19, 2009 11:39 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 24 guests