由java.lang.NullPointerException引起的java.lang.RuntimeException

时间:2015-06-17 15:13:47

标签: java android http-post android-volley

我收到此错误消息并且不知道为什么。我已经使用相同的Exception检查了一些问题,但这似乎有所不同。

以下是Log的其余部分:

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
        at android.app.ActivityThread.access$600(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5039)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
        at info.androidhive.nemax.MainActivity.onPostCreate(MainActivity.java:269)
        at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1143)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5039)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)

这是代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    instacia=savedInstanceState;
    loadMenu();


}

public void loadMenu(){
        Globales gVars=(Globales)getApplicationContext();
        String url="https://" + gVars.getDominio()  + ".website.com/app/Menu.php";
        StringRequest request = new StringRequest(Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        String []resp=s.split(System.getProperty("line.separator"));
                        menu=resp[2].split(",");
                        menuLinks=resp[3].split(",");
                        if(menu.length!=0 && menuLinks.length!=0)
                            createMenu();
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError ex) {
                        // System.out.println(ex.getMessage().toString());
                    }
                }
        ){
            @Override
            protected Map<String,String> getParams(){
                Globales gVars =(Globales)getApplicationContext();
                String token=gVars.getToken();
                Map<String,String> params = new HashMap<String, String>();
                params.put("Tk",token);
                return params;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String,String> params = new HashMap<String, String>();
                params.put("Content-Type","application/x-www-form-urlencoded");
                return params;
            }
        };

        RequestQueue queue = Volley.newRequestQueue(this);
        queue.add(request);
}

这就是明白:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="somepackage"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-permission android:name="android.permission.INTERNET"> </uses-permission>

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />

    <application android:name="example.example.Globales"
        android:allowBackup="true"
        android:icon="@drawable/ic_drawer"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="example.example.LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="example.example.MainActivity"
            android:label="somelabel">
        </activity>

    </application>



</manifest>

任何帮助将不胜感激。感谢

0 个答案:

没有答案