Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Android Application stopping a few moments after launching

pete mwangi:

My application a few moments after launching. Initially, the app used to run without problems, but after i added a login screen before the main screen, it frequently stops, with an error "Unfortunately AutoparesOnline has stopped. I'm new to android and i'd appreciate any help. below is the log and the AndroidManifest.xml








android:largeScreens="true"
android:normalScreens="true"
android:xlargeScreens="true" />

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:supportsRtl="true"
android:theme="@style/AppTheme">


android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:theme="@style/Theme.Design.Light.NoActionBar">







android:name=".AnotherActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.NoActionBar">


android:name=".SignupActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">


android:theme="@style/Theme.AppCompat.NoActionBar"
android:screenOrientation="portrait">


android:theme="@style/Theme.AppCompat.NoActionBar"
android:screenOrientation="portrait">


android:name=".BrakeActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/AppTheme">


android:name=".SteeringActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/AppTheme">


android:label="@string/app_name"
android:theme="@style/AppTheme"
android:screenOrientation="portrait">


android:theme="@style/AppTheme"
android:label="@string/app_name"
android:screenOrientation="portrait">


android:theme="@style/AppTheme"
android:label="@string/app_name"
android:screenOrientation="portrait">


android:label="@string/app_name"
android:theme="@style/AppTheme">



This is the java code


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;


public class MainActivity extends AppCompatActivity{

Button btn1;
private ProgressBar pBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);

btn1 = (Button)btn1.findViewById(R.id.btnStartMainActivity);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, AnotherActivity.class);
startActivity(intent);
}
});
pBar.setVisibility(View.VISIBLE);



}

Here is part of the error.


FATAL EXCEPTION: main
Process: co.autosparesonline.ke, PID: 3011
java.lang.RuntimeException: Unable to start activity ComponentInfo{http://ift.tt/2BIxH4T}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at co.autosparesonline.ke.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Android Application stopping a few moments after launching

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×