应用程序子类

时间:2015-12-01 01:55:36

标签: java android pointers exception null

我收到此NullPointerException错误,我不知道原因。我对编码很新,所以我不完全理解将它们整理出来的解释。我将尝试在此提供相关信息。

我在this tutorial工作。

以下是Logcat的堆栈跟踪:

11-30 20:28:34.415 1294-1313/system_process I/ActivityManager: Displayed com.brasiltradefx.btfxalerts/.UserProfile: +1s84ms
11-30 20:28:34.433 13772-13802/com.brasiltradefx.btfxalerts E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab7d7980
11-30 20:28:37.164 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 10.648ms
11-30 20:28:37.237 1294-1306/system_process I/ActivityManager: START u0 {cmp=com.brasiltradefx.btfxalerts/.AlertMainActivity} from uid 10059 on display 0
11-30 20:28:37.315 13772-13772/com.brasiltradefx.btfxalerts D/AndroidRuntime: Shutting down VM
11-30 20:28:37.315 13772-13772/com.brasiltradefx.btfxalerts E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.brasiltradefx.btfxalerts, PID: 13772
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brasiltradefx.btfxalerts/com.brasiltradefx.btfxalerts.AlertMainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.toolbox.ImageLoader com.brasiltradefx.btfxalerts.app.AppController.getImageLoader()' on a null object reference
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                  at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:148)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.toolbox.ImageLoader com.brasiltradefx.btfxalerts.app.AppController.getImageLoader()' on a null object reference
                                                                                  at com.brasiltradefx.btfxalerts.adapter.FeedListAdapter.<init>(FeedListAdapter.java:32)
                                                                                  at com.brasiltradefx.btfxalerts.AlertMainActivity.onCreate(AlertMainActivity.java:48)
                                                                                  at android.app.Activity.performCreate(Activity.java:6237)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:148) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
11-30 20:28:37.317 1294-1441/system_process W/ActivityManager:   Force finishing activity com.brasiltradefx.btfxalerts/.AlertMainActivity
11-30 20:28:37.324 1294-1441/system_process W/ActivityManager:   Force finishing activity com.brasiltradefx.btfxalerts/.UserProfile
11-30 20:28:37.383 1294-1793/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
11-30 20:28:37.542 1294-1793/system_process W/EGL_emulation: eglSurfaceAttrib not implemented
11-30 20:28:37.542 1294-1793/system_process W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9cbb11e0, error=EGL_SUCCESS
11-30 20:28:37.831 1294-1308/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{198e9e9 u0 com.brasiltradefx.btfxalerts/.AlertMainActivity t34 f}
11-30 20:28:47.251 1294-1308/system_process W/ActivityManager: Launch timeout has expired, giving up wake lock!
11-30 20:28:47.330 1294-1308/system_process W/ActivityManager: Activity destroy timeout for ActivityRecord{b9d213b u0 com.brasiltradefx.btfxalerts/.UserProfile t34 f}
11-30 20:28:54.408 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 9.171ms
11-30 20:28:57.300 1294-1308/system_process W/ActivityManager: Activity destroy timeout for ActivityRecord{198e9e9 u0 com.brasiltradefx.btfxalerts/.AlertMainActivity t34 f}
11-30 20:29:19.308 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 8.771ms
11-30 20:29:46.339 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 9.186ms
11-30 20:29:56.702 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 31.840ms
11-30 20:30:19.788 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 8.535ms
11-30 20:30:41.479 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 8.854ms
11-30 20:30:59.203 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 11.610ms
11-30 20:31:06.733 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 19.746ms
11-30 20:31:16.218 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 7.017ms
11-30 20:31:34.588 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 6.590ms
11-30 20:32:10.567 1294-1668/system_process D/ConnectivityService: reportNetworkConnectivity(100, false) by 10007
11-30 20:32:10.568 1294-1874/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]: Forcing reevaluation for UID 10007
11-30 20:32:10.627 1294-1874/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]: Checking http://connectivitycheck.gstatic.com/generate_204 on epc.tmobile.com, connectivitycheck.gstatic.com=74.125.21.139
11-30 20:32:10.656 1920-17221/com.google.android.gms I/EventLogService: Aggregate from 1448931729741 (log), 1448931729741 (data)
11-30 20:32:10.725 1294-1874/system_process D/NetworkMonitor/NetworkAgentInfo [MOBILE (UMTS) - 100]: isCaptivePortal: ret=204 headers={null=[HTTP/1.1 204 No Content], Content-Length=[0], Date=[Tue, 01 Dec 2015 01:40:19 GMT], Server=[GFE/2.0], X-Android-Received-Millis=[1448933530725], X-Android-Response-Source=[NETWORK 204], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1448933530679]}
11-30 20:32:10.726 1294-1335/system_process D/ConnectivityService: setProvNotificationVisibleIntent null visible=false networkType=MOBILE extraInfo=null highPriority=false
11-30 20:32:10.727 1294-1335/system_process D/ConnectivityService: NetworkAgentInfo [MOBILE (UMTS) - 100] validation  passed
11-30 20:32:10.836 1813-1826/com.google.process.gapps W/art: Suspending all threads took: 13.693ms
11-30 20:32:10.853 1813-1826/com.google.process.gapps I/art: Background sticky concurrent mark sweep GC freed 8892(951KB) AllocSpace objects, 0(0B) LOS objects, 18% free, 5MB/6MB, paused 15.651ms total 33.468ms
11-30 20:32:11.082 1813-17230/com.google.process.gapps I/PhenotypeFlagCommitter: Experiment Configs successfully retrieved for com.google.android.gms.playlog.uploader
11-30 20:32:11.085 1813-17230/com.google.process.gapps I/GoogleURLConnFactory: Using platform SSLCertificateSocketFactory
11-30 20:32:33.446 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 13.292ms
11-30 20:33:17.374 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 11.145ms
11-30 20:33:21.985 13772-13785/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 12.440ms
11-30 20:33:37.367 13772-13772/com.brasiltradefx.btfxalerts I/Process: Sending signal. PID: 13772 SIG: 9
11-30 20:33:37.395 1294-1793/system_process E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa1a9d4c0
11-30 20:33:37.451 1294-1668/system_process D/GraphicsStats: Buffer count: 6
11-30 20:33:37.452 1294-1668/system_process I/WindowState: WIN DEATH: Window{afedcc3 u0 com.brasiltradefx.btfxalerts/com.brasiltradefx.btfxalerts.GoogleInAppBilling}
11-30 20:33:37.496 1294-1686/system_process I/ActivityManager: Process com.brasiltradefx.btfxalerts (pid 13772) has died
11-30 20:33:37.528 18411-18411/? I/art: Not late-enabling -Xcheck:jni (already on)
11-30 20:33:37.528 18411-18411/? I/art: Late-enabling JIT
11-30 20:33:37.535 1294-1686/system_process I/ActivityManager: Start proc 18411:com.brasiltradefx.btfxalerts/u0a59 for activity com.brasiltradefx.btfxalerts/.GoogleInAppBilling
11-30 20:33:37.582 18411-18411/? I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
11-30 20:33:37.732 18411-18411/? W/System: ClassLoader referenced unknown path: /data/app/com.brasiltradefx.btfxalerts-1/lib/x86
11-30 20:33:38.016 18411-18438/com.brasiltradefx.btfxalerts I/GMPM: App measurement is starting up
11-30 20:33:38.021 18411-18438/com.brasiltradefx.btfxalerts E/GMPM: getGoogleAppId failed with status: 10
11-30 20:33:38.022 18411-18438/com.brasiltradefx.btfxalerts E/GMPM: Uploading is not possible. App measurement disabled
11-30 20:33:38.131 18411-18411/com.brasiltradefx.btfxalerts E/c3+U6b5T6IHUG94DJ22teQVKojk=:: PMSeT4Q8FLTjYUOwNpnShvIlw4E=
11-30 20:33:38.310 18411-18426/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 23.876ms
11-30 20:33:38.453 18411-18426/com.brasiltradefx.btfxalerts I/art: Background sticky concurrent mark sweep GC freed 11632(697KB) AllocSpace objects, 8(160KB) LOS objects, 65% free, 1265KB/3MB, paused 160.467ms total 230.843ms
11-30 20:33:38.485 18411-18422/com.brasiltradefx.btfxalerts W/art: Suspending all threads took: 28.821ms
11-30 20:33:38.694 1294-1313/system_process I/Choreographer: Skipped 65 frames!  The application may be doing too much work on its main thread.
11-30 20:33:38.718 1294-1313/system_process W/AppOps: Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0

FeedListAdapter.java

package com.brasiltradefx.btfxalerts.adapter;

import com.brasiltradefx.btfxalerts.FeedImageView;
import com.brasiltradefx.btfxalerts.R;
import com.brasiltradefx.btfxalerts.app.AppController;
import com.brasiltradefx.btfxalerts.data.FeedItem;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;

/**
 * Created by Deryk on 11/30/2015.
 */
public class FeedListAdapter extends BaseAdapter {
    private Activity activity;
    private LayoutInflater inflater;
    private List<FeedItem> feedItems;
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();

    public FeedListAdapter(Activity activity, List<FeedItem> feedItems) {
        this.activity = activity;
        this.feedItems = feedItems;
    }

    @Override
    public int getCount() {
        return feedItems.size();
    }

    @Override
    public Object getItem(int location) {
        return feedItems.get(location);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (inflater == null)
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null)
            convertView = inflater.inflate(R.layout.feed_item, null);

        if (imageLoader == null)
            imageLoader = AppController.getInstance().getImageLoader();

        TextView name = (TextView) convertView.findViewById(R.id.name);
        TextView timestamp = (TextView) convertView
                .findViewById(R.id.timestamp);
        TextView statusMsg = (TextView) convertView
                .findViewById(R.id.txtStatusMsg);
        TextView url = (TextView) convertView.findViewById(R.id.txtUrl);

        TextView order_type = (TextView) convertView.findViewById(R.id.tvOrder_type);
        TextView pair = (TextView) convertView.findViewById(R.id.tvPair);
        TextView rate = (TextView) convertView.findViewById(R.id.tvRate);
        TextView quick_target = (TextView) convertView.findViewById(R.id.tvQuick_Target);
        TextView long_target = (TextView) convertView.findViewById(R.id.tvLong_Target);
        TextView stop_loss = (TextView) convertView.findViewById(R.id.tvStop_Loss);
        TextView break_even = (TextView) convertView.findViewById(R.id.tvBreak_Even);




        FeedImageView feedImageView = (FeedImageView) convertView
                .findViewById(R.id.feedImage1);

        FeedItem item = feedItems.get(position);

        name.setText(item.getName());

        // Converting timestamp into x ago format
        CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
                Long.parseLong(item.getTimeStamp()),
                System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
        timestamp.setText(timeAgo);

        // Chcek for empty status message
        if (!TextUtils.isEmpty(item.getStatus())) {
            statusMsg.setText(item.getStatus());
            statusMsg.setVisibility(View.VISIBLE);
        } else {
            // status is empty, remove from view
            statusMsg.setVisibility(View.GONE);
        }

        // Checking for null feed url
        if (item.getUrl() != null) {
            url.setText(Html.fromHtml("<a href=\"" + item.getUrl() + "\">"
                    + item.getUrl() + "</a> "));

            // Making url clickable
            url.setMovementMethod(LinkMovementMethod.getInstance());
            url.setVisibility(View.VISIBLE);
        } else {
            // url is null, remove from the view
            url.setVisibility(View.GONE);
        }


        // Feed image
        if (item.getImge() != null) {
            feedImageView.setImageUrl(item.getImge(), imageLoader);
            feedImageView.setVisibility(View.VISIBLE);
            feedImageView
                    .setResponseObserver(new FeedImageView.ResponseObserver() {
                        @Override
                        public void onError() {
                        }

                        @Override
                        public void onSuccess() {
                        }
                    });
        } else {
            feedImageView.setVisibility(View.GONE);
        }

        return convertView;
    }

}

AlertMainActivity.java

package com.brasiltradefx.btfxalerts;

import com.brasiltradefx.btfxalerts.adapter.FeedListAdapter;
import com.brasiltradefx.btfxalerts.app.AppController;
import com.brasiltradefx.btfxalerts.data.FeedItem;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

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

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ListView;

import com.android.volley.Cache;
import com.android.volley.Cache.Entry;
import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;

public class AlertMainActivity extends Activity {
    private static final String TAG = AlertMainActivity.class.getSimpleName();
    private ListView listView;
    private FeedListAdapter listAdapter;
    private List<FeedItem> feedItems;
    private String URL_FEED = "http://www.contrariantradefx.info/android/btfxalerts/fetchalertdata.json";  //todo change URL here -done!

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alert_main);

        listView = (ListView) findViewById(R.id.list);

        feedItems = new ArrayList<FeedItem>();

        listAdapter = new FeedListAdapter(this, feedItems);
        listView.setAdapter(listAdapter);


        // We first check for cached request
        Cache cache = AppController.getInstance().getRequestQueue().getCache();
        Entry entry = cache.get(URL_FEED);
        if (entry != null) {
            // fetch the data from cache
            try {
                String data = new String(entry.data, "UTF-8");
                try {
                    parseJsonFeed(new JSONObject(data));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

        } else {
            // making fresh volley request and getting json
            JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET,
                    URL_FEED, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    VolleyLog.d(TAG, "Response: " + response.toString());
                    if (response != null) {
                        parseJsonFeed(response);
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                }
            });

            // Adding request to volley request queue
            AppController.getInstance().addToRequestQueue(jsonReq);
        }

    }

    /**
     * Parsing json reponse and passing the data to feed view list adapter
     * */
    private void parseJsonFeed(JSONObject response) {
        try {
            JSONArray feedArray = response.getJSONArray("feed");

            for (int i = 0; i < feedArray.length(); i++) {
                JSONObject feedObj = (JSONObject) feedArray.get(i);

                FeedItem item = new FeedItem();
                item.setId(feedObj.getInt("id"));
                item.setName(feedObj.getString("name"));

                // Image might be null sometimes
                String image = feedObj.isNull("image") ? null : feedObj
                        .getString("image");
                item.setImge(image);
                item.setStatus(feedObj.getString("status"));
                item.setProfilePic(feedObj.getString("profilePic"));
                item.setTimeStamp(feedObj.getString("timeStamp"));

                // url might be null sometimes
                String feedUrl = feedObj.isNull("url") ? null : feedObj
                        .getString("url");
                item.setUrl(feedUrl);

                item.setOrder_type(feedObj.getString("order_type"));
                item.setPair(feedObj.getString("pair"));
                item.setRate(feedObj.getString("rate"));
                item.setQuick_target(feedObj.getString("quick_target"));
                item.setLong_target(feedObj.getString("long_target"));
                item.setStop_loss(feedObj.getString("stop_loss"));
                item.setBreak_Even(feedObj.getString("break_even"));

                feedItems.add(item);
            }

            // notify data changes to list adapter
            listAdapter.notifyDataSetChanged();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

我认为它也与AppController有关,所以我已将其包括在内。

package com.brasiltradefx.btfxalerts.app;

import com.brasiltradefx.btfxalerts.volley.LruBitmapCache;
import android.app.Application;
import android.text.TextUtils;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;


/**
 * Created by Deryk on 11/30/2015.
 */
public class AppController extends Application {

    public static final String TAG = AppController.class.getSimpleName();

    private RequestQueue mRequestQueue;
    private ImageLoader mImageLoader;
    LruBitmapCache mLruBitmapCache;

    private static AppController mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
    }

    public static synchronized AppController getInstance() {
        return mInstance;
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        }

        return mRequestQueue;
    }

    public ImageLoader getImageLoader() {
        getRequestQueue();
        if (mImageLoader == null) {
            getLruBitmapCache();
            mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
        }

        return this.mImageLoader;
    }

    public LruBitmapCache getLruBitmapCache() {
        if (mLruBitmapCache == null)
            mLruBitmapCache = new LruBitmapCache();
        return this.mLruBitmapCache;
    }

    public <T> void addToRequestQueue(Request<T> req, String tag) {
        req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
        getRequestQueue().add(req);
    }

    public <T> void addToRequestQueue(Request<T> req) {
        req.setTag(TAG);
        getRequestQueue().add(req);
    }

    public void cancelPendingRequests(Object tag) {
        if (mRequestQueue != null) {
            mRequestQueue.cancelAll(tag);
        }
    }
}

这是清单。

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />

        <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="BTFX Alerts"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <activity android:name=".LoginActivity">
            android:label="BTFX Alerts" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LogoutActivity"
            android:label="@string/title_activity_logout" />
        <activity android:name=".AlertsPage" />
        <activity android:name=".GoogleInAppBilling" />
        <activity android:name=".Blog" />
        <activity android:name=".ForexNews" />
        <activity android:name=".BTFXForum" />
        <activity android:name=".ForexShow" />
        <activity android:name=".ChartAnalysis" />
        <activity android:name=".UserProfile" />
        <activity android:name="com.facebook.LoginActivity" />
        <activity android:name="com.brasiltradefx.btfxalerts.app.AppController" />
        <!--
             ATTENTION: This was auto-generated to add Google Play services to your project for
             App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information.
        -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity android:name=".AlertPage" />
        <activity android:name=".FeedViewImage" />
        <activity android:name=".AlertMainActivity" />
        <activity android:name=".FeedImageView"></activity>
    </application>

</manifest>

给予任何帮助!

2 个答案:

答案 0 :(得分:1)

null类的getInstance()方法中返回一个AppController - 对象,然后尝试在该对象上调用方法。

要修复,请更换

public static synchronized AppController getInstance() {
    return mInstance;
}

public static synchronized AppController getInstance() {
    if(mInstance == null){
        mInstance = new AppController();
    }
    return mInstance;
}

您确定要一个扩展Application的课程吗?

答案 1 :(得分:1)

你在Manifest中指定了MyApplication,它应该是AppController以匹配你的Application子类。

如果查看您正在使用的教程,您会看到他们在AndroidManifest.xml中引用了应用程序类名称:

<application
        android:name="info.androidhive.listviewfeed.app.AppController"

在您的情况下,您可以使用带有android:name="com.brasiltradefx.btfxalerts.app.AppController"的AppController类修改AndroidManifest,以使用正确的Application子类:

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


    <application
        android:name="com.brasiltradefx.btfxalerts.app.AppController"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
            //......................
相关问题