-1

所以我不得不更新我的数据库并重新启动我的应用程序。但是,当我这样做时,我得到了下面列出的运行时错误。我不确定为什么会在这里出错,但一切似乎都井井有条。

    06-13 08:53:32.843: W/dalvikvm(10574): threadid=1: thread exiting with uncaught exception (group=0x41594360)
    06-13 08:53:32.903: E/AndroidRuntime(10574): FATAL EXCEPTION: main
    06-13 08:53:32.903: E/AndroidRuntime(10574): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.projectcaruso.naturalfamilyplaning/com.projectcaruso.naturalfamilyplaning.FragmentChange}: java.lang.NullPointerException
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.ActivityThread.access$700(ActivityThread.java:143)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.os.Handler.dispatchMessage(Handler.java:99)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.os.Looper.loop(Looper.java:137)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.ActivityThread.main(ActivityThread.java:4950)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at java.lang.reflect.Method.invokeNative(Native Method)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at java.lang.reflect.Method.invoke(Method.java:511)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at dalvik.system.NativeStart.main(Native Method)
    06-13 08:53:32.903: E/AndroidRuntime(10574): Caused by: java.lang.NullPointerException
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at com.projectcaruso.naturalfamilyplaning.WelcomeFragment.onCreateView(WelcomeFragment.java:111)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.Activity.performStart(Activity.java:5187)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2083)
    06-13 08:53:32.903: E/AndroidRuntime(10574):    ... 11 more

这是课程:它说错误所在的行是 111mlblEmail.setVisibility(View.GONE);

public class WelcomeFragment extends Fragment {

    private UiLifecycleHelper uiHelper;
    WebView mWebView;
    TextView mName, mother, mlblEmail, mlblName, mlblOther;
    ImageView mImage;
    LoginButton mAuthButton;


