-6

Commented out almost everything still can't find the null ?? I only get this error on 2.1 any higher all works well ?? Thanks for the help.

public class BizProfiles extends Activity {

    private Button button;
    private Button btnFbLogin;
    private Button btnPostToWall;
    private Button btnTLogin;
     // Facebook APP ID
    private static String APP_ID = "App ID here"; // 

    // Instance of Facebook Class
    private Facebook facebook;
    @SuppressWarnings("unused")
    private AsyncFacebookRunner mAsyncRunner;
    String FILENAME = "AndroidSSO_data";
    private SharedPreferences mPrefs;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        final Context context = this;
        super.onCreate(savedInstanceState);
        facebook = new Facebook(APP_ID);
        mAsyncRunner = new AsyncFacebookRunner(facebook);



        /////////////////////////////////////////////////////////////////////////////////
        Display display = getWindowManager().getDefaultDisplay(); 
        int width = display.getWidth();
        int height = display.getHeight();
        if (width == 320 && height == 480)
        {
              setContentView(R.layout.bizprofiles320); 
              Log.v("blah", "320 layout");
        }
        else
        {
            Log.v("blah", "480 800 layout");


            setContentView(R.layout.bizprofiles);
        //////
        }
//      String name = getIntent().getExtras().getString("BizName");
//      String address = getIntent().getExtras().getString("BizAddress");
//      String phone = getIntent().getExtras().getString("BizPhone");
//      String about = getIntent().getExtras().getString("BizAbout");
//      String monfri = getIntent().getExtras().getString("BizMonFri");
//      String satsun = getIntent().getExtras().getString("BizSatSun");
//      String imgname = getIntent().getExtras().getString("BizImg");
//      final String website = getIntent().getExtras().getString("BizWeb");


        //////
        button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {

          public void onClick(View arg0) {
            Intent intent = new Intent(context, BizWebSite.class);
         //   intent.putExtra("BizWeb", website.toString());
            startActivity(intent);
          } });

        btnFbLogin = (Button) findViewById(R.id.button2);
        btnFbLogin.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                    loginToFacebook();
                }
        });

        btnPostToWall = (Button) findViewById(R.id.Button01);
        btnPostToWall.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                postToWall();
            }
        });


        btnTLogin = (Button) findViewById(R.id.tlogin);
        btnTLogin.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
//              Intent intent = new Intent(context, TweetPage.class);
//           //   intent.putExtra("BizWeb", website.toString());
//              startActivity(intent);

                 new Twitter_Dialog(BizProfiles.this,"http://twitter.com/?status="+Uri.encode("Twitter Post")).show();

            }
        });

       // String getimg = imgname;
//        int resID = getResources().getIdentifier(imgname, "drawable", "com.RforR.ForPlay1");
//      ImageView image = (ImageView) findViewById(R.id.imageView3); //null;
//      image.setImageResource(resID);
        //System.out.println(resID);
        //Log.v("blah*************", resID);

//      AutoResizeTextView obtar = new AutoResizeTextView(context);
//      obtar tvme = (TextView) findViewById(R.id.tvName);

//        TextView theTextView = (TextView) findViewById(R.id.tvName);
//        theTextView.setText(name);
//        TextView theAdd = (TextView) findViewById(R.id.tvAddress);
//        theAdd.setText(address);
//        TextView thePhone = (TextView) findViewById(R.id.tvPhone);
//        thePhone.setText(phone);

    }



    public void onGetNames(View gn)
    {

//      String name = getIntent().getExtras().getString("BizName");
//      String address = getIntent().getExtras().getString("BizAddress");
//      String phone = getIntent().getExtras().getString("BizName");
//      String about = getIntent().getExtras().getString("BizAbout");
//      String monfri = getIntent().getExtras().getString("BizMonFri");
//      String satsun = getIntent().getExtras().getString("BizSatSun");
//      
//      System.out.println(name);
//      System.out.println(about);
//      System.out.println(satsun);


        Log.v("blah", "blah blah");

    }


    public void loginToFacebook() {
        mPrefs = getPreferences(MODE_PRIVATE);
        String access_token = mPrefs.getString("access_token", null);
        long expires = mPrefs.getLong("access_expires", 0);

        if (access_token != null) {
            facebook.setAccessToken(access_token);
        }

        if (expires != 0) {
            facebook.setAccessExpires(expires);
        }

        if (!facebook.isSessionValid()) {
            facebook.authorize(this,
                    new String[] { "email", "publish_stream" },
                    new DialogListener() {

                        public void onCancel() {
                            // Function to handle cancel event
                        }

                        public void onComplete(Bundle values) {
                            // Function to handle complete event
                            // Edit Preferences and update facebook acess_token
                            SharedPreferences.Editor editor = mPrefs.edit();
                            editor.putString("access_token",
                                    facebook.getAccessToken());
                            editor.putLong("access_expires",
                                    facebook.getAccessExpires());
                            editor.commit();
                        }

                        public void onError(DialogError error) {
                            // Function to handle error

                        }

                        public void onFacebookError(FacebookError fberror) {
                            // Function to handle Facebook errors

                        }

                    });
        }
    }


    public void postToWall() {
        // post on user's wall.
        facebook.dialog(this, "feed", new DialogListener() {

            public void onFacebookError(FacebookError e) {
            }

            public void onError(DialogError e) {
            }

            public void onComplete(Bundle values) {
            }

            public void onCancel() {
            }
        });

    }



    public void onGoBk(View cc)
    {

        finish();
    }


}

