Android Studio Yahoo Finance Fragment - 这里有什么问题?

时间:2015-04-14 00:19:27

标签: java android android-fragments yahoo-finance

我试图简单地显示标准普尔和纳斯达克指数的价格。出于某种原因,我的应用程序仍然崩溃。该代码在Eclipse中工作,而不是在Android Studio中。任何帮助将不胜感激。这是我的片段:

package com.capstone.hammond.wallstreetfantasyleaguefinal;

    import android.app.Activity;
    import android.net.Uri;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.annotation.Nullable;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;
    import java.math.BigDecimal;
    import yahoofinance.Stock;
    import yahoofinance.YahooFinance;


public class HomeFragment extends Fragment {
    public static String spPriceS;
    public static String spPercentS;
    public static String nasdaqPriceS;
    public static String nasdaqPercentS;

    View rootview;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootview = inflater.inflate(R.layout.fragment_home, container, false);
        return rootview;
    }

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

        yahoofinance.Stock stockOne = YahooFinance.get("^GSPC");
        BigDecimal spPriceBD = stockOne.getQuote().getPrice();
        HomeFragment.spPriceS = spPriceBD.toString();
        BigDecimal spPercentBD = stockOne.getQuote().getChangeInPercent();
        HomeFragment.spPercentS = spPercentBD.toString();

        yahoofinance.Stock stockTwo = YahooFinance.get("^IXIC");
        BigDecimal nasdaqPriceBD = stockTwo.getQuote().getPrice();
        HomeFragment.nasdaqPriceS = nasdaqPriceBD.toString();
        BigDecimal nasdaqPercentBD = stockTwo.getQuote().getChangeInPercent();
        HomeFragment.nasdaqPercentS = nasdaqPercentBD.toString();

    }

    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        TextView spPrice = (TextView) view.findViewById(R.id.sp_price);
        spPrice.setText(spPriceS);
        TextView spPercent = (TextView) view.findViewById(R.id.sp_percent);
        spPercent.setText(spPercentS);

        TextView nasdaqPrice = (TextView) view.findViewById(R.id.nasdaq_price);
        nasdaqPrice.setText(nasdaqPriceS);
        TextView nasdaqPercent = (TextView) view.findViewById(R.id.nasdaq_percent);
        nasdaqPercent.setText(nasdaqPercentS);

    }

}

这是我的logcat输出:

