4 Replies - 3648 Views - Last Post: 03 December 2014 - 08:46 AM

#1 jrab504   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 35
  • Joined: 08-May 14

Emulator says app unfortunately has stopped

Posted 30 November 2014 - 01:29 PM

Hey guys i'm doing an android app for my capstone and just fixed the sqlite connection to editText fields but now the emulator is giving me trouble. Can yall help me? Man this has been so hard for me i spent hours trying to fix it, i did a google search and made modifications to the manifest changed the adb connection time out to 10000, but still no luck!
Here is my AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.changesbarbersandbeautyappointmentbook"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        >
        
        
        <activity
            android:name=".MainActivity"
            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=".MakeAppointment"
            android:label="@string/title_activity_make_appointment" >
        </activity>
       
    </application>

</manifest>



Here is my MainActivity:
package com.example.changesbarbersandbeautyappointmentbook;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/*
 * Steps to using the DB
 * 1. [done] Instantiate the DB adapter
 * 2. [done] Open the DB
 * 3. use get, insert, delete.. to change database
 * 4. [done] Close the database
 */


public class MainActivity extends ActionBarActivity {
	
	Button   mButton;
	EditText mEdit; //name text
	EditText mEdit2; // time text
	EditText mEdit3; // date text
	DataHandler handler;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		
		mButton = (Button)findViewById(R.id.button2);
	    mEdit   = (EditText)findViewById(R.id.NameText);
	    mEdit2 = (EditText)findViewById(R.id.TimeText);
	    mEdit3   = (EditText)findViewById(R.id.DateText);
	    

	    mButton.setonclickListener(
	        new View.onclickListener()
	        {
	            public void onclick(View view)
	            {
	                String getDate = mEdit3.getText().toString();
	                String getTime = mEdit2.getText().toString();
	                String getName = mEdit.getText().toString();
	                handler = new DataHandler(getBaseContext());
	                handler.open();
	                long id = handler.insertData(getDate, getTime, getName);
	                Toast.makeText(getBaseContext(), "Data inserted", Toast.LENGTH_LONG).show();
	                handler.close();
	                
	                
	            }
	        });
	}
	
	


	
	

	@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;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	/** Called when the user clicks the Make Appointment button */
	public void openAppointment(View view)
	{
		Intent intent = new Intent(this, MakeAppointment.class);
		startActivity(intent);
	}
	
	
	public void Reset(View view)
	{
		
	}
}


Here is my DataHandler:
package com.example.changesbarbersandbeautyappointmentbook;

import java.sql.SQLException;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DataHandler {
	public static final String DATE = "Date";
	public static final String TIME = "Time";
	public static final String NAME = "Name";
	public static final String TABLE_NAME = "Appointment";
	public static final String DATA_BASE_NAME = "appointment.sqlite";
	public static final int DATABASE_VERSION = 3;
	public static final String TABLE_CREATE = "create table Appointment (Date text not null, Time text not null, Name text not null);";
	
	DataBaseHelper dbhelper;
	Context ctx;
	SQLiteDatabase db;
	public DataHandler(Context ctx)
	{
		this.ctx = ctx;
		dbhelper = new DataBaseHelper(ctx);
	}
	
	private static class DataBaseHelper extends SQLiteOpenHelper
	{
		
		public DataBaseHelper(Context ctx)
		{
			super(ctx,DATA_BASE_NAME,null,DATABASE_VERSION);
		}
		
		@Override
		public void onCreate(SQLiteDatabase db) {
			
			db.execSQL(TABLE_CREATE);
		}
		
		
		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
		{
			db.execSQL("DROP TABLE IF EXISTS Appointment");
			onCreate(db);
		}
	}
	

	public DataHandler open()
	{
		db = dbhelper.getWritableDatabase();
		return this;
	}
	
	public void close()
	{
		dbhelper.close();
	}
	
	public long insertData(String Date, String Time, String Name)
	{
		ContentValues content = new ContentValues();
		content.put(DATE, Date);
		content.put(TIME, Time);
		content.put(NAME, Name);
		return db.insertOrThrow(TABLE_NAME, null, content);
	}
	
	public Cursor returnData()
	{
		return db.query(TABLE_NAME, new String[] {DATE,TIME,NAME},null,null, null, null, null);
	}

}


Thanks for any help! I'm really lost and only have two more weeks to complete this.

Is This A Good Question/Topic? 0
  • +

Replies To: Emulator says app unfortunately has stopped

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12680
  • View blog
  • Posts: 45,861
  • Joined: 27-December 08

Re: Emulator says app unfortunately has stopped

Posted 30 November 2014 - 02:39 PM

The LogCat should indicate any errors you may be encountering.
Was This Post Helpful? 1
  • +
  • -

#3 jrab504   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 35
  • Joined: 08-May 14

Re: Emulator says app unfortunately has stopped

Posted 01 December 2014 - 07:06 AM

View Postmacosxnerd101, on 30 November 2014 - 09:39 PM, said:

The LogCat should indicate any errors you may be encountering.

