Android : Unable to start activity Component Info
<p>I've got a problem with my Android App.
I'm trying to communicate in a serial way between my Android-Device and my PC.
That for im using Android NDK.
As soon as i start to use methods using serialport s im getting the error message. either .getSerialPort() or .getOutputStream()</p>

<p>Of course i've allready tried to fix this problem via google.
But actually i didnt found a fix to my problem yet.
I checked if my manifest contains everything needed and im pretty sure it does.
Hopefully someone of you can find the problem in my code.</p>

<p>This is the first time im asking a question on stackoverflow, so i'm up for hints how to ask in a better way in the future.
If any informations are missing, tell me and i'll post them asap.</p>

<p>This is my mainactivity:</p>

<pre><code>package com.example.serialtest3;

import java.io.IOException;
import java.io.OutputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.serialtest3.SerialPort;

public class MainActivity extends Activity {

TextView tv;
EditText et;    
SerialPort s;

protected OutputStream out= new OutputStream() {

@Override
public void write(int oneByte) throws IOException {
}
};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    out = s.getOutputStream(); 
    try {
        s.getSerialPort();                        
    } catch (InvalidParameterException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (SecurityException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    Button b1 = (Button) findViewById(R.id.button1);
    b1.setOnClickListener(new View.OnClickListener() {


        public void onClick(View v) {

            String text = et.getText().toString();
            if (v.getId()==R.id.button1){
                try {
                out.write(new String(text).getBytes());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        }
    });

    et =(EditText) findViewById(R.id.editT);
}
</code></pre>

<p>SerialPort:</p>

<pre><code>package com.example.serialtest3;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidParameterException;
import android.util.Log;
import com.example.serialtest3.*;

public class SerialPort {

private static final String TAG = "SerialPort";
SerialPort serial;
/*
 * Do not remove or rename the field mFd: it is used by native method close();
 */
private FileDescriptor mFd;
private FileInputStream mFileInputStream;
private FileOutputStream mFileOutputStream;

public SerialPort(File device, int baudrate, int flags) throws SecurityException, IOException {

    /* Check access permission */
    if (!device.canRead() || !device.canWrite()) {
        try {
            /* Missing read/write permission, trying to chmod the file */
            Process su;
            su = Runtime.getRuntime().exec("/system/bin/su");
            String cmd = "chmod 666 " + device.getAbsolutePath() + "\n"
                    + "exit\n";
            su.getOutputStream().write(cmd.getBytes());
            if ((su.waitFor() != 0) || !device.canRead()
                    || !device.canWrite()) {
                throw new SecurityException();
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new SecurityException();
        }
    }

    mFd = open(device.getAbsolutePath(), baudrate, flags);
    if (mFd == null) {
        Log.e(TAG, "native open returns null");
        throw new IOException();
    }
    mFileInputStream = new FileInputStream(mFd);
    mFileOutputStream = new FileOutputStream(mFd);

}

public SerialPort getSerialPort() throws SecurityException, IOException, InvalidParameterException {
    String path = "/dev/ttyO0";
    int baudrate= 115200;
    serial = new SerialPort(new File(path), baudrate, 0);
    return serial;
}

// Getters and setters
public InputStream getInputStream() {
    return mFileInputStream;
}

public OutputStream getOutputStream() {
    return mFileOutputStream;
}

// JNI
private native static FileDescriptor open(String path, int baudrate, int flags);
public native void close();
static {
    System.loadLibrary("serial_port");  // this lib contains open and close method which are written in the c-code
}
</code></pre>

<p>}</p>

<p>android manifest:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.serialtest3"
android:versionCode="1"
android:versionName="1.0" &gt;

&lt;uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" /&gt;

&lt;application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" &gt;
    &lt;activity
        android:name="com.example.serialtest3.MainActivity"
        android:label="@string/app_name" &gt;
        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;

            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
&lt;/application&gt;
</code></pre>

<p></p>

<p>error messages:</p>

<pre><code>01-01 04:03:29.451: D/AndroidRuntime(2370): Shutting down VM
01-01 04:03:29.451: W/dalvikvm(2370): threadid=1: thread exiting with uncaught exception (group=0x40a421f8)
01-01 04:03:29.451: E/AndroidRuntime(2370): FATAL EXCEPTION: main
01-01 04:03:29.451: E/AndroidRuntime(2370): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.serialtest3/com.example.serialtest3.MainActivity}: java.lang.NullPointerException
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.os.Looper.loop(Looper.java:137)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.ActivityThread.main(ActivityThread.java:4424)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at java.lang.reflect.Method.invokeNative(Native Method)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at java.lang.reflect.Method.invoke(Method.java:511)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at dalvik.system.NativeStart.main(Native Method)
01-01 04:03:29.451: E/AndroidRuntime(2370): Caused by: java.lang.NullPointerException
01-01 04:03:29.451: E/AndroidRuntime(2370):     at com.example.serialtest3.MainActivity.onCreate(MainActivity.java:65)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.Activity.performCreate(Activity.java:4465)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-01 04:03:29.451: E/AndroidRuntime(2370):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-01 04:03:29.451: E/AndroidRuntime(2370):     ... 11 more
01-01 04:04:56.035: D/AndroidRuntime(2421): Shutting down VM
01-01 04:04:56.035: W/dalvikvm(2421): threadid=1: thread exiting with uncaught exception (group=0x40a421f8)
01-01 04:04:56.035: E/AndroidRuntime(2421): FATAL EXCEPTION: main
01-01 04:04:56.035: E/AndroidRuntime(2421): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.serialtest3/com.example.serialtest3.MainActivity}: java.lang.NullPointerException
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.os.Looper.loop(Looper.java:137)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.ActivityThread.main(ActivityThread.java:4424)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at java.lang.reflect.Method.invokeNative(Native Method)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at java.lang.reflect.Method.invoke(Method.java:511)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at dalvik.system.NativeStart.main(Native Method)
01-01 04:04:56.035: E/AndroidRuntime(2421): Caused by: java.lang.NullPointerException
01-01 04:04:56.035: E/AndroidRuntime(2421):     at com.example.serialtest3.MainActivity.onCreate(MainActivity.java:54)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.Activity.performCreate(Activity.java:4465)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-01 04:04:56.035: E/AndroidRuntime(2421):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-01 04:04:56.035: E/AndroidRuntime(2421):     ... 11 more
01-01 04:05:03.232: I/Process(2421): Sending signal. PID: 2421 SIG: 9
</code></pre>

<p>activity_main.xml:</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" &gt;


&lt;Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="155dp"
    android:text="Button" /&gt;

&lt;EditText
    android:id="@+id/editT"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="80dp"
    android:ems="10"
    android:lines="1" /&gt;
</code></pre>

<p></p>