04-13 20:04:39.144: D/AndroidRuntime(2539): Shutting down VM
04-13 20:04:39.144: E/AndroidRuntime(2539): FATAL EXCEPTION: main
04-13 20:04:39.144: E/AndroidRuntime(2539): Process: com.capstone.hammond.wallstreetfantasyleaguefinal, PID: 2539
04-13 20:04:39.144: E/AndroidRuntime(2539): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.capstone.hammond.wallstreetfantasyleaguefinal/com.capstone.hammond.wallstreetfantasyleaguefinal.NavDrawer}: android.os.NetworkOnMainThreadException
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.os.Looper.loop(Looper.java:135)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.ActivityThread.main(ActivityThread.java:5221)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at java.lang.reflect.Method.invoke(Native Method)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at java.lang.reflect.Method.invoke(Method.java:372)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-13 20:04:39.144: E/AndroidRuntime(2539): Caused by: android.os.NetworkOnMainThreadException
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at java.net.InetAddress.getAllByName(InetAddress.java:215)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.HostResolver$1.getAllByName(HostResolver.java:29)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:232)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:124)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:272)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:373)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:190)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at yahoofinance.quotes.QuotesRequest.getResult(QuotesRequest.java:83)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at yahoofinance.YahooFinance.getQuotes(YahooFinance.java:332)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at yahoofinance.YahooFinance.get(YahooFinance.java:76)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at yahoofinance.YahooFinance.get(YahooFinance.java:61)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at com.capstone.hammond.wallstreetfantasyleaguefinal.HomeFragment.onCreate(HomeFragment.java:38)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.Activity.performStart(Activity.java:5949)
04-13 20:04:39.144: E/AndroidRuntime(2539):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
04-13 20:04:39.144: E/AndroidRuntime(2539):     ... 10 more
04-13 20:04:39.152: W/ActivityManager(1233):   Force finishing activity com.capstone.hammond.wallstreetfantasyleaguefinal/.NavDrawer
04-13 20:04:39.487: I/Choreographer(1233): Skipped 32 frames!  The application may be doing too much work on its main thread.
04-13 20:04:39.494: E/gralloc_goldfish(932): gralloc_alloc: Mismatched usage flags: 576 x 576, usage 333
04-13 20:04:39.494: W/GraphicBufferAllocator(932): alloc(576, 576, 1, 00000333, ...) failed -22 (Invalid argument)
04-13 20:04:39.494: E/(932): GraphicBufferAlloc::createGraphicBuffer(w=576, h=576) failed (Invalid argument), handle=0x0
04-13 20:04:39.496: E/BufferQueueProducer(1233): [ScreenshotClient] dequeueBuffer: createGraphicBuffer failed
04-13 20:04:39.497: W/WindowManager(1233): Screenshot failure taking screenshot for (1080x1920) to layer 21015
04-13 20:04:39.498: E/ActivityManager(1233): Invalid thumbnail dimensions: 576x576
04-13 20:04:39.506: D/Atlas(1233): Validating map...
04-13 20:04:39.564: I/OpenGLRenderer(1233): Initialized EGL, version 1.4
04-13 20:04:39.601: W/EGL_emulation(1233): eglSurfaceAttrib not implemented
04-13 20:04:39.601: W/OpenGLRenderer(1233): Failed to set EGL_SWAP_BEHAVIOR on surface 0xb0a12e20, error=EGL_SUCCESS
04-13 20:04:42.403: D/TaskPersister(1233): removeObsoleteFile: deleting file=398_task.xml
04-13 20:04:43.226: I/Choreographer(1233): Skipped 214 frames!  The application may be doing too much work on its main thread.
04-13 20:04:43.338: W/ActivityManager(1233): Activity pause timeout for ActivityRecord{8853baa u0 com.capstone.hammond.wallstreetfantasyleaguefinal/.NavDrawer t399 f}
04-13 20:04:43.804: W/EGL_emulation(1536): eglSurfaceAttrib not implemented
04-13 20:04:43.805: W/OpenGLRenderer(1536): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa65402c0, error=EGL_SUCCESS
04-13 20:04:44.989: I/Process(2539): Sending signal. PID: 2539 SIG: 9
04-13 20:04:44.996: W/AudioTrack(1233): AUDIO_OUTPUT_FLAG_FAST denied by client
04-13 20:04:45.094: W/InputDispatcher(1233): channel '9e101c6 com.capstone.hammond.wallstreetfantasyleaguefinal/com.capstone.hammond.wallstreetfantasyleaguefinal.LoginActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
04-13 20:04:45.095: E/InputDispatcher(1233): channel '9e101c6 com.capstone.hammond.wallstreetfantasyleaguefinal/com.capstone.hammond.wallstreetfantasyleaguefinal.LoginActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
04-13 20:04:45.137: I/ActivityManager(1233): Process com.capstone.hammond.wallstreetfantasyleaguefinal (pid 2539) has died
04-13 20:04:45.205: I/WindowState(1233): WIN DEATH: Window{9e101c6 u0 com.capstone.hammond.wallstreetfantasyleaguefinal/com.capstone.hammond.wallstreetfantasyleaguefinal.LoginActivity}
04-13 20:04:45.205: W/InputDispatcher(1233): Attempted to unregister already unregistered input channel '9e101c6 com.capstone.hammond.wallstreetfantasyleaguefinal/com.capstone.hammond.wallstreetfantasyleaguefinal.LoginActivity (server)'
04-13 20:04:47.483: W/SurfaceFlinger(932): couldn't log to binary event log: overflow.
04-13 20:04:47.640: W/InputMethodManagerService(1233): Got RemoteException sending setActive(false) notification to pid 2539 uid 10059
04-13 20:04:47.745: W/OpenGLRenderer(1536): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
04-13 20:04:47.746: W/OpenGLRenderer(1536): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
04-13 20:04:47.746: W/OpenGLRenderer(1536): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
04-13 20:04:48.744: D/TaskPersister(1233): removeObsoleteFile: deleting file=399_task.xml
04-13 20:05:21.633: I/ActivityManager(1233): Killing 1876:com.android.music/u0a36 (adj 15): empty #17
04-13 20:05:21.684: W/libprocessgroup(1233): failed to open /acct/uid_10036/pid_1876/cgroup.procs: No such file or directory
04-13 20:11:04.911: I/art(1502): Background sticky concurrent mark sweep GC freed 15182(816KB) AllocSpace objects, 0(0B) LOS objects, 38% free, 1706KB/2MB, paused 5.802ms total 50.040ms

0 个答案:

没有答案