Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when i click to go on another activity i get error java.lang.RuntimeException: Unable to start activity ComponentInfo {…}: java.lang.NullPointerException #22

Open
shivam1692 opened this issue Aug 2, 2014 · 0 comments

Comments

@shivam1692
Copy link

This my java file

import android.net.wifi.WifiConfiguration.Status;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Tab_login extends Activity {

Boolean isConnectionExist=false;
WIfiInternetConnectionDetector cd;

Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab_login);
    cd= new WIfiInternetConnectionDetector(getApplicationContext());
    isConnectionExist = cd.checkMobileInternetcon();

    if(isConnectionExist)
    {

    Button register= (Button)findViewById(R.id.button2);
    register.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        Intent it= new Intent(Tab_login.this,Registration.class);
        startActivity(it);
        }
    });
    Button bt= (Button)findViewById(R.id.button3);
    bt.setOnClickListener(new OnClickListener() {

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

            //startActivityFromChild(Login.class, Intent it = new Intent(), requestCode)
            Intent i = new Intent(Tab_login.this,Login.class);
            startActivity(i);
        }
    });
}

    else
    {   
        AlertDialog.Builder wifi = new AlertDialog.Builder(context);

        wifi.setTitle("Your Device is not connected with Wi-Fi");
        wifi.setMessage("To change settings Kindly tap on the Button Change");
        wifi.setIcon(R.drawable.cancel_d);
        wifi.setPositiveButton("Change", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub



            }
        });

        wifi.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(),"Switch on your Wi-Fi first", Toast.LENGTH_LONG).show();
            Intent it = new Intent(Tab_login.this,MainActivity.class);
            startActivity(it);

            }
        });


    }
}


public void openWifisetting()
{
    final Intent it = new Intent(Intent.ACTION_MAIN,null);
    it.addCategory(Intent.CATEGORY_LAUNCHER);
    final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
    it.setComponent(cn);
    it.setFlags(it.FLAG_ACTIVITY_NEW_TASK);
    startActivity(it);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/* (non-Javadoc)
 * @see android.app.Activity#onStart()
 */
@Override
protected void onStart() {
    // TODO Auto-generated method stub


    super.onStart();
}

}

here is logcat

08-02 06:06:41.397: E/AndroidRuntime(2334): FATAL EXCEPTION: main
08-02 06:06:41.397: E/AndroidRuntime(2334): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xxxi/com.example.xxx.Tab}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xxx/com.example.xxx.Tab_login}: java.lang.NullPointerException
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.os.Looper.loop(Looper.java:137)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-02 06:06:41.397: E/AndroidRuntime(2334): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 06:06:41.397: E/AndroidRuntime(2334): at java.lang.reflect.Method.invoke(Method.java:525)
08-02 06:06:41.397: E/AndroidRuntime(2334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-02 06:06:41.397: E/AndroidRuntime(2334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-02 06:06:41.397: E/AndroidRuntime(2334): at dalvik.system.NativeStart.main(Native Method)
08-02 06:06:41.397: E/AndroidRuntime(2334): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xxx/com.example.xxx.Tab_login}: java.lang.NullPointerException
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2054)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.widget.TabHost.addTab(TabHost.java:240)
08-02 06:06:41.397: E/AndroidRuntime(2334): at com.example.xxx.Tab.onCreate(Tab.java:41)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.Activity.performCreate(Activity.java:5133)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-02 06:06:41.397: E/AndroidRuntime(2334): ... 11 more
08-02 06:06:41.397: E/AndroidRuntime(2334): Caused by: java.lang.NullPointerException
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:143)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.AlertDialog$Builder.(AlertDialog.java:360)
08-02 06:06:41.397: E/AndroidRuntime(2334): at com.example.xxx.Tab_login.onCreate(Tab_login.java:62)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.Activity.performCreate(Activity.java:5133)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-02 06:06:41.397: E/AndroidRuntime(2334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-02 06:06:41.397: E/AndroidRuntime(2334): ... 21 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant