Android : Android Studio Unfortunately, application has stopped

on Monday, March 23, 2015


So I have been trying hard to fix the problem. Seems like my Application (Proffesor's Application) fails to run when I'm on the YearAndSection Java file going to activity_content. What is supposed to be the problem? The application stops everytime I press OK button on the checklist. I'm kind of new on android studio so please do help me. Thanks.



package com.example.user.professorsapplication;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;


public class YearAndSection extends ActionBarActivity {
TextView addYear;
Button yearSec;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_year_and_section);

yearSec = (Button) findViewById(R.id.btnYear);
addYear = (TextView) findViewById(R.id.txtYearSec);
yearSec.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(YearAndSection.this);
final EditText txtYearSec = new EditText(YearAndSection.this);


//process
builder.setTitle("Year and Section");
builder.setMessage("Enter Year and Section");
builder.setView(txtYearSec);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
addYear.setText(txtYearSec.getText());
Display();
Toast.makeText(getApplicationContext(), "Course has been named", Toast.LENGTH_SHORT);


}
});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(getApplicationContext(), "Course has not been named", Toast.LENGTH_SHORT);
}
});

AlertDialog dialog = builder.create();
dialog.show();

}
public void Display() { }
});


final ArrayList array = new ArrayList();
final String[] strings = {"Attendance","Assignment","Exams","Chapter Test","Reports","LabWork","Projects","Midterms","FinalGrade"};

addYear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder alert = new AlertDialog.Builder(YearAndSection.this);
alert.setTitle("Select Category");
alert.setMultiChoiceItems(strings, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked)
{
array.add(which);
}
else if (array.contains (which)){
array.remove(Integer.valueOf(which));
}
}
});
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int intloop = 0; intloop < array.size(); intloop++) {
array.get(intloop);
ArrayAdapter<String> adapt = new ArrayAdapter<String>(YearAndSection.this, R.layout.list, array);
ListView list = (ListView) findViewById(R.id.list);
list.setAdapter(adapt);
}
Display();
Toast.makeText(getApplicationContext(),"Done", Toast.LENGTH_SHORT).show();

}

});
AlertDialog poop = alert.create();
poop.show();
}
public void Display() { }
});
Button button = (Button) findViewById(R.id.BtnMove);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(YearAndSection.this, Content.class));
}
});
}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_year_and_section, 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();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}


This is for the layout of the activity_content.xml



<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.user.professorsapplication.Content"
android:orientation="horizontal">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list" />
</LinearLayout>


This is for the list.xml



<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TextView>

0 comments:

Post a Comment