1

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();
                    }
                });
8
  • 1
    What's the error you receive? Can you post it? Commented Nov 9, 2012 at 14:11
  • post the error what your getting Commented Nov 9, 2012 at 14:12
  • How do I get the error? :s im using eclipse, and in my phone just says it as stop working Commented Nov 9, 2012 at 14:15
  • see the error in Logcat in eclipse Commented Nov 9, 2012 at 14:16
  • It is showing NullPointerException in MainActivity.java at line no. 85. check it.. Commented Nov 9, 2012 at 14:21

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Putted setContentView(R.layout.categorias); to load other contentview

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.