Sunita
Sunita

Reputation: 321

Reading JSON from URL to Android

I've start now in Java / Android, and I have this error...

Following this tutorial (modified to my needs ofc), I wanted to connect to rumonet.pt/feeder/index_android.php That outputs a json array.

But that code gives me one error in

  button = (Button) findViewById(R.id.btnFetch);
        buttonClear = (Button) findViewById(R.id.btnClear);
        textView = (TextView) findViewById(R.id.txtView);
        button.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v)
            {
               // examineJSONFile();
            }
        });
        buttonClear.setOnClickListener(new Button.OnClickListener()
        {
            public void onClick(View v)
            {
                //textView.setText("");
            }
        });

More specificly in button and buttonclear SetOnClickListener, because if I comment those lines and the void, it works... Just doesn't do nothing...

Any1 know why, or got a better tutorial? =) Thanks =)

EDIT

11-09 14:16:31.836: D/AndroidRuntime(9939): Shutting down VM
11-09 14:16:31.836: W/dalvikvm(9939): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
11-09 14:16:31.836: E/AndroidRuntime(9939): FATAL EXCEPTION: main
11-09 14:16:31.836: E/AndroidRuntime(9939): java.lang.RuntimeException: Unable to start activity ComponentInfo{noticias.rumonet.pt/noticias.rumonet.pt.MainActivity}: java.lang.NullPointerException
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.os.Looper.loop(Looper.java:137)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.ActivityThread.main(ActivityThread.java:4441)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at java.lang.reflect.Method.invokeNative(Native Method)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at java.lang.reflect.Method.invoke(Method.java:511)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at dalvik.system.NativeStart.main(Native Method)
11-09 14:16:31.836: E/AndroidRuntime(9939): Caused by: java.lang.NullPointerException
11-09 14:16:31.836: E/AndroidRuntime(9939):     at noticias.rumonet.pt.MainActivity.onCreate(MainActivity.java:85)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.Activity.performCreate(Activity.java:4465)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-09 14:16:31.836: E/AndroidRuntime(9939):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
11-09 14:16:31.836: E/AndroidRuntime(9939):     ... 11 more







   button.setOnClickListener(new Button.OnClickListener()
                {
                    public void onClick(View v)
                    {
                       // examineJSONFile();
                    }
                });

Upvotes: 1

Views: 298

Answers (1)

nsemeniuk
nsemeniuk

Reputation: 1171

Check the XML layout. Is it really called btnClear??

It seems to me that you have a null pointer once you try to assing the onClickListener because it doesn't find the view on the layout.

Upvotes: 1

Related Questions