Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8306243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:17:34+00:00 2026-06-08T18:17:34+00:00

When i click on the button OK, it force closes. There is something wrong

  • 0

When i click on the button “OK”, it force closes. There is something wrong with the startActivity() function.When i click on the ok button, the app force closes and the LogCat throws the following errors enclosed. There is something wrong with the startactivity() method in MainActivity.java

MainActivity.java

package com.location.sensor;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
            Button btn=(Button) findViewById(R.id.btn_OK);
            Animation anim= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.jump);
            btn.startAnimation(anim);
            btn.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Animation anim= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.jump);
                    anim.setDuration(3000);
                    v.startAnimation(anim);
                    TextView n=new TextView(getBaseContext());
                    EditText txt=(EditText) findViewById(R.id.txt_username);
                    //Animation anim= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.jump);
                    //n.startAnimation(anim);
                    String s=txt.getText().toString();
                    n.setText(s);
                    n.setBackgroundResource(R.drawable.icn);
                    //Intent i=new Intent("com.location.pendintent");
                    //Bundle extras=new Bundle();
                    //extras.putString("alarm", s);
                    //i.putExtras(extras);
                    try {
                        startActivity(new Intent("com.hello.loc"));
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        Log.d("service", "Caught here!");
                    }

                }
            });

    }
}

NotificationClass.java

package com.location.sensor;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class NotificationClass extends Activity {
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        //String data=getIntent().getExtras().getString("alarm").toString();
        TextView tv=(TextView) findViewById(R.id.txt_pendint);
        Button btn=(Button) findViewById(R.id.btn_cancel);
        //tv.setText(data);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                showDialog(0);

            }
        });
        setContentView(R.layout.notif);
    }
protected Dialog onCreateDialog(int id)
{
    switch(id)
    {
    case 0:

        return new AlertDialog.Builder(this)
                .setIcon(R.drawable.excl_mark)
                .setTitle("Do you want to Cancel?")
                .setPositiveButton("Yes",new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        finish();
                    }
                })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Toast.makeText(getBaseContext(), "Cancel Clicked!", Toast.LENGTH_LONG).show();
                    }
                })
                .create();
    }
    return null;

}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.location.sensor"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10"/>

    <application
        android:icon="@drawable/gps1"
        android:label="@string/app_name" >
        <activity
            android:name=".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=".NotificationClass"
            android:label="YOU ARE IN PROXIMITY AREA!!!">
            <intent-filter>
               <action android:name="com.hello.loc"/> 
               <category  android:name="android.intent.category.DEFAULT" /> 
             </intent-filter>   
        </activity>
    </application>

</manifest>

LogCat

08-01 00:42:20.665: E/Trace(808): error opening trace file: No such file or directory (2)
08-01 00:42:51.165: E/AndroidRuntime(808): FATAL EXCEPTION: main
08-01 00:42:51.165: E/AndroidRuntime(808): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.location.sensor/com.location.sensor.NotificationClass}: java.lang.NullPointerException
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.os.Looper.loop(Looper.java:137)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.ActivityThread.main(ActivityThread.java:4745)
08-01 00:42:51.165: E/AndroidRuntime(808):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 00:42:51.165: E/AndroidRuntime(808):  at java.lang.reflect.Method.invoke(Method.java:511)
08-01 00:42:51.165: E/AndroidRuntime(808):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-01 00:42:51.165: E/AndroidRuntime(808):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-01 00:42:51.165: E/AndroidRuntime(808):  at dalvik.system.NativeStart.main(Native Method)
08-01 00:42:51.165: E/AndroidRuntime(808): Caused by: java.lang.NullPointerException
08-01 00:42:51.165: E/AndroidRuntime(808):  at com.location.sensor.NotificationClass.onCreate(NotificationClass.java:23)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.Activity.performCreate(Activity.java:5008)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-01 00:42:51.165: E/AndroidRuntime(808):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-01 00:42:51.165: E/AndroidRuntime(808):  ... 11 more

notif.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
 <Button
     android:text="Cancel"
     android:id="@+id/btn_cancel"
     android:layout_height="wrap_content"
     android:layout_width="fill_parent"
     android:background="#FF4000"
     />
 <LinearLayout 
     android:padding="5px"
     android:orientation="vertical">
     <TextView 
         android:id="@+id/txt_pendint"
         android:textSize="18px"
         android:text="No text Added"
         android:textColor="#A9F5E1"
         android:background="#0B3B39"/>
 </LinearLayout>

</RelativeLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:17:35+00:00Added an answer on June 8, 2026 at 6:17 pm

    I think you have to put setContentView(R.layout.notif); below your super.onCreate(savedInstanceState);

    public class NotificationClass extends Activity {
        public void onCreate(Bundle savedInstanceState)
        {
           super.onCreate(savedInstanceState);
            setContentView(R.layout.notif);
            //Rest of code.
        }
    

    EDIT: In regars to “Exported Activity does not require permission” try adding android:exported="false" to the activity property like so:

    <activity 
     android:name=".MainActivity"
     android:label="@string/app_name"
     android:exported="false">
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
    </activity>
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I click the button 1 , the application crashes(force closes). I am not
when i click a button the browser force the image to download the code
I have a very small jquery app with one button and a jquery function.
I call below javascript on click of link/textbox or button. function OpenPopupLinkRisk(Number) { window.open(../PopUp.aspx?id=
How can I force validation when user clicks button? One would think this should
I made a camera layout where two buttons existed.A click button and a share
I am trying to use some action when I click button in navigation controller.
click the button to call this method: private void goRegister(final boolean isUsername) { new
In button click event I am writing this code.(code behind).I know button click event
I click the button and nothing happens. If I take out the validation code,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.