    final static int AUTHORIZE_ACTIVITY_RESULT_CODE = 0;
    String[] permissions = { "user_relationships" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }       

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_welcome, null);

        uiHelper = new UiLifecycleHelper(getActivity(), callback);
        uiHelper.onCreate(savedInstanceState);

        String about = getResources().getString(R.string.about_msg);
        mName = (TextView) view.findViewById(R.id.txtName);

        mother = (TextView) view.findViewById(R.id.txtOther);   
        mImage = (ImageView) view.findViewById(R.id.profilepicture);  
        mAuthButton = (LoginButton) view.findViewById(R.id.authButton);

        about = about.replace("\\", "");
        about = "<html><body>"
                + "<p align=\"justify\">" 
                + about + "</p> "
                + "</body></html>";
        mWebView = ((WebView) view.findViewById(R.id.about));
        mWebView.loadData(about, "text/html", "utf-8");

        // Get the data
        Cursor c = getActivity().getContentResolver().query(StatusProvider.CONTENT_URI_USER, null, null, null, null);

        if((c.moveToFirst()) && (c.getCount()>0))
        {
            mAuthButton.setVisibility(View.GONE);
            mName.setText(c.getString(c.getColumnIndex(StatusData.KEY_USER_NAME))); //name


            //new ImageDownloader().execute(c.getString(c.getColumnIndex(StatusData.KEY_USER_EMAIL)); //call asynctask
            mother.setText(c.getString(c.getColumnIndex(StatusData.KEY_USER_OTHER))); //significant_other


            AQuery aq = new AQuery(view);

           //returns the cached file by url, returns null if url is not cached
            File file = aq.getCachedFile(c.getString(c.getColumnIndex(StatusData.KEY_USER_PICTURE)));

            if (file == null) {
                Log.i("PROJECTCARUSO", "Did not find user picture on file" );
                //load an image to an ImageView from network, cache image to file and memory
                aq.id(R.id.profilepicture).image(c.getString(c.getColumnIndex(StatusData.KEY_USER_PICTURE)));
            } else {
                Log.i("PROJECTCARUSO", "Found user picture on file" );
                Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
                mImage.setImageBitmap(myBitmap);
            }

            Log.i("PROJECTCARUSO", "Found user information in database" );
        } else {

            mlblName = (TextView) view.findViewById(R.id.lblName);

            mlblOther = (TextView) view.findViewById(R.id.lblOther);

            //Hide everything
            mName.setVisibility(View.GONE);

            mother.setVisibility(View.GONE);
            mImage.setVisibility(View.GONE);
            mlblName.setVisibility(View.GONE);
            mlblEmail.setVisibility(View.GONE);
            mlblOther.setVisibility(View.GONE);

            Log.i("PROJECTCARUSO", "Did not find user information in database" );
        }

        mAuthButton.setFragment(this);
        mAuthButton.setReadPermissions(Arrays.asList("email"));

        return view;
    }   

    public void refreshView(){

        // Get the data
        Cursor c = getActivity().getContentResolver().query(StatusProvider.CONTENT_URI_USER, null, null, null, null);

        if((c.moveToFirst()) && (c.getCount()>0))
        {
            mAuthButton.setVisibility(View.GONE);


            //Show everything
            mName.setVisibility(View.VISIBLE);

            mother.setVisibility(View.VISIBLE);
            mImage.setVisibility(View.VISIBLE);
            mlblName.setVisibility(View.VISIBLE);
            mlblEmail.setVisibility(View.VISIBLE);
            mlblOther.setVisibility(View.VISIBLE);

            mName.setText(c.getString(c.getColumnIndex(StatusData.KEY_USER_NAME))); //name


            //new ImageDownloader().execute(c.getString(c.getColumnIndex(StatusData.KEY_USER_EMAIL)); //call asynctask
            mother.setText(c.getString(c.getColumnIndex(StatusData.KEY_USER_OTHER))); //significant_other


            AQuery aq = new AQuery(getActivity());

           //returns the cached file by url, returns null if url is not cached
            File file = aq.getCachedFile(c.getString(c.getColumnIndex(StatusData.KEY_USER_PICTURE)));

            if (file == null) {
                Log.i("PROJECTCARUSO", "Did not find user picture on file" );
                //load an image to an ImageView from network, cache image to file and memory
                aq.id(R.id.profilepicture).image(c.getString(c.getColumnIndex(StatusData.KEY_USER_PICTURE)));
            } else {
                Log.i("PROJECTCARUSO", "Found user picture on file" );
                Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
                mImage.setImageBitmap(myBitmap);
            }

            Log.i("PROJECTCARUSO", "Found user information in database" );
        } else {
            Log.i("PROJECTCARUSO", "Did not find user information in database" );
        }


    }

    private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        if (state.isOpened()) {

            // Request user data and show the results
            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {

                        // Get the user info
                        Log.i("PROJECTCARUSO", "Getting the reponse data! ");

                        Utility.userUID = user.getId();
                        final String name = user.getName();
                        final String fname = user.getFirstName();
                        final String username = user.getUsername();
                        final String email = (String) user.getProperty("email");
                        String picURL = null;
                        String significant_other = null;

                        try {
                            String inputLine = user.getProperty("significant_other").toString();
                            JSONObject json = new JSONObject(inputLine.toString());
                            significant_other = json.get("name").toString();
                        } catch (JSONException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }

                        picURL = "http://graph.facebook.com/"+Utility.userUID+"/picture";
                        Log.i("PROJECTCARUSO", "Logged in...");

                        try{            
                                ContentValues values = new ContentValues();
                                values.put(StatusData.KEY_USER_ROWID, Utility.userUID);
                                values.put(StatusData.KEY_USER_NAME, name);
                                values.put(StatusData.KEY_USER_FNAME, fname);
                                values.put(StatusData.KEY_USER_USERNAME, username);
                                values.put(StatusData.KEY_USER_EMAIL, email);
                                values.put(StatusData.KEY_USER_PICTURE, picURL);
                                values.put(StatusData.KEY_USER_OTHER, significant_other);


                                StatusData StatusData = new StatusData(getActivity());

                                StatusData.insertOrReplaceUser(values);

                                Log.i("PROJECTCARUSO", "Insert of facebook information was successfull ");
                                refreshView();
                        } catch (Exception e ) {
                            Log.i("PROJECTCARUSO", "Insert of facebook information was not successfull ");
                        }
                    }
                }
            });

        } else if (state.isClosed()) {
            Log.i("PROJECTCARUSO", "Logged out...");
            Log.i("PROJECTCARUSO", "Exception: " + exception);
        }
    }


    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    @Override
    public void onResume() {
        super.onResume();

        // For scenarios where the main activity is launched and user
        // session is not null, the session state change notification
        // may not be triggered. Trigger it if it's open/closed.
        Session session = Session.getActiveSession();
        if (session != null &&
               (session.isOpened() || session.isClosed()) ) {
            onSessionStateChange(session, session.getState(), null);
        }

        uiHelper.onResume();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }


}
4

1 回答 1

1

您尚未初始化文本视图 mlblEmail

      mlblEmail =(TextView) view.findViewById(R.id.textview);
于 2013-06-13T14:05:50.187 回答