2016-12-10 13 views
0

更新列表視圖沒有使用相同的應用程序返回的其他Facebook好友列表

現在沒有得到一個錯誤,但Facebook好友列表誰也有應用程序沒有未來了我登錄後的主視圖,如果有人可以幫助,那就太棒了。 我已經上傳了HERE這個項目讓任何人看看,並讓我知道我要去哪裏錯了請 如果你能讓我知道哪個文件和哪個部分是錯誤的,以及如何修復它,太棒了!


我試圖登錄時,才能得到顯示好友列表還有誰在某人的Facebook好友列表中的應用程序,我不斷收到錯誤「顯示java.lang.NullPointerException:嘗試調用虛擬方法'int java.lang.String.length()'在空對象引用「

發生錯誤,因爲savedInstanceState總是空的我相信,根據調試...任何想法?完整的代碼如下:

package com.phinder.phinder; 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 

import com.bumptech.glide.Glide; 
import com.bumptech.glide.load.engine.DiskCacheStrategy; 

import org.json.JSONArray; 
import org.json.JSONException; 

import java.util.ArrayList; 

public class MainActivity extends AppCompatActivity { 

public com.phinder.phinder.utils.Constants constants; 
ImageView imageView_picture_profile; 
TextView textview_nameprofile, textview_emailprofile; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    constants = new com.phinder.phinder.utils.Constants(); 

    imageView_picture_profile = (ImageView) findViewById(R.id.imageView_picture_profile); 
    textview_emailprofile = (TextView) findViewById(R.id.textview_emailprofile); 
    textview_nameprofile = (TextView) findViewById(R.id.textview_nameprofile); 

    textview_emailprofile.setText(constants.loginSharedPreferences.getString(constants.LoginEmail, "")); 
    textview_nameprofile.setText(constants.loginSharedPreferences.getString(constants.LoginName, "")); 


    try { 

     Glide.with(getApplicationContext()) 
       .load("http://" + constants.loginSharedPreferences.getString(constants.LoginImage, "")) 
       .placeholder(R.mipmap.ic_launcher) 
       .thumbnail(.1F) 
       .error(R.mipmap.ic_launcher) 
       .diskCacheStrategy(DiskCacheStrategy.SOURCE) 
       .into(imageView_picture_profile); 
    } catch (Exception e) { 
     e.getStackTrace(); 
     Log.d("msg", "Photo " + e.getMessage()); 
    } 

    setContentView(R.layout.activity_main); 
    Intent intent = getIntent(); 
    String jsondata = intent.getStringExtra("jsondata"); 
    JSONArray friendslist; 
    ArrayList<String> friends = new ArrayList<>(); 
    try { 
     friendslist = new JSONArray(jsondata); 
     for (int l = 0; l < friendslist.length(); l++) { 
      friends.add(friendslist.getJSONObject(l).getString("name")); 
     } 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
    ArrayAdapter adapter = new ArrayAdapter<>(MainActivity.this, R.layout.activity_main, friends); 
    ListView listView = (ListView) findViewById(R.id.listView); 
    listView.setAdapter(adapter); 

} 
} 

我很新的Android編碼,所以很抱歉,如果這似乎很明顯!

我已經加入清單下方此外,如果多數民衆贊成需要:

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

<uses-permission android:name="android.permission.INTERNET" /> 

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

    <meta-data 
     android:name="com.facebook.sdk.ApplicationId" 
     android:value="@string/app_id" /> 

    <activity android:name=".MainActivity"></activity> 


    <activity android:name=".LoginActivity"> 

     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <meta-data 
      android:name="com.facebook.sdk.ApplicationId" 
      android:value="@string/app_id" /> 
    </activity> 

    <activity 
     android:name="com.facebook.FacebookActivity" 
     android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.Translucent.NoTitleBar" /> 

    <meta-data 
     android:name="com.facebook.sdk.ApplicationId" 
     android:value="@string/app_id" /> 
</application> 

</manifest> 

這裏是一個錯誤日誌也(去掉了一些個人信息,它擺在那裏從Facebook檢索時):

12/10 23:40:03: Launching app 
    $ adb shell am start -n "com.phinder.phinder/com.phinder.phinder.LoginActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D 
