Android : Newbie Android 4.4 Hello Word App Crash Issue

on Sunday, July 6, 2014


Android newb here. Writing my first hello world app and can't get past two "Unfortunately" errors and a crash. I am going to guess it's a null pointer exception, but no amount of Googling makes me understand it any better. Thank you so much in advance.


AndroidManifest.xml



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eventexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.eventexample.EventExampleActivity"
android:label="@string/app_name" >

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


EventExampleActivity.java



package com.example.eventexample;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.TextView;

public class EventExampleActivity extends Activity {
@Override
protected void onStart()
{
super.onStart();

Button button =
(Button)findViewById(R.id.myButton);

button.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
TextView myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText("Button clicked");
}
}
);
}
}

activity_event_example.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".EventExampleActivity" >

<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/mybutton_string" />

<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/myButton"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="@string/mytextview_string"
android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>


Console Dump



[2014-07-06 21:35:36 - EventExample] ------------------------------
[2014-07-06 21:35:36 - EventExample] Android Launch!
[2014-07-06 21:35:36 - EventExample] adb is running normally.
[2014-07-06 21:35:36 - EventExample] Performing com.example.eventexample.EventExampleActivity activity launch
[2014-07-06 21:35:38 - EventExample] Application already deployed. No need to reinstall.
[2014-07-06 21:35:38 - EventExample] Starting activity com.example.eventexample.EventExampleActivity on device 192.168.56.101:5555
[2014-07-06 21:35:38 - EventExample] ActivityManager: WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
[2014-07-06 21:35:39 - EventExample] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.eventexample/.EventExampleActivity }


LogCat dump



07-07 02:35:38.276: E/AndroidRuntime(1681): FATAL EXCEPTION: main
07-07 02:35:38.276: E/AndroidRuntime(1681): Process: com.example.eventexample, PID: 1681
07-07 02:35:38.276: E/AndroidRuntime(1681): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.eventexample/com.example.eventexample.EventExampleActivity}: java.lang.NullPointerException
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.os.Handler.dispatchMessage(Handler.java:102)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.os.Looper.loop(Looper.java:136)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-07 02:35:38.276: E/AndroidRuntime(1681): at java.lang.reflect.Method.invokeNative(Native Method)
07-07 02:35:38.276: E/AndroidRuntime(1681): at java.lang.reflect.Method.invoke(Method.java:515)
07-07 02:35:38.276: E/AndroidRuntime(1681): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-07 02:35:38.276: E/AndroidRuntime(1681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-07 02:35:38.276: E/AndroidRuntime(1681): at dalvik.system.NativeStart.main(Native Method)
07-07 02:35:38.276: E/AndroidRuntime(1681): Caused by: java.lang.NullPointerException
07-07 02:35:38.276: E/AndroidRuntime(1681): at com.example.eventexample.EventExampleActivity.onStart(EventExampleActivity.java:25)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.Activity.performStart(Activity.java:5241)
07-07 02:35:38.276: E/AndroidRuntime(1681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
07-07 02:35:38.276: E/AndroidRuntime(1681): ... 11 more

0 comments:

Post a Comment