Issue
I'm a newbie to android developing so please bear with me and help me to solve this problem thanx so much in advance..
When i run my app on emulator splash screen is working properly but right after that when next layout should displayed pops up a message "Application Stopped Unexpectedly" Every time i run the app same result splash works perfectly but right after that the error message.
I deleted & recreated AVD, cleaned the project,restarted the eclipse,machine but nothing....
additional info if it helps
At 1st I created project targeting Google API 14 & min SDK 8 but i had trouble with running the emulator it got stuck with only a black screen so later recreated AVD and changed target SDK to Google API 8 (projrct->properties->Android->Google API 8->apply->ok) and with min SDK 4.
This is MainActivity (splash screen)
package com.example.GPS;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kclogo);
MediaPlayer mpsplash = MediaPlayer.create(this, R.raw.startup_tone);
mpsplash.start();
Thread logoTimer=new Thread()
{
public void run()
{
try
{
int logoTimer=0;
while(logoTimer<3499)
{
sleep(100);
logoTimer= logoTimer +100;
}
startActivity(new Intent("com.example.GPS.KCLOGO"));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
finish();
}
}
};
logoTimer.start();
}
}
This is MenuActivity
package com.example.GPS;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MenuActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
final MediaPlayer mpButtonClick = MediaPlayer.create(this,R.raw.buttonclick);
Button btn1 = (Button) findViewById(R.id.btnlogin);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.GPS.LOGIN"));
mpButtonClick.start();
}
});
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.GPS"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.GPS.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.GPS.MenuActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.GPS.KCLOGO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
//sorry didn't include it to the question at first
<activity
android:name="com.example.GPS.LoginActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.GPS.LOGIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
LogCat
02-27 22:29:14.031:E/AndroidRuntime(307): FATAL EXCEPTION: main
02-27 22:29:14.031:E/AndroidRuntime(307): java.lang.**RuntimeException**:Unable to start activity ComponentInfo{com.example.GPS/com.example.GPS.MenuActivity}: java.lang.**NullPointerException**
02-27 22:29:14.031:E/AndroidRuntime(307):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.os.Looper.loop(Looper.java:123)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.app.ActivityThread.main(ActivityThread.java:4627)
02-27 22:29:14.031:E/AndroidRuntime(307):at java.lang.reflect.Method.invokeNative(Native Method)
02-27 22:29:14.031:E/AndroidRuntime(307):at java.lang.reflect.Method.invoke(Method.java:521)
02-27 22:29:14.031:E/AndroidRuntime(307):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-27 22:29:14.031:E/AndroidRuntime(307):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-27 22:29:14.031:E/AndroidRuntime(307):at dalvik.system.NativeStart.main(Native Method)
02-27 22:29:14.031:E/AndroidRuntime(307): Caused by: java.lang.**NullPointerException**
02-27 22:29:14.031:E/AndroidRuntime(307):at com.example.GPS.MenuActivity.onCreate(MenuActivity.java:21)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.app.Instrumentation.**callActivityOnCreate**(Instrumentation.java:1047)
02-27 22:29:14.031:E/AndroidRuntime(307):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
console
[2013-02-27 22:28:25 - GPSTracker] Android Launch!
[2013-02-27 22:28:25 - GPSTracker] adb is running normally.
[2013-02-27 22:28:25 - GPSTracker] Performing com.example.GPS.MainActivity activity launch
[2013-02-27 22:28:25 - GPSTracker] Automatic Target Mode: launching new emulator with compatible AVD 'GMD'
[2013-02-27 22:28:25 - GPSTracker] Launching a new emulator with Virtual Device 'GMD'
[2013-02-27 22:28:27 - GPSTracker] New emulator found: emulator-5554
[2013-02-27 22:28:27 - GPSTracker] Waiting for HOME ('android.process.acore') to be launched...
[2013-02-27 22:28:50 - GPSTracker] HOME is up on device 'emulator-5554'
[2013-02-27 22:28:50 - GPSTracker] Uploading GPSTracker.apk onto device 'emulator-5554'
[2013-02-27 22:28:52 - GPSTracker] Installing GPSTracker.apk...
[2013-02-27 22:29:07 - GPSTracker] Success!
[2013-02-27 22:29:07 - GPSTracker] Starting activity com.example.GPS.MainActivity on device emulator-5554
[2013-02-27 22:29:08 - GPSTracker] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.GPS/.MainActivity }
login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/layoutbg" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.45" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/login_pic" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/tvuserid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="User ID"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etuserid"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:ems="10"
android:background="@drawable/gradiant" >
<requestFocus />
</EditText>
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/tvpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etpass"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.42"
android:ems="10"
android:inputType="textPassword"
android:background="@drawable/gradiant" />
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp" >
<Button
android:id="@+id/btnlogin"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_weight="1"
android:drawableLeft="@drawable/padlock"
android:text="Login" />
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="150dp"
android:layout_weight="0.04"
android:src="@drawable/exclamation" />
<Button
android:id="@+id/btnsignup"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginRight="25dp"
android:layout_weight="0.33"
android:background="@color/layoutbg"
android:text="Sign Up"
android:textSize="16dp" />
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>
kclogo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/layoutbg">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:src="@drawable/kclogo" />
</LinearLayout>
menu.xml
<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:gravity="center_horizontal"
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"
android:background="@color/layoutbg" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/gpscollage" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_below="@+id/imageView1"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<Button
android:id="@+id/loginsignup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:drawableLeft="@drawable/thumb_up_icon"
android:text="Login/Sign Up" />
<Button
android:id="@+id/addnewtomap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:drawableLeft="@drawable/add_to_map"
android:text="Add Member/s To Map" />
<Button
android:id="@+id/addnewtocontacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/add_contact_list"
android:text="Add To Contact List" />
</LinearLayout>
</RelativeLayout>
Solution
Make sure Button btnlogin
exists in your layout xml.
The layout you're using in the MenuActivity is main.xml, and you're looking in main.xml for btnlogin, which doesnt exist. btn1 is null because it doesnt exist in the layout.
Answered By - John Boker
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.