Thank you macosxnerd101, i tried what you said and found a bunch of errors. The first one is Read-only file system, i looked it up and it said to do a adb remount. I'm not really sure how to do this here i post the logcat for you:
12-01 07:44:50.818: E/libprocessgroup(1753): failed to make and chown /acct/uid_10061: Read-only file system
12-01 07:44:51.020: E/AndroidRuntime(1753): FATAL EXCEPTION: main
12-01 07:44:51.020: E/AndroidRuntime(1753): Process: com.example.changesbarbersandbeautyappointmentbook, PID: 1753
12-01 07:44:51.020: E/AndroidRuntime(1753): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.changesbarbersandbeautyappointmentbook/com.example.changesbarbersandbeautyappointmentbook.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setonclickListener(android.view.View$onclickListener)' on a null object reference
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.os.Handler.dispatchMessage(Handler.java:102)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.os.Looper.loop(Looper.java:135)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.ActivityThread.main(ActivityThread.java:5221)
12-01 07:44:51.020: E/AndroidRuntime(1753): at java.lang.reflect.Method.invoke(Native Method)
12-01 07:44:51.020: E/AndroidRuntime(1753): at java.lang.reflect.Method.invoke(Method.java:372)
12-01 07:44:51.020: E/AndroidRuntime(1753): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-01 07:44:51.020: E/AndroidRuntime(1753): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-01 07:44:51.020: E/AndroidRuntime(1753): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setonclickListener(android.view.View$onclickListener)' on a null object reference
12-01 07:44:51.020: E/AndroidRuntime(1753): at com.example.changesbarbersandbeautyappointmentbook.MainActivity.onCreate(MainActivity.java:45)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.Activity.performCreate(Activity.java:5933)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-01 07:44:51.020: E/AndroidRuntime(1753): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
12-01 07:44:51.020: E/AndroidRuntime(1753): ... 10 more
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12680
  • View blog
  • Posts: 45,861
  • Joined: 27-December 08

Re: Emulator says app unfortunately has stopped

Posted 01 December 2014 - 09:37 AM

Your error message says:

Quote

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setonclickListener(android.view.View$onclickListener)' on a null object reference


I think mButton is null. You should check this.
Was This Post Helpful? 1
  • +
  • -

#5 jrab504   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 35
  • Joined: 08-May 14

Re: Emulator says app unfortunately has stopped

Posted 03 December 2014 - 08:46 AM

View Postmacosxnerd101, on 01 December 2014 - 04:37 PM, said:

Your error message says:

Quote

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setonclickListener(android.view.View$onclickListener)' on a null object reference


I think mButton is null. You should check this.


Macos i did what you said and it worked. However i am still having trouble, i can't get it to schedule the appointment and send it to email when i click schedule. Also, i wanted to implement a way to check to see if the date was available before making the appointment. I thought sqlite was for storing data on users phone only, i did some research and found out i could use a google app engine as a backend on the cloud, would this be hard to implement?

here is the code:
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MakeAppointment extends ActionBarActivity {


	Button   mButton;
	EditText mEdit; //name text
	EditText mEdit2; // time text
	EditText mEdit3; // date text
	DataHandler handler;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_make_appointment);
		if (savedInstanceState == null) {
			getSupportFragmentManager().beginTransaction()
					.add(R.id.container, new PlaceholderFragment()).commit();
			

		    mButton = (Button)findViewById(R.id.EnterAppointmentButton);
		    mEdit   = (EditText)findViewById(R.id.NameText);
		    mEdit2 = (EditText)findViewById(R.id.TimeText);
		    mEdit3   = (EditText)findViewById(R.id.DateText);
		   
		    
		    mButton.setonclickListener(
			        new View.onclickListener()
			        {
			            public void onclick(View view)
			            {
			            	
			            	// Get strings for NameText, TimeText, DateText
			                String getDate = mEdit3.getText().toString();		            				            	
			                String getTime = mEdit2.getText().toString();
			                String getName = mEdit.getText().toString();
			                
			              
			                
			                Intent email = new Intent(Intent.ACTION_SEND);
			  			    email.putExtra(Intent.EXTRA_EMAIL, new String[]{ "[email protected]"});
			  			    //email.putExtra(Intent.EXTRA_CC, new String[]{ to});
			  			    //email.putExtra(Intent.EXTRA_BCC, new String[]{to});
			  			    email.putExtra(Intent.EXTRA_SUBJECT, getDate);
			  			    email.putExtra(Intent.EXTRA_TEXT,"An appointment has been made for: " + getDate + "\nTime: " + getTime + "\nName: " + getName  );
			  			   
			  			  
			  			    
			   
			  			   //need this to prompts email client only
			  			   email.setType("plain/text");
			   
			  			  startActivity(Intent.createChooser(email, "Choose an Email client :"));
			  			  
			  			  //sqlite
			  			handler = new DataHandler(getBaseContext());
		                handler.open();
		                long id = handler.insertData(getDate, getTime, getName);
		                Toast.makeText(getBaseContext(), "Data inserted", Toast.LENGTH_LONG).show();
		                handler.close();



			     
			                
			                
			            }
			        });

		    
		}
		}
	

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

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	/**
	 * A placeholder fragment containing a simple view.
	 */
	public static class PlaceholderFragment extends Fragment {

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(
					R.layout.activity_make_appointment, container, false);
			return rootView;
		}
	}
}





Thanks osmac
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1