logcat

enter image description here

AhabLives
  • 1,308
  • 6
  • 22
  • 34
  • Do you know how to use the debugger? Do you know how to use logcat? – Simon Jan 29 '13 at 21:15
  • 1
    Or you can analyze the trace and NOT expect us to cater to your every need. You know it's a NPE, why are you asking a question? The trace tells you exactly where it occurs. – A--C Jan 29 '13 at 21:16
  • 1
    @Simon &A--C would love to to learn. log cat will not tell me the line or the variable not sure how to use the debugger...as for the stack trace how or where would I find that ? thx anyway. – AhabLives Jan 29 '13 at 21:18
  • To expand on what the others are saying: That's **not** how you debug runtime exceptions. First, check the logcat. It'll give you a line number which tells you exactly which line of code threw the exception. – keyser Jan 29 '13 at 21:20
  • Logcat will show you the complete stack trace, no need for a debugger. See http://stackoverflow.com/q/3280051/1741542 for how to enable it. – Olaf Dietsche Jan 29 '13 at 21:20
  • @Keyser I swear I have looked at the logcat I have no line number...I wish I did... – AhabLives Jan 29 '13 at 21:21
  • 2
    Then post your logcat here. That sounds weird. – keyser Jan 29 '13 at 21:21
  • 1
    Line 106, BizProfiles.onCreate. That's probably all you need. Always look for the `Caused by` line. – keyser Jan 29 '13 at 21:24
  • because all the other numbers were out of range of the code I assumed this number was out of range as well. guess not. thanks for the help. – AhabLives Jan 29 '13 at 21:29
  • @AhabLives That's because they're not referring to your code :p Np. And to clarify my last comment: You want to check the top row(s) below the `Caused by`line to find the local line number – keyser Jan 29 '13 at 21:31
  • I assume that you are using Eclipse. http://www.youtube.com/watch?v=JqHYbm9e05A – Simon Jan 29 '13 at 21:35
  • @Keyser Thanks for the help. the real question would be why this only happens for platform 2.1 and not for 2.2 or higher ? – AhabLives Jan 29 '13 at 21:35
  • @AhabLives What's on line 106 of BizProfiles? – Raghav Sood Jan 29 '13 at 21:40
  • @RaghavSood btnTLogin = (Button) findViewById(R.id.tlogin); btnTLogin.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Intent intent = new Intent(context, TweetPage.class); // // intent.putExtra("BizWeb", website.toString()); // startActivity(intent); new Twitter_Dialog(BizProfiles.this,"http://twitter.com/?status="+Uri.encode("Twitter Post")).show(); } }); – AhabLives Jan 29 '13 at 21:44

1 Answers1

0

You are getting your null pointer exception on 21 and below because getHeight and getWidth were added then. Try this ;

if (  Integer.valueOf(android.os.Build.VERSION.SDK_INT) < 13 ) {
     Display display = getWindowManager().getDefaultDisplay(); 
     int width = display.getWidth();
     int height = display.getHeight();
   } else {
       Display display = getWindowManager().getDefaultDisplay();
          Point size = new Point();
          display.getSize(size);
          int width = size.x;
          int height = size.y;
   }

You may need to play around with the API level (I can't remember what 2.1 is)

jcw
  • 5,132
  • 7
  • 45
  • 54
  • You seem to be correct. the only issue seems to be "display.getSize(size)" ....."getSize()" function does not exist ? – AhabLives Jan 29 '13 at 21:58
  • @AhabLives try removing that line and seeing what happens. This was copied from one of my projects but I may have removed some // by accident – jcw Jan 30 '13 at 07:35