2 Replies - 196 Views - Last Post: 27 May 2013 - 02:05 PM

#1 droidus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 29-April 12

app force closing

Posted 09 May 2013 - 09:39 PM

I am trying to learn Android, and the basics for now. I wrote a simple program. I find that it force-closes though when running the avd (nexus) - 512 ram. I understand logcat is used for logging errors. I have provided a screenshot of the error in logcat. I am unsure of how to read the logcat log files/errors.

Attached Image

Here is my code:

package com.example.simple;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	final EditText text = (EditText) findViewById(R.id.text);
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //final String textInEditText = text.getText().toString();
                
        final Button button = (Button) findViewById(R.id.button1);
        button.setonclickListener(new View.onclickListener() {
            public void onclick(View v) {
            	Context context = getApplicationContext();
            	CharSequence status = "Your session is being saved...";
            	int duration = Toast.LENGTH_SHORT;

            	Toast toast = Toast.makeText(context, status, duration);
            	toast.show();
            	
            	//ET.setVisibility(View.INVISIBLE);
                if(text.getText().toString() == "")
                {
                } else {
                context = getApplicationContext();
                status = "Please enter something first";
                toast = Toast.makeText(context, status, duration);
                toast.show(); 
                }
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}



Is This A Good Question/Topic? 0
  • +

Replies To: app force closing

#2 JHol  Icon User is offline

  • New D.I.C Head

Reputation: 14
  • View blog
  • Posts: 45
  • Joined: 10-February 11

Re: app force closing

Posted 24 May 2013 - 11:12 AM

it says something like: You have a null pointerexception on line 16.
please post entire logcat output instead of a picture of the output.
It like telling a story without a start, makes us miss important points of what is going on!
Was This Post Helpful? 1
  • +
  • -

#3 Apokio  Icon User is offline

  • D.I.C Addict

Reputation: 134
  • View blog
  • Posts: 510
  • Joined: 14-August 09

Re: app force closing

Posted 27 May 2013 - 02:05 PM

In your layout activity_main.xml do you have a EditText assigned the id "text"?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1