Waiting for application to come online: com.phinder.phinder.test | com.phinder.phinder 
Waiting for application to come online: com.phinder.phinder.test | com.phinder.phinder 
Waiting for application to come online: com.phinder.phinder.test | com.phinder.phinder 
Connecting to com.phinder.phinder 
Connected to the target VM, address: 'localhost:8600', transport: 'socket' 
E/Zygote: v2 
I/SELinux: Function: selinux_compare_spd_ram, index[1], SPD-policy is existed. and_ver=SEPF_SECMOBILE_6.0.1 ver=11 
I/libpersona: KNOX_SDCARD checking this for 10412 
I/libpersona: KNOX_SDCARD not a persona 
W/SELinux: Function: selinux_compare_spd_ram, index[1], priority [1], priority version is VE=SEPF_SECMOBILE_6.0.1_0011 
E/Zygote: accessInfo : 0 
W/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=com.phinder.phinder 
I/art: Late-enabling -Xcheck:jni 
D/TimaKeyStoreProvider: TimaSignature is unavailable 
D/ActivityThread: Added TimaKeyStore provider 
I/System.out: Sending WAIT chunk 
W/ActivityThread: Application com.phinder.phinder is waiting for the debugger on port 8100... 
I/art: Debugger is active 
I/System.out: Debugger has connected 
I/System.out: waiting for debugger to settle... 
I/System.out: waiting for debugger to settle... 
I/System.out: waiting for debugger to settle... 
I/System.out: waiting for debugger to settle... 
I/System.out: waiting for debugger to settle... 
I/System.out: waiting for debugger to settle... 
I/System.out: waiting for debugger to settle... 
I/System.out: waiting for debugger to settle... 
I/System.out: debugger has settled (1439) 
W/System: ClassLoader referenced unknown path: /data/app/com.phinder.phinder-1/lib/arm 
I/InstantRun: Instant Run Runtime started. Android package is com.phinder.phinder, real application class is null. 
W/System: ClassLoader referenced unknown path: /data/app/com.phinder.phinder-1/lib/arm 
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
W/System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/com.phinder.phinder/files/AppEventsLogger.persistedevents 
D/Package Name=: com.phinder.phinder 
D/Key Hash=: zs7kzMXx78uDoJ9QjcsCuL2xPY0= 
W/System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/com.phinder.phinder/files/AppEventsLogger.persistedsessioninfo 
D/SecWifiDisplayUtil: Metadata value : none 
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{802af0f I.E...... R.....ID 0,0-0,0} 
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 
D/libEGL: eglInitialize EGLDisplay = 0x9e67f7c4 
I/OpenGLRenderer: Initialized EGL, version 1.4 
D/mali_winsys: new_window_surface returns 0x3000, [2560x1440]-format:1 
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=2 
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView) 
I/Timeline: Timeline: Activity_idle id: [email protected] time:66569701 
W/System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/com.phinder.phinder/files/AppEventsLogger.persistedevents 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
I/Timeline: Timeline: Activity_launch_request id:com.phinder.phinder time:66595549 
D/SecWifiDisplayUtil: Metadata value : none 
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{cb1dd37 I.E...... R.....I. 0,0-0,0} 
D/mali_winsys: new_window_surface returns 0x3000, [2560x1440]-format:1 
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=2 
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView) 
I/Timeline: Timeline: Activity_idle id: [email protected] time:66595716 
V/ActivityThread: updateVisibility : ActivityRecord{1393c2f [email protected] {com.phinder.phinder/com.phinder.phinder.LoginActivity}} show : true 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{9b1361b V.E...... R.....I. 0,0-0,0} 
D/msg: Facebook 
D/msg: fbid : 10154826532222425 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
D/mali_winsys: new_window_surface returns 0x3000, [1952x720]-format:1 
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView) 
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=2 
I/Timeline: Timeline: Activity_idle id: [email protected] time:66596446 
D/ViewRootImpl: #3 mView = null 
I/Timeline: Timeline: Activity_launch_request id:com.phinder.phinder time:66596581 
D/AbsListView: Get MotionRecognitionManager 
E/MotionRecognitionManager: mSContextService = [email protected] 
E/MotionRecognitionManager: motionService = [email protected]4394d48 
E/MotionRecognitionManager: motionService = [email protected]4394d48 
D/AbsListView: Get MotionRecognitionManager 
D/SecWifiDisplayUtil: Metadata value : none 
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{f7ccc01 I.E...... R.....ID 0,0-0,0} 
D/mali_winsys: new_window_surface returns 0x3000, [2560x1440]-format:1 
W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView) 
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=2 
I/Timeline: Timeline: Activity_idle id: [email protected] time:66596826 
V/ActivityThread: updateVisibility : ActivityRecord{1393c2f [email protected] {com.phinder.phinder/com.phinder.phinder.LoginActivity}} show : false 
D/msg: Fb data1 : {Response: responseCode: 200, graphObject: {"id":"10154826532222425","name":"Dean Mokhtar","location":{"id":"109563165735553","name":"October 6, Al Jizah, Egypt"},"email":"[email protected]","picture":{"data":{"is_silhouette":false,"url":"https:\/\/scontent.xx.fbcdn.net\/v\/t1.0-1\/s200x200\/1471998_10152127224047425_6664922_n.jpg?oh=b5df53e5296ebea31a34126407b64933&oe=58EA2DCC"}}}, error: null} 
D/msg: Fb data : {"id":"10154826532222425","name":"DM","location":{"id":"","name":""},"email":"@","picture":{"data":{"is_silhouette":false,"url":"https:\/\/scontent.xx.fbcdn.net\/v\/t1.0-1\/s200x200\/1471998_10152127224047425_6664922_n.jpg?oh=b5df53e5296ebea31a34126407b64933&oe=58EA2DCC"}}} 
D/email: 
I/WebViewFactory: Loading com.google.android.webview version 55.0.2883.91 (code 288309100) 
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter> 
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter> 
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter> 
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter> 
I/cr_LibraryLoader: Time to load native libraries: 1 ms (timestamps 6941-6942) 
I/cr_LibraryLoader: Expected native library version number "55.0.2883.91", actual native library version number "55.0.2883.91" 
I/Timeline: Timeline: Activity_launch_request id:com.phinder.phinder time:66596962 
D/ViewRootImpl: #3 mView = null 
D/ViewRootImpl: #3 mView = null 
D/AbsListView: Get MotionRecognitionManager 
E/MotionRecognitionManager: mSContextService = [email protected] 
E/MotionRecognitionManager: motionService = [email protected]9e94849 
E/MotionRecognitionManager: motionService = [email protected]9e94849 
D/AbsListView: Get MotionRecognitionManager 
D/AndroidRuntime: Shutting down VM 
E/AndroidRuntime: FATAL EXCEPTION: main 
        Process: com.phinder.phinder, PID: 9793 
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.phinder.phinder/com.phinder.phinder.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference 
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253) 
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
         at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
         at android.os.Handler.dispatchMessage(Handler.java:102) 
         at android.os.Looper.loop(Looper.java:158) 
         at android.app.ActivityThread.main(ActivityThread.java:7225) 
         at java.lang.reflect.Method.invoke(Native Method) 
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
        Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference 
         at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) 
         at org.json.JSONTokener.nextValue(JSONTokener.java:94) 
         at org.json.JSONArray.<init>(JSONArray.java:92) 
         at org.json.JSONArray.<init>(JSONArray.java:108) 
         at com.phinder.phinder.MainActivity.onCreate(MainActivity.java:61) 
         at android.app.Activity.performCreate(Activity.java:6876) 
         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) 
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)  
         at android.app.ActivityThread.access$1100(ActivityThread.java:221)  
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)  
         at android.os.Handler.dispatchMessage(Handler.java:102)  
         at android.os.Looper.loop(Looper.java:158)  
         at android.app.ActivityThread.main(ActivityThread.java:7225)  
         at java.lang.reflect.Method.invoke(Native Method)  
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)  
W/System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/com.phinder.phinder/files/AppEventsLogger.persistedevents 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false 
I/Process: Sending signal. PID: 9793 SIG: 9 
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket' 
+0

