Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
849 views
in Technique[技术] by (71.8m points)

android - Check whether its connected or not

The logcat output is this..

 01-30 06:34:43.633: D/AndroidRuntime(1228): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
    01-30 06:34:43.643: D/AndroidRuntime(1228): CheckJNI is ON
    01-30 06:34:43.703: D/dalvikvm(1228): Trying to load lib libjavacore.so 0x0
    01-30 06:34:43.713: D/dalvikvm(1228): Added shared lib libjavacore.so 0x0
    01-30 06:34:43.733: D/dalvikvm(1228): Trying to load lib libnativehelper.so 0x0
    01-30 06:34:43.743: D/dalvikvm(1228): Added shared lib libnativehelper.so 0x0
    01-30 06:34:43.743: D/dalvikvm(1228): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
    01-30 06:34:43.933: D/dalvikvm(1228): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
    01-30 06:34:44.463: E/memtrack(1228): Couldn't load memtrack module (No such file or directory)
    01-30 06:34:44.463: E/android.os.Debug(1228): failed to load memtrack module: -2
    01-30 06:34:44.743: D/AndroidRuntime(1228): Calling main entry com.android.commands.pm.Pm
    01-30 06:34:44.783: D/AndroidRuntime(1228): Shutting down VM
    01-30 06:34:44.783: D/dalvikvm(1228): Debugger has detached; object registry had 1 entries
    01-30 06:34:45.503: D/AndroidRuntime(1239): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
    01-30 06:34:45.503: D/AndroidRuntime(1239): CheckJNI is ON
    01-30 06:34:45.563: D/dalvikvm(1239): Trying to load lib libjavacore.so 0x0
    01-30 06:34:45.573: D/dalvikvm(1239): Added shared lib libjavacore.so 0x0
    01-30 06:34:45.593: D/dalvikvm(1239): Trying to load lib libnativehelper.so 0x0
    01-30 06:34:45.593: D/dalvikvm(1239): Added shared lib libnativehelper.so 0x0
    01-30 06:34:45.603: D/dalvikvm(1239): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
    01-30 06:34:45.863: D/dalvikvm(1239): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
    01-30 06:34:46.373: E/memtrack(1239): Couldn't load memtrack module (No such file or directory)
    01-30 06:34:46.373: E/android.os.Debug(1239): failed to load memtrack module: -2
    01-30 06:34:46.653: D/AndroidRuntime(1239): Calling main entry com.android.commands.am.Am
    01-30 06:34:46.723: I/ActivityManager(379): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.ptuxiaki.stockpredictions/.MainActivity} from pid 1239
    01-30 06:34:46.763: E/gralloc_goldfish(50): gralloc_alloc: Mismatched usage flags: 328 x 583, usage 333
    01-30 06:34:46.763: W/GraphicBufferAllocator(50): alloc(328, 583, 1, 00000333, ...) failed -22 (Invalid argument)
    01-30 06:34:46.763: E/(50): GraphicBufferAlloc::createGraphicBuffer(w=328, h=583) failed (Invalid argument), handle=0x0
    01-30 06:34:46.763: E/BufferQueue(379): [ScreenshotClient] dequeueBuffer: SurfaceComposer::createGraphicBuffer failed
    01-30 06:34:46.763: W/WindowManager(379): Screenshot failure taking screenshot for (328x583) to layer 21005
    01-30 06:34:46.783: D/AndroidRuntime(1239): Shutting down VM
    01-30 06:34:46.803: D/jdwp(1239): Got wake-up signal, bailing out of select
    01-30 06:34:46.803: D/dalvikvm(1239): Debugger has detached; object registry had 1 entries
    01-30 06:34:46.833: D/dalvikvm(1250): Not late-enabling CheckJNI (already on)
    01-30 06:34:46.833: I/ActivityManager(379): Start proc com.ptuxiaki.stockpredictions for activity com.ptuxiaki.stockpredictions/.MainActivity: pid=1250 uid=10054 gids={50054, 3003}
    01-30 06:34:47.513: D/dalvikvm(1250): GC_FOR_ALLOC freed 47K, 4% free 3137K/3256K, paused 57ms, total 59ms
    01-30 06:34:47.533: I/dalvikvm-heap(1250): Grow heap (frag case) to 4.202MB for 1127536-byte allocation
    01-30 06:34:47.603: D/dalvikvm(1250): GC_FOR_ALLOC freed 2K, 3% free 4235K/4360K, paused 71ms, total 71ms
    01-30 06:34:47.813: D/AndroidRuntime(1250): Shutting down VM
    01-30 06:34:47.813: W/dalvikvm(1250): threadid=1: thread exiting with uncaught exception (group=0xb1b06ba8)
    01-30 06:34:47.823: E/AndroidRuntime(1250): FATAL EXCEPTION: main
    01-30 06:34:47.823: E/AndroidRuntime(1250): Process: com.ptuxiaki.stockpredictions, PID: 1250
    01-30 06:34:47.823: E/AndroidRuntime(1250): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ptuxiaki.stockpredictions/com.ptuxiaki.stockpredictions.MainActivity}: java.lang.NullPointerException
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.os.Handler.dispatchMessage(Handler.java:102)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.os.Looper.loop(Looper.java:136)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.ActivityThread.main(ActivityThread.java:5017)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at java.lang.reflect.Method.invokeNative(Native Method)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at java.lang.reflect.Method.invoke(Method.java:515)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at dalvik.system.NativeStart.main(Native Method)
    01-30 06:34:47.823: E/AndroidRuntime(1250): Caused by: java.lang.NullPointerException
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at com.ptuxiaki.stockpredictions.MainActivity.onCreate(MainActivity.java:55)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.Activity.performCreate(Activity.java:5231)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
    01-30 06:34:47.823: E/AndroidRuntime(1250):     ... 11 more
    01-30 06:34:47.823: W/ActivityManager(379):   Force finishing activity com.ptuxiaki.stockpredictions/.MainActivity
    01-30 06:34:48.013: D/dalvikvm(1250): GC_FOR_ALLOC freed 217K, 6% free 4532K/4816K, paused 22ms, total 22ms
    01-30 06:34:48.243: I/WindowManager(379): Screenshot max retries 4 of Token{b215f238 ActivityRecord{b2373780 u0 com.ptuxiaki.stockpredictions/.MainActivity t6 f}} appWin=Window{b22ec3a8 u0 Starting com.ptuxiaki.stockpredictions} drawState=4
    01-30 06:34:48.243: W/WindowManager(379): Screenshot failure taking screenshot for (720x1280) to layer 21010
    01-30 06:34:48.773: W/ActivityManager(379): Activity pause timeout for ActivityRecord{b2373780 u0 com.ptuxiaki.stockpredictions/.MainActivity t6 f}
    01-30 06:34:48.883: W/EGL_emulation(540): eglSurfaceAttrib not implemented
    01-30 06:34:49.933: D/LightsService(379): Excessive delay setting light: 218ms
    01-30 06:34:50.033: E/SoundPool(379): error loading /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.033: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.033: E/SoundPool(379): error loading /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.033: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.033: E/SoundPool(379): error loading /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.033: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.053: E/SoundPool(379): error loading /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.053: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.053: E/SoundPool(379): error loading /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.053: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
    01-30 06:34:50.053: E/SoundPool(379): error loading /system/media/audio/ui/KeypressStandard.ogg
    01-30 06:34:50.053: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/KeypressStandard.ogg
    01-30 06:34:50.063: W/InputMethodManagerService(379): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b2385490 attribute=null, token = android.os.BinderProxy@b20c9ac8
    01-30 06:34:50.073: E/SoundPool(379): error loading /system/media/audio/ui/KeypressSpacebar.ogg
    01-30 06:34:50.073: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/KeypressSpacebar.ogg
    01-30 06:34:50.073: E/SoundPool(379): error loading /system/media/audio/ui/KeypressDelete.ogg
    01-30 06:34:50.073: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/KeypressDelete.ogg
    01-30 06:34:50.073: E/SoundPool(379): error loading /system/media/audio/ui/KeypressReturn.ogg
    01-30 06:34:50.073: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/KeypressReturn.ogg
    01-30 06:34:50.083: E/SoundPool(379): error loading /system/media/audio/ui/KeypressInvalid.ogg
    01-30 06:34:50.083: W/AudioService(379): Soundpool could not load file: /system/media/audio/ui/KeypressInvalid.ogg
    01-30 06:34:50.083: W/AudioService(379): onLoadSoundEffects(), Error -1 while loading samples
    01-30 06:34:50.083: I/Process(1250): Sending signal. PID: 1250 SIG: 9
    01-30 06:34:50.103: D/LightsService(379): Excessive delay setting light: 124ms
    01-30 06:34:50.113: I/ActivityManager(379): Process com.ptuxiaki.stockpredictions (pid 1250) has died.
    01-30 06:34:50.113: I/WindowState(379): WIN DEATH: Window{b23292d0 u0 com.ptuxiaki.stockpredictions/com.ptuxiaki.stockpredictions.MainActivity}
    01-30 06:34:50.203: D/LightsService(379): Excessive delay setting light: 109ms

and my code is...when i try to run it says has stopped working...i have the permission access_network_state in the manifest. can anyone point me what i am doing wrong??what i want to do is when the app starts to detect if there is network connection and if it is to do what i do in onCreate, if it isnt to create an alert dialog and when user presses ok to launch the settings wifi page to be able to turn the wifi on.. please help me...

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.w

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

remove

 private Activity context;

and everywhere when you are using it, also remove it. For instance change

 context.getSystemService(...

to just

  getSystemService(...

your MainActivity is already a Context, and that is what you need. You created context field, but is is null, and anyways that wont work since you need a context created by the systems. and that is what your activity is.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...