請包括完整的堆棧跟蹤。既然你不在這個方法的任何地方調用'String.length()',那麼這個錯誤就會發生在別的地方。 – Kiskae

+0

我從調試中爲你添加了一個完整的日誌...說實話,我不知道如何做「堆棧跟蹤」,所以我不知道這是否足夠。 –

+0

和String.length()用於列表視圖以知道檢索列表中有多少項目 –

回答

0
    at org.json.JSONArray.<init>(JSONArray.java:108) 
        at com.phinder.phinder.MainActivity.onCreate(MainActivity.java:61) 

有問題的錯誤發生在JsonArray的構造函數中。 這表示問題出在線friendslist = new JSONArray(jsondata)

由於有問題的錯誤是NullPointerException原因很可能是intent.getStringExtra("jsondata")返回null,它在沒有值的情況下執行。

要解決這個錯誤,要麼確保任何啓動活動的人都包含Intent中的附加數據,要麼檢查數據是否存在,並以您自己的方式處理缺少數據。

+0

我意識到這一點的代碼是在錯誤的.java文件中,所以我有移動它,現在我沒有得到錯誤...雖然我沒有得到任何出現在ListView中的東西(應該顯示也有應用程序的Facebook朋友),所以現在我有一個全新的問題... 我有一個其他人已經安裝它,他們肯定在我的朋友列表,所以他們應該顯示... –

+0

我已經添加了一個更新,能夠下載該項目 - 主要問題是,列表isn現在不在設備上顯示... –

+0

@DeanMokhtar你真的不應該改變問題。如果您遇到特定問題,請創建一個新問題,但SO不是免費的調試服務 – Kiskae

相關問題