How can I implent ArrayLists to a Spinner? - java

Help me anything is wrong about the whole thing.
I want to make a Spinner with the ArrayLists but it simply does not work!
I think it has something to do with the 'protected void onCreate' part.
I have tried so hard but I allways get the same error.
My Main Class:
package com.example.hvt;
import java.util.ArrayList;
import com.example.hvt.Klassenvertretung.Bezeichnung;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnItemSelectedListener {
public Spinner news, klassen;
public Button btnnews, btnklassen, btnzurueck1, btnzurueck2;
Bezeichnung bezeichnung;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> Bezeichnung = new ArrayList<String>();
String listString = "";
for (String s : Bezeichnung)
{
listString += s + "\t";
}
int listInt;
listInt = Integer.parseInt(listString);
Spinner klassen;
ArrayAdapter<String> klassenadapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item);
klassen = (Spinner) findViewById(R.id.klassenspinner);
bezeichnung.Hinzufügen(bezeichnung);
ArrayAdapter<String> klassen_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, listInt);
klassen_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
klassen.setAdapter(klassenadapter);
klassen.setSelection(0);
klassen.setOnItemSelectedListener(this);
}
#Override
public void onItemSelected(AdapterView<?> parent, View v, int pos,
long id) {
if (pos == 1){
setContentView(R.layout.activity_5aklassen);
}
if (pos <= 1 ){
Toast.makeText(parent.getContext(),
"Deine Auswahl ist: " + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_LONG).show();
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}
An Class in the same package(this Class picks information form the Internet| it should work because I have tested it in normal JAVA)
package com.example.hvt;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class Vertretungsplan {
public Vertretungsplan(String woche)
{
Woche = woche;
Einlesen(woche);
}
public String Woche;
public List<Klassenvertretung> Klassen = new ArrayList<Klassenvertretung>();
private void Hinzufügen(Klassenvertretung neuesElement)
{
Klassen.add(neuesElement);
}
private void Einlesen(String woche)
{
try
{
for (int webseite = 1; webseite < 10000; webseite++)
{
Klassenvertretung klassenvertretung = new Klassenvertretung();
String teilseite = "w000";
if (webseite < 10)
teilseite = teilseite + "0";
teilseite = teilseite + webseite;
Document doc = Jsoup.connect("http://www.hh.shuttle.de/hh/gyhr/Vertretungsplan/Vertretungsplan_Internet/" + woche + "/w/" + teilseite + ".htm").get();
Element h2 = doc.select("h2").get(0);
klassenvertretung.Bezeichnung = h2.text();
Element table = doc.select("table").get(1);
Element[] elemente = table.select("tr").toArray(new Element[0]);
for (int i = 1; i < elemente.length; i++)
{
Element[] tds = elemente[i].select("td").toArray(new Element[0]);
Vertretung vertretung = new Vertretung();
vertretung.Klasse = tds[0].text();
vertretung.Stunde = tds[1].text();
vertretung.Art = tds[2].text();
vertretung.Fach = tds[3].text();
vertretung.Raum = tds[4].text();
vertretung.stattFach = tds[5].text();
vertretung.stattRaum = tds[6].text();
vertretung.Informationen = tds[7].text();
klassenvertretung.Hinzufügen(vertretung);
}
Hinzufügen(klassenvertretung);
}
}
catch (IOException io)
{
}
finally
{
}
}
}
Another Class in the same package(this code should combine all the info too two ArrayLists (tested it in normal JAVA as well so there shouldn't be a mistake))
package com.example.hvt;
import java.util.ArrayList;
import java.util.List;
public class Klassenvertretung
{
public String Bezeichnung;
public static class Bezeichnung {
public List<Bezeichnung> Bezeichnung = new ArrayList<Bezeichnung>();
public void Hinzufügen(Bezeichnung neuesElement)
{
Bezeichnung.add(neuesElement);
}
}
public List<Vertretung> Vertretungen = new ArrayList<Vertretung>();
public void Hinzufügen(Vertretung neuesElement)
{
Vertretungen.add(neuesElement);
}
}
My last Class: (as you can see this is just a class where I defined some Object(they belong to the Class above))
package com.example.hvt;
public class Vertretung
{
public String Klasse;
public String Stunde;
public String Art;
public String Fach;
public String Raum;
public String stattFach;
public String stattRaum;
public String Informationen;
}
The Chat-Log:
11-15 00:26:26.160: I/dalvikvm(714): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
11-15 00:26:26.160: W/dalvikvm(714): VFY: unable to resolve virtual method 11377: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
11-15 00:26:26.160: D/dalvikvm(714): VFY: replacing opcode 0x6f at 0x0000
11-15 00:26:26.160: I/dalvikvm(714): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
11-15 00:26:26.160: W/dalvikvm(714): VFY: unable to resolve virtual method 11383: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
11-15 00:26:26.160: D/dalvikvm(714): VFY: replacing opcode 0x6f at 0x0000
11-15 00:26:26.170: I/dalvikvm(714): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
11-15 00:26:26.170: W/dalvikvm(714): VFY: unable to resolve virtual method 8956: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
11-15 00:26:26.170: D/dalvikvm(714): VFY: replacing opcode 0x6e at 0x000e
11-15 00:26:26.190: I/dalvikvm(714): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
11-15 00:26:26.190: W/dalvikvm(714): VFY: unable to resolve virtual method 364: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
11-15 00:26:26.190: D/dalvikvm(714): VFY: replacing opcode 0x6e at 0x0002
11-15 00:26:26.190: I/dalvikvm(714): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
11-15 00:26:26.190: W/dalvikvm(714): VFY: unable to resolve virtual method 386: Landroid/content/res/TypedArray;.getType (I)I
11-15 00:26:26.190: D/dalvikvm(714): VFY: replacing opcode 0x6e at 0x0002
11-15 00:26:26.320: D/AndroidRuntime(714): Shutting down VM
11-15 00:26:26.320: W/dalvikvm(714): threadid=1: thread exiting with uncaught exception (group=0xb1a90d70)
11-15 00:26:26.330: E/AndroidRuntime(714): FATAL EXCEPTION: main
11-15 00:26:26.330: E/AndroidRuntime(714): Process: com.example.hvt, PID: 714
11-15 00:26:26.330: E/AndroidRuntime(714): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hvt/com.example.hvt.MainActivity}: java.lang.NumberFormatException: Invalid int: ""
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.ActivityThread.access$800(ActivityThread.java:138)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.os.Handler.dispatchMessage(Handler.java:102)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.os.Looper.loop(Looper.java:136)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.ActivityThread.main(ActivityThread.java:5026)
11-15 00:26:26.330: E/AndroidRuntime(714): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 00:26:26.330: E/AndroidRuntime(714): at java.lang.reflect.Method.invoke(Method.java:515)
11-15 00:26:26.330: E/AndroidRuntime(714): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-15 00:26:26.330: E/AndroidRuntime(714): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-15 00:26:26.330: E/AndroidRuntime(714): at dalvik.system.NativeStart.main(Native Method)
11-15 00:26:26.330: E/AndroidRuntime(714): Caused by: java.lang.NumberFormatException: Invalid int: ""
11-15 00:26:26.330: E/AndroidRuntime(714): at java.lang.Integer.invalidInt(Integer.java:137)
11-15 00:26:26.330: E/AndroidRuntime(714): at java.lang.Integer.parseInt(Integer.java:358)
11-15 00:26:26.330: E/AndroidRuntime(714): at java.lang.Integer.parseInt(Integer.java:331)
11-15 00:26:26.330: E/AndroidRuntime(714): at com.example.hvt.MainActivity.onCreate(MainActivity.java:39)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.Activity.performCreate(Activity.java:5242)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-15 00:26:26.330: E/AndroidRuntime(714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
11-15 00:26:26.330: E/AndroidRuntime(714): ... 11 more
11-15 00:26:29.320: I/Process(714): Sending signal. PID: 714 SIG: 9
11-15 00:26:38.220: I/dalvikvm(803): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
11-15 00:26:38.220: W/dalvikvm(803): VFY: unable to resolve virtual method 11377: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
11-15 00:26:38.220: D/dalvikvm(803): VFY: replacing opcode 0x6f at 0x0000
11-15 00:26:38.220: I/dalvikvm(803): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
11-15 00:26:38.220: W/dalvikvm(803): VFY: unable to resolve virtual method 11383: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
11-15 00:26:38.230: D/dalvikvm(803): VFY: replacing opcode 0x6f at 0x0000
11-15 00:26:38.250: I/dalvikvm(803): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
11-15 00:26:38.250: W/dalvikvm(803): VFY: unable to resolve virtual method 8956: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
11-15 00:26:38.250: D/dalvikvm(803): VFY: replacing opcode 0x6e at 0x000e
11-15 00:26:38.270: I/dalvikvm(803): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
11-15 00:26:38.270: W/dalvikvm(803): VFY: unable to resolve virtual method 364: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
11-15 00:26:38.270: D/dalvikvm(803): VFY: replacing opcode 0x6e at 0x0002
11-15 00:26:38.280: I/dalvikvm(803): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
11-15 00:26:38.280: W/dalvikvm(803): VFY: unable to resolve virtual method 386: Landroid/content/res/TypedArray;.getType (I)I
11-15 00:26:38.280: D/dalvikvm(803): VFY: replacing opcode 0x6e at 0x0002
11-15 00:26:38.400: D/AndroidRuntime(803): Shutting down VM
11-15 00:26:38.400: W/dalvikvm(803): threadid=1: thread exiting with uncaught exception (group=0xb1a90d70)
11-15 00:26:38.410: E/AndroidRuntime(803): FATAL EXCEPTION: main
11-15 00:26:38.410: E/AndroidRuntime(803): Process: com.example.hvt, PID: 803
11-15 00:26:38.410: E/AndroidRuntime(803): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hvt/com.example.hvt.MainActivity}: java.lang.NumberFormatException: Invalid int: ""
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.ActivityThread.access$800(ActivityThread.java:138)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.os.Handler.dispatchMessage(Handler.java:102)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.os.Looper.loop(Looper.java:136)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.ActivityThread.main(ActivityThread.java:5026)
11-15 00:26:38.410: E/AndroidRuntime(803): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 00:26:38.410: E/AndroidRuntime(803): at java.lang.reflect.Method.invoke(Method.java:515)
11-15 00:26:38.410: E/AndroidRuntime(803): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-15 00:26:38.410: E/AndroidRuntime(803): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-15 00:26:38.410: E/AndroidRuntime(803): at dalvik.system.NativeStart.main(Native Method)
11-15 00:26:38.410: E/AndroidRuntime(803): Caused by: java.lang.NumberFormatException: Invalid int: ""
11-15 00:26:38.410: E/AndroidRuntime(803): at java.lang.Integer.invalidInt(Integer.java:137)
11-15 00:26:38.410: E/AndroidRuntime(803): at java.lang.Integer.parseInt(Integer.java:358)
11-15 00:26:38.410: E/AndroidRuntime(803): at java.lang.Integer.parseInt(Integer.java:331)
11-15 00:26:38.410: E/AndroidRuntime(803): at com.example.hvt.MainActivity.onCreate(MainActivity.java:39)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.Activity.performCreate(Activity.java:5242)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-15 00:26:38.410: E/AndroidRuntime(803): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
11-15 00:26:38.410: E/AndroidRuntime(803): ... 11 more

the error is bcz of "nothing there to parse!!"
you are creating the ArrayList but not assaigning or adding any values to List at all..!!
your List is empty when it reaches the for loop: so it will return runtime exception as the Logcat shows.!
ArrayList<String> Bezeichnung = new ArrayList<String>();
// populate your List before using it, otherwise it is null/"";
// need some statements like
// Bezeichnung.add("string1");
// Bezeichnung.add("string1");
String listString = "";
for (String s : Bezeichnung)
{
listString += s + "\t";
}
also have some suggestions for you,
you have to follow Java Naming Conventions to avoid mistakes by naming conflict!
make sure you named them correct before running, it may cause generating some unexpected results, which you may not figure out easily!

Related

Fragment on android studio

I have two fragments but the second fragment can not open when clicked
this is the drug fragment the second fragment cant open because of the spinner i
placed on the first screen and i dont know how to fix it please help
I have two fragments but the second fragment can not open when clicked
this is the drug fragment the second fragment cant open because of the spinner i
placed on the first screen and i dont know how to fix it please help
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<Button
android:id="#+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="51dp"
android:layout_marginStart="63dp"
android:text="Save" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/btnSave"
android:layout_marginEnd="76dp"
android:text="Cancel" />
<EditText
android:id="#+id/textView4"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="221dp"
android:layout_marginStart="36dp"
android:hint="Drug" />
<Spinner
android:id="#+id/SpinnerTime"
android:layout_width="133dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/btnSave"
android:layout_marginBottom="135dp" />
<Spinner
android:id="#+id/spinnerFrequency"
android:layout_width="93dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="175dp"
android:layout_marginStart="86dp" />
<Spinner
android:id="#+id/SpinnerQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="227dp"
android:layout_marginEnd="63dp" />
</RelativeLayout>
this is the appointment fragment code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
import android.graphics.Color;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
private TabLayout tabLayout;
private AppBarLayout appBarLayout;
private ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = (TabLayout) findViewById(R.id.tablayout);
appBarLayout = (AppBarLayout)findViewById(R.id.bar);
viewPager = (ViewPager)findViewById(R.id.viewpager);
Spinner spin1 = (Spinner)findViewById(R.id.spinnerFrequency);
Spinner spin2 = (Spinner)findViewById(R.id.SpinnerTime);
Spinner spin3 = (Spinner)findViewById(R.id.SpinnerQty);
Adapter adapter = new Adapter(getSupportFragmentManager());
adapter.AddFragment(new Drugfragment(),"Drug");
adapter.AddFragment(new Appointmentfragment(),"Appointment");
ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.Qty,android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> arrayAdapter2 = ArrayAdapter.createFromResource(this, R.array.time,android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> arrayAdapter3 = ArrayAdapter.createFromResource(this, R.array.frequency,android.R.layout.simple_spinner_item);
spin1.setAdapter(arrayAdapter);
spin2.setAdapter(arrayAdapter2);
spin3.setAdapter(arrayAdapter3);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
arrayAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin1.setOnItemSelectedListener(this);
spin2.setOnItemSelectedListener(this);
spin3.setOnItemSelectedListener(this);
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String text = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(),text,Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
logcat error when i dont add the include layout
05-18 10:26:34.316 5868-5868/? D/dalvikvm: Not late-enabling CheckJNI (already on)
05-18 10:26:34.326 5868-5874/? E/jdwp: Failed sending reply to debugger: Broken pipe
05-18 10:26:34.326 5868-5874/? D/dalvikvm: Debugger has detached; object registry had 1 entries
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.view.Window$Callback.onPointerCaptureChanged, referenced from method android.support.v7.view.WindowCallbackWrapper.onPointerCaptureChanged
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve interface method 20907: Landroid/view/Window$Callback;.onPointerCaptureChanged (Z)V
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve interface method 20909: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve interface method 20911: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve interface method 20915: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 866: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 888: Landroid/content/res/TypedArray;.getType (I)I
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.createDeviceProtectedStorageContext, referenced from method android.support.v4.content.ContextCompat.createDeviceProtectedStorageContext
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 644: Landroid/content/Context;.createDeviceProtectedStorageContext ()Landroid/content/Context;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getCodeCacheDir, referenced from method android.support.v4.content.ContextCompat.getCodeCacheDir
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 650: Landroid/content/Context;.getCodeCacheDir ()Ljava/io/File;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getColor, referenced from method android.support.v4.content.ContextCompat.getColor
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 651: Landroid/content/Context;.getColor (I)I
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v4.content.ContextCompat.getColorStateList
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 652: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getDataDir, referenced from method android.support.v4.content.ContextCompat.getDataDir
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 654: Landroid/content/Context;.getDataDir ()Ljava/io/File;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getDrawable, referenced from method android.support.v4.content.ContextCompat.getDrawable
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 655: Landroid/content/Context;.getDrawable (I)Landroid/graphics/drawable/Drawable;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getExternalCacheDirs, referenced from method android.support.v4.content.ContextCompat.getExternalCacheDirs
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 657: Landroid/content/Context;.getExternalCacheDirs ()[Ljava/io/File;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getExternalFilesDirs, referenced from method android.support.v4.content.ContextCompat.getExternalFilesDirs
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 659: Landroid/content/Context;.getExternalFilesDirs (Ljava/lang/String;)[Ljava/io/File;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getNoBackupFilesDir, referenced from method android.support.v4.content.ContextCompat.getNoBackupFilesDir
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 663: Landroid/content/Context;.getNoBackupFilesDir ()Ljava/io/File;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.getObbDirs, referenced from method android.support.v4.content.ContextCompat.getObbDirs
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 665: Landroid/content/Context;.getObbDirs ()[Ljava/io/File;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.isDeviceProtectedStorage, referenced from method android.support.v4.content.ContextCompat.isDeviceProtectedStorage
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 676: Landroid/content/Context;.isDeviceProtectedStorage ()Z
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.336 5868-5868/? I/dalvikvm: Could not find method android.content.Context.startForegroundService, referenced from method android.support.v4.content.ContextCompat.startForegroundService
05-18 10:26:34.336 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 691: Landroid/content/Context;.startForegroundService (Landroid/content/Intent;)Landroid/content/ComponentName;
05-18 10:26:34.336 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
05-18 10:26:34.346 5868-5868/? I/dalvikvm: Could not find method android.support.design.widget.AppBarLayout.setKeyboardNavigationCluster, referenced from method android.support.design.widget.AppBarLayout.<init>
05-18 10:26:34.346 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 3160: Landroid/support/design/widget/AppBarLayout;.setKeyboardNavigationCluster (Z)V
05-18 10:26:34.346 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x006e
05-18 10:26:34.346 5868-5868/? I/dalvikvm: Could not find method android.support.design.widget.AppBarLayout.setTouchscreenBlocksFocus, referenced from method android.support.design.widget.AppBarLayout.<init>
05-18 10:26:34.346 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 3163: Landroid/support/design/widget/AppBarLayout;.setTouchscreenBlocksFocus (Z)V
05-18 10:26:34.346 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x007f
05-18 10:26:34.346 5868-5868/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
05-18 10:26:34.346 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 829: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-18 10:26:34.346 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-18 10:26:34.346 5868-5868/? I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
05-18 10:26:34.346 5868-5868/? W/dalvikvm: VFY: unable to resolve virtual method 831: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
05-18 10:26:34.346 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
05-18 10:26:34.346 5868-5868/? E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
05-18 10:26:34.346 5868-5868/? W/dalvikvm: VFY: unable to resolve instanceof 239 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
05-18 10:26:34.346 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
05-18 10:26:34.346 5868-5868/? I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
05-18 10:26:34.346 5868-5868/? W/dalvikvm: VFY: unable to resolve direct method 21530: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
05-18 10:26:34.346 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
05-18 10:26:34.346 5868-5868/? I/dalvikvm: Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.design.widget.AppBarLayout$LayoutParams.<init>
05-18 10:26:34.346 5868-5868/? W/dalvikvm: VFY: unable to resolve direct method 21530: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
05-18 10:26:34.346 5868-5868/? D/dalvikvm: VFY: replacing opcode 0x70 at 0x0000
05-18 10:26:34.346 5868-5871/? D/dalvikvm: GC_CONCURRENT freed 168K, 25% free 2708K/3580K, paused 0ms+0ms, total 2ms
05-18 10:26:34.346 5868-5868/? D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 1ms
05-18 10:26:34.356 5868-5868/? D/dalvikvm: GC_FOR_ALLOC freed 100K, 26% free 2829K/3804K, paused 1ms, total 1ms
05-18 10:26:34.356 5868-5868/? I/dalvikvm-heap: Grow heap (frag case) to 4.521MB for 1127532-byte allocation
05-18 10:26:34.356 5868-5877/? D/dalvikvm: GC_FOR_ALLOC freed <1K, 20% free 3930K/4908K, paused 2ms, total 2ms
05-18 10:26:34.366 5868-5871/? D/dalvikvm: GC_CONCURRENT freed <1K, 20% free 3930K/4908K, paused 2ms+0ms, total 4ms
05-18 10:26:34.366 5868-5868/? D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 2ms
05-18 10:26:34.366 5868-5868/? I/dalvikvm-heap: Grow heap (frag case) to 6.940MB for 2536932-byte allocation
05-18 10:26:34.366 5868-5871/? D/dalvikvm: GC_CONCURRENT freed 0K, 14% free 6408K/7388K, paused 1ms+0ms, total 5ms
05-18 10:26:34.376 5868-5868/? D/AndroidRuntime: Shutting down VM
05-18 10:26:34.376 5868-5868/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4fa4678)
05-18 10:26:34.376 5868-5868/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.koichisato.medtime/com.example.koichisato.medtime.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.koichisato.medtime.MainActivity.onCreate(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
at android.app.ActivityThread.access$600(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 
Drugfragment
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Spinner;
public class Drugfragment extends Fragment {
View view;
public Drugfragment(){
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.drugfragment,container,false);
return view;
}
}
appointmentfragment
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Appointmentfragment extends Fragment {
View view;
public Appointmentfragment(){
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.appointmentfragment,container,false);
return view;
}
}
Adapter
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class Adapter extends FragmentPagerAdapter {
private final List<Fragment> fragmentList = new ArrayList<>();
private final List<String> fragmentListTitles = new ArrayList<>();
public Adapter(FragmentManager fn){
super(fn);
}
public Fragment getItem(int position) {
return fragmentList.get(position);
}
#Override
public int getCount() {
return fragmentListTitles.size();
}
#Override
public CharSequence getPageTitle(int position) {
return fragmentListTitles.get(position);
}
public void AddFragment(Fragment fragment, String Title){
fragmentList.add(fragment);
fragmentListTitles.add(Title);
}
}
activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:elevation="0dp"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#be0a16"
app:tabGravity="fill"
app:tabIndicatorColor="#color/colorTabindi"
app:tabMode="fixed"
app:tabTextColor="#color/colorText">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewpager">
</android.support.v4.view.ViewPager>
</LinearLayout>
Strings
<resources>
<string name="app_name">MedTime</string>
<string-array name="frequency">
<item>x1</item>
<item>x2</item>
<item>x3</item>
<item>x4</item>
<item>x5</item>
</string-array>
<string-array name="time">
<item>12:00AM</item>
<item>11:00AM</item>
<item>10:00AM</item>
<item>09:00AM</item>
<item>08:00AM</item>
<item>07:00AM</item>
<item>06:00AM</item>
<item>05:00AM</item>
<item>04:00AM</item>
<item>03:00AM</item>
<item>02:00AM</item>
<item>01:00AM</item>
<item>12:00PM</item>
<item>11:00PM</item>
<item>10:00PM</item>
<item>09:00PM</item>
<item>08:00PM</item>
<item>07:00PM</item>
<item>06:00PM</item>
<item>05:00PM</item>
<item>04:00PM</item>
<item>03:00PM</item>
<item>02:00PM</item>
<item>01:00PM</item>
</string-array>
<string-array name="Qty">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
</string-array>
</resources>
Change your drugfragment to
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class Drugfragment extends Fragment {
View view;
public Drugfragment() {
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.drugfragment, container, false);
final Spinner spin1 = view.findViewById(R.id.spinnerFrequency);
final Spinner spin2 = view.findViewById(R.id.SpinnerTime);
final Spinner spin3 = view.findViewById(R.id.SpinnerQty);
Button save = view.findViewById(R.id.btnSave);
ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(getContext(), R.array.Qty, android.R.layout.simple_spinner_dropdown_item);
ArrayAdapter<CharSequence> arrayAdapter2 = ArrayAdapter.createFromResource(getContext(), R.array.time, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> arrayAdapter3 = ArrayAdapter.createFromResource(getContext(), R.array.frequency, android.R.layout.simple_spinner_item);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
arrayAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin1.setAdapter(arrayAdapter);
spin2.setAdapter(arrayAdapter2);
spin3.setAdapter(arrayAdapter3);
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = spin1.getSelectedItem().toString();
String text2 = spin2.getSelectedItem().toString();
String text3 = spin3.getSelectedItem().toString();
Toast.makeText(getContext(), "text1: " + text + "\ntext2: " + text2 + "\ntext3: " + text3, Toast.LENGTH_SHORT).show();
}
});
return view;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
and your main activity to
import android.graphics.Color;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
private TabLayout tabLayout;
private AppBarLayout appBarLayout;
private ViewPager viewPager;
Spinner spin1;
Spinner spin2;
Spinner spin3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = findViewById(R.id.tablayout);
appBarLayout = findViewById(R.id.bar);
viewPager = findViewById(R.id.viewpager);
spin1 = findViewById(R.id.spinnerFrequency);
spin2 = findViewById(R.id.SpinnerTime);
spin3 = findViewById(R.id.SpinnerQty);
Adapter adapter = new Adapter(getSupportFragmentManager());
adapter.AddFragment(new Drugfragment(), "Drug");
adapter.AddFragment(new appointmentfragment(), "Appointment");
ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.Qty, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> arrayAdapter2 = ArrayAdapter.createFromResource(this, R.array.time, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> arrayAdapter3 = ArrayAdapter.createFromResource(this, R.array.frequency, android.R.layout.simple_spinner_item);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
arrayAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String text = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), text, Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
and do the same for appointmentfragment, Its the same

Pass data from activity with retrofit

i'm create recycler view to display data, after that I want to pass
position of the data to the another activity, but when I use the loge for check if position is pass or not I can't found the position in logcat.
In MainActivity I add static list for Recipe model and I create method to return this list:
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private ProgressBar progressBar;
private LinearLayoutManager mLayoutManager;
private ArrayList<Model> list;
private RecyclerViewAdapter adapter;
private static List<Recipe>mListrecipe;
String url = "https://d17h27t6h515a5.cloudfront.net/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
progressBar = (ProgressBar) findViewById(R.id.progressbar);
mLayoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(mLayoutManager);
/// create a list--
list = new ArrayList<>();
/// get the list from json file
getRetrofitArray();
adapter = new RecyclerViewAdapter( list, MainActivity.this);
// set adapter to recyclerview
recyclerView.setAdapter(adapter);
}
public void getRetrofitArray(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitArrayAPI service = retrofit.create(RetrofitArrayAPI.class);
Call<List<Recipe>> call = service.getRecipeDetails();
call.enqueue(new Callback<List<Recipe>>() {
#Override
public void onResponse(Call<List<Recipe>> call, Response<List<Recipe>> response) {
Log.e("main ", " retrofit response "+ response.body().toString());
mListrecipe=response.body();
for (int i=0; i<response.body().size();i++){
Log.e("main ", " name "+ response.body().get(i).getName() + " serving "+
response.body().get(i).getServings());
list.add( new Model( Model.IMAGE_TYPE,response.body(), response.body().get(i).getName() ,
" Serving " +response.body().get(i).getServings() ) );
}
adapter.notifyDataSetChanged();
}
#Override
public void onFailure(Call<List<Recipe>> call, Throwable t) {
Log.e("main ", " retrofit error "+ t.toString());
}
});
}
public static List<Recipe>getList(){
return mListrecipe;
}
}
I add putExtra with key value to pass position
public class RecyclerViewAdapter extends RecyclerView.Adapter {
private ArrayList<Model> dataset;
private Context mContext;
public RecyclerViewAdapter(ArrayList<Model> mlist, Context context) {
this.dataset = mlist;
this.mContext = context;
}
public static class ImageTypeViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
TextView title, subtitle;
public ImageTypeViewHolder(View itemView) {
super(itemView);
this.title = (TextView) itemView.findViewById(R.id.title);
this.subtitle = (TextView) itemView.findViewById(R.id.subtitle);
this.imageView=(ImageView)itemView.findViewById(R.id.imageview);
}
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from( parent.getContext()).inflate(R.layout.itemlist, parent, false);
return new ImageTypeViewHolder(view) ;
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
Model object = dataset.get(position);
( (ImageTypeViewHolder) holder).title.setText( object.title );
( (ImageTypeViewHolder) holder).subtitle.setText( object.subtitle );
/// dataset.get(position)
( (ImageTypeViewHolder) holder).title.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new Intent(mContext,SelectReceipe.class);
intent.putExtra("itempostion",position);
mContext.startActivity(intent);
}
});
( (ImageTypeViewHolder) holder).subtitle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new Intent(mContext,SelectReceipe.class);
intent.putExtra("itempostion",position);
mContext.startActivity(intent);
}
});
( (ImageTypeViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new Intent(mContext,SelectReceipe.class);
intent.putExtra("itempostion",position);
mContext.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return dataset.size() ;
}
}
this is 2 activity I pass position but i can't find value in logcat
public class SelectReceipe extends AppCompatActivity {
List<Recipe>sListRecipe;
public int itempostion;
private String TAG;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selectreceipe);
sListRecipe=MainActivity.getList();
Intent i =getIntent();
itempostion= i.getExtras().getInt("itempostion");
Log.e(TAG,"itempostion"+String.valueOf(itempostion)+"valou"+sListRecipe.get(itempostion).getName().toString());
}
logcat:
09-26 13:34:41.355 31852-31852/? D/dalvikvm: Late-enabling CheckJNI
09-26 13:34:42.459 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
09-26 13:34:42.471 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve interface method 20343: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
09-26 13:34:42.471 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
09-26 13:34:42.479 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
09-26 13:34:42.479 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
09-26 13:34:42.479 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve interface method 20345: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
09-26 13:34:42.479 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
09-26 13:34:42.479 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
09-26 13:34:42.479 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve interface method 20349: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
09-26 13:34:42.479 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
09-26 13:34:42.483 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
09-26 13:34:42.495 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve virtual method 478: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
09-26 13:34:42.495 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-26 13:34:42.495 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
09-26 13:34:42.495 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve virtual method 500: Landroid/content/res/TypedArray;.getType (I)I
09-26 13:34:42.495 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
09-26 13:34:42.695 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.widget.FrameLayout.startActionModeForChild, referenced from method android.support.v7.widget.ActionBarContainer.startActionModeForChild
09-26 13:34:42.695 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve virtual method 20822: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
09-26 13:34:42.699 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
09-26 13:34:42.735 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
09-26 13:34:42.735 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve virtual method 20233: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
09-26 13:34:42.735 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x6f at 0x0007
09-26 13:34:42.739 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
09-26 13:34:42.743 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve virtual method 292: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
09-26 13:34:42.743 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
09-26 13:34:42.763 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
09-26 13:34:42.763 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve virtual method 441: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
09-26 13:34:42.763 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-26 13:34:42.763 31852-31852/blueappsoftware.mybakingtips I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
09-26 13:34:42.767 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve virtual method 443: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
09-26 13:34:42.767 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-26 13:34:42.771 31852-31852/blueappsoftware.mybakingtips E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
09-26 13:34:42.771 31852-31852/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve instanceof 142 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
09-26 13:34:42.771 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
09-26 13:34:42.815 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 256K, 3% free 10939K/11271K, paused 18ms+1ms, total 27ms
09-26 13:34:42.815 31852-31852/blueappsoftware.mybakingtips D/dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 4ms
09-26 13:34:42.911 31852-31852/blueappsoftware.mybakingtips D/libEGL: loaded /system/lib/egl/libEGL_genymotion.so
[ 09-26 13:34:42.931 31852:31852 D/ ]
HostConnection::get() New Host Connection established 0xb7f81e90, tid 31852
09-26 13:34:43.019 31852-31852/blueappsoftware.mybakingtips D/libEGL: loaded /system/lib/egl/libGLESv1_CM_genymotion.so
09-26 13:34:43.035 31852-31852/blueappsoftware.mybakingtips D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so
09-26 13:34:43.111 31852-31852/blueappsoftware.mybakingtips W/EGL_genymotion: eglSurfaceAttrib not implemented
09-26 13:34:43.127 31852-31852/blueappsoftware.mybakingtips D/OpenGLRenderer: Enabling debug mode 0
09-26 13:34:43.183 31852-31852/blueappsoftware.mybakingtips D/OpenGLRenderer: TextureCache::get: create texture(0xb7fa1438): name, size, mSize = 1, 4096, 4096
09-26 13:34:43.339 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips I/dalvikvm: Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve static method 22787: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips I/dalvikvm: Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips W/dalvikvm: VFY: unable to resolve static method 22786: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
09-26 13:34:43.343 31852-31877/blueappsoftware.mybakingtips D/dalvikvm: VFY: replacing opcode 0x71 at 0x000a
09-26 13:34:43.567 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 279K, 4% free 11121K/11527K, paused 24ms+10ms, total 38ms
09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: retrofit response [blueappsoftware.mybakingtips.Recipe#536b4c20, blueappsoftware.mybakingtips.Recipe#536c68ec, blueappsoftware.mybakingtips.Recipe#536c1a24, blueappsoftware.mybakingtips.Recipe#536e27b8]
09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Nutella Pie serving 8
09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Brownies serving 8
09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Yellow Cake serving 8
09-26 13:34:44.079 31852-31852/blueappsoftware.mybakingtips E/main: name Cheesecake serving 8
09-26 13:34:44.119 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 217K, 4% free 11298K/11655K, paused 15ms+0ms, total 20ms
09-26 13:34:44.179 31852-31852/blueappsoftware.mybakingtips D/OpenGLRenderer: TextureCache::get: create texture(0xb7f36950): name, size, mSize = 9, 33856, 37952
09-26 13:34:48.955 31852-31852/blueappsoftware.mybakingtips W/EGL_genymotion: eglSurfaceAttrib not implemented
09-26 13:34:48.955 31852-31852/blueappsoftware.mybakingtips E/RecyclerView: No adapter attached; skipping layout
09-26 13:34:48.967 31852-31852/blueappsoftware.mybakingtips E/RecyclerView: No adapter attached; skipping layout
09-26 13:52:03.367 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 332K, 4% free 11375K/11847K, paused 6ms+1ms, total 16ms
09-26 14:16:49.627 31852-31853/blueappsoftware.mybakingtips D/dalvikvm: GC_CONCURRENT freed 426K, 5% free 11345K/11911K, paused 9ms+0ms, total 9ms
You are probably not getting the list because you are using the getter from a different Activity.Instead, you can pass your list via Intent, but for that, you should implement your class as Parcelable or Serializable .Here is a nice post for that How can I make my custom objects Parcelable? And one thing if you are bound to load and temporarily save a list so that you can use anywhere in App then you can use setter and getter in Android Application class.Here is a nice post for that Using the Android Application class to persist data

My app unfortunately stopped may be due to mistakes

My app consists of level, each level has 10 question. This is my first level and first question class..
public class level1 extends ActionBarActivity {
private EditText mans1;
private TextView mcount;
int sum;
public void Onclick(View v) {
mans1 = (EditText) findViewById(R.id.ans1);
mcount = (TextView) findViewById(R.id.count);
double answer = Double.parseDouble(mans1.getText().toString());
if (answer == (8 + 7))
{
Toast.makeText(level1.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
mcount.setText(sum++);
}
else
{
Toast.makeText(level1.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
mcount.setText(sum);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1);
final TextView texview = (TextView)findViewById(R.id.count);
Button sendButton = (Button)findViewById(R.id.tm);
sendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int count = Integer.parseInt(texview.getText().toString());
Intent intent = new Intent(getApplicationContext(), level1.class);
intent.putExtra("mycount", sum);
startActivity(intent);
}
});
}
public void buttonOnClickgo(View v) {
Button next = (Button) v;
startActivity(new Intent(getApplicationContext(), level1q2.class));
}
public void buttonOnClickBack(View v) {
Button back = (Button) v;
startActivity(new Intent(getApplicationContext(), Activity2.class));
}
}
and this is the first level second question class.
public class level1q2 extends ActionBarActivity {
private EditText mans1;
private TextView mcount;
int sum;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1q2);
TextView textView = (TextView)findViewById(R.id.count);
Intent intent = getIntent();
int count = intent.getIntExtra("mycount", 0);
textView.setText(count);}
public void Onclick(View view)
{
mans1 = (EditText) findViewById(R.id.ans1);
mcount = (TextView) findViewById(R.id.count);
double answer = Double.parseDouble(mans1.getText().toString());
if (answer == (15-3)) {
Toast.makeText(level1q2.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
int count = getIntent().getIntExtra("mycount", 0);
mcount.setText(count++);
} else {
Toast.makeText(level1q2.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
int count = getIntent().getIntExtra("mycount", 0);
mcount.setText(count);
}
}
public void buttonOnClickgo(View v) {
Button next = (Button) v;
startActivity(new Intent(getApplicationContext(), level1q3.class));
}
public void buttonOnClickBack(View v) {
Button back = (Button) v;
startActivity(new Intent(getApplicationContext(), Activity2.class));
}
}
I did some changes in these classes because I want to pass the count variable from first question to the second question activity.
It is was working before I edited them but now it shows "unfortunately stopped" message ..
please review the codes
After debugging ..
04:30:29.101 1075-1075/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3b03ba8)
08-23 04:30:29.121 1075-1075/com.mainuser.math.passgrade4.passgrade4 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mainuser.math.passgrade4.passgrade4, PID: 1075
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mainuser.math.passgrade4.passgrade4/com.mainuser.math.passgrade4.passgrade4.level1}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at com.mainuser.math.passgrade4.passgrade4.level1.onCreate(level1.java:34)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
08-23 04:30:37.051 1075-1075/com.mainuser.math.passgrade4.passgrade4 I/Process﹕ Sending signal. PID: 1075 SIG: 9
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 366: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 388: Landroid/content/res/TypedArray;.getType (I)I
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.591 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ GC_FOR_ALLOC freed 125K, 7% free 2894K/3100K, paused 35ms, total 35ms
The problem is exactly what your exception says:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mainuser.math.passgrade4.passgrade4/com.mainuser.math.passgrade4.passgrade4.level1}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
...
Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at com.mainuser.math.passgrade4.passgrade4.level1.onCreate(level1.java:34)
...
Your button is an ImageButton, but you tried to cast it to Button (which is not a superclass of ImageButton).

How to check if checkbox was checked?

I am creating a quiz app for androids. I have 3 fragments and 3 checkboxes on first two of them. On the last fragment there is a button which when pressed opens an activity called "End". I need that on the "End" activity a result would appear of how many correct answers one have chosen.
Firstly, I've tried to check if it's working with only the first fragment, but I got stuck. The app closes when I press the button.
End.java:
package bandymas.viewpagerexample;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class End extends ActionBarActivity {
private CheckBox checkBox1, checkBox2, checkBox3;
private Button button;
TextView newresult = (TextView)findViewById(R.id.textView1);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
getSupportActionBar().hide();
addListenerOnButton();
}
private void addListenerOnButton() {
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
//Run when button is clicked
#Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
result.append("CheckBox1 : ").append(checkBox1.isChecked());
result.append("\nCheckbox2 : ").append(checkBox2.isChecked());
result.append("\nCheckBox3 :").append(checkBox3.isChecked());
newresult.setText("My Awesome Text");
}
});
}
#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_naujas_baigimas, 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);
}
}
Here's my logcat:
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:04:37.684 6020-6020/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:04:37.734 6020-6020/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=SEPF_GT-I9505_4.4.2_0033
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> Normal User
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> bandymas.viewpagerexample [ userId:0 | appId:10229 ]
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ Late-enabling CheckJNI
04-01 20:07:31.584 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:31.594 7094-7094/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:07:31.794 7094-7094/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:07:31.844 7094-7094/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:42.454 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 365: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 387: Landroid/content/res/TypedArray;.getType (I)I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample D/AndroidRuntime﹕ Shutting down VM
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4187fda0)
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: bandymas.viewpagerexample, PID: 7094
java.lang.RuntimeException: Unable to start activity ComponentInfo{bandymas.viewpagerexample/bandymas.viewpagerexample.End}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at bandymas.viewpagerexample.End.addListenerOnButton(End.java:33)
at bandymas.viewpagerexample.End.onCreate(End.java:23)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
activity_end.xml:
<RelativeLayout 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="bandymas.viewpagerexample.End">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Result"
android:id="#+id/textView1"
android:layout_marginTop="100dp"
android:textSize="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Please Check that there is the button(R.id.button) in activity_end.xml.
I guess that the button's id doesn't exist in activity_end.xml.

New Activity Problems

Okay, so i finally got my button to start my new activity from the main activity. now, the problem i have is that when the new activity starts, the avd gives me an error saying "unfortunately, yourApp has stopped working". I tried for hours to detect the problem untill i began to comment some part of the new activity's code and then finally, i found it. keep in mind, that almost all the variables i used in the new activity also had common names and ids to those in the mainActivity, but this should not be the problem since i am not passing anything through both activities...at least not now. The problem was from the spinners. their declaration worked fine...i guess, the findViewByid method gave no problem, the arrayAdapter also gave no problems but i noticed that the app only shuts down when i remove the comments from the onItemSelectedListener and the setAdapters methods. i don't know why this happens. i used the same code for the mainActivity and it works perfectly. Dunno if i overloaded the onCreate method but as i said earlier, it works fine in the mainActivity. the new activity code for th onCreate method is given below...the other parts of the code works fine.
public class firstYearSecondSemester2 extends Activity implements AdapterView.OnItemSelectedListener {
private String[] grades;
public Spinner spinner0, spinner1, spinner2, spinner3, spinner4, spinner5, spinner6, spinner7, spinner8;
private double[] grade_values = {0.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0};
//private Spinner gpa_grade0, gpa_grade1, gpa_grade2, gpa_grade3, gpa_grade4, gpa_grade5;
private double gpa_grade_0, gpa_grade_1, gpa_grade_2, gpa_grade_3, gpa_grade_4, gpa_grade_5, gpa_grade_6, gpa_grade_7, gpa_grade_8;
private TextView gpa, gpa_credits0, gpa_credits1, gpa_credits2, gpa_credits3, gpa_credits4,gpa_credits5, gpa_credits6, gpa_credits7,gpa_credits8;
private int gpa_credits_0, gpa_credits_1, gpa_credits_2, gpa_credits_3, gpa_credits_4, gpa_credits_5, gpa_credits_6, gpa_credits_7, gpa_credits_8;
public int[] spinner_ids;
public int spinner_check;
public int spinner_index;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_year_second_semester2);
spinner_ids = new int[9];
spinner_check = 0;
spinner_index = 0;
gpa = (TextView) findViewById(R.id.gpa_results_text);
grades = getResources().getStringArray(R.array.grades);
gpa_credits0 = (TextView) findViewById(R.id.gpa_credits_0);
gpa_credits1 = (TextView) findViewById(R.id.gpa_credits_1);
gpa_credits2 = (TextView) findViewById(R.id.gpa_credits_2);
gpa_credits3 = (TextView) findViewById(R.id.gpa_credits_3);
gpa_credits4 = (TextView) findViewById(R.id.gpa_credits_4);
gpa_credits5 = (TextView) findViewById(R.id.gpa_credits_5);
gpa_credits6 = (TextView) findViewById(R.id.gpa_credits_6);
gpa_credits7 = (TextView) findViewById(R.id.gpa_credits_7);
gpa_credits8 = (TextView) findViewById(R.id.gpa_credits_8);
spinner0 = (Spinner) findViewById(R.id.gradeSpinner0);
spinner1 = (Spinner) findViewById(R.id.gradeSpinner1);
spinner2 = (Spinner) findViewById(R.id.gradeSpinner2);
spinner3 = (Spinner) findViewById(R.id.gradeSpinner3);
spinner4 = (Spinner) findViewById(R.id.gradeSpinner4);
spinner5 = (Spinner) findViewById(R.id.gradeSpinner5);
spinner6 = (Spinner) findViewById(R.id.gradeSpinner6);
spinner7 = (Spinner) findViewById(R.id.gradeSpinner7);
spinner8 = (Spinner) findViewById(R.id.gradeSpinner8);
ArrayAdapter<String> each_grade = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, grades);
each_grade.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner0.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner1.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner2.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner3.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner4.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner5.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner6.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner7.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner8.setAdapter(new NothingSelectedSpinnerAdapter(each_grade, R.layout.contact_spinner_row_nothing_selected,/* R.layout.contact_spinner_nothing_selected_dropdown, // Optional*/this));
spinner0.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner1.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner2.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner3.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner4.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner5.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner6.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner7.setOnItemSelectedListener(firstYearSecondSemester2.this);
spinner8.setOnItemSelectedListener(firstYearSecondSemester2.this);
}
Logcat Messages
04-14 02:21:16.260 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11350: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11356: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 9044: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-14 02:21:16.830 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 368: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ VFY: unable to resolve virtual method 390: Landroid/content/res/TypedArray;.getType (I)I
04-14 02:21:16.910 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-14 02:21:17.150 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ GC_FOR_ALLOC freed 140K, 8% free 3075K/3340K, paused 0ms, total 5ms
04-14 02:21:17.150 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/dalvikvm-heap﹕ Grow heap (frag case) to 4.195MB for 1127532-byte allocation
04-14 02:21:17.210 1772-1781/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ GC_FOR_ALLOC freed 13K, 7% free 4163K/4444K, paused 3ms, total 4ms
04-14 02:21:18.930 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/Choreographer﹕ Skipped 103 frames! The application may be doing too much work on its main thread.
04-14 02:21:18.930 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
04-14 02:27:17.189 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 I/Choreographer﹕ Skipped 60 frames! The application may be doing too much work on its main thread.
04-14 02:27:17.309 1772-1772/com.daftnerds.juliusugochukwu.cgpa4 D/dalvikvm﹕ GC_FOR_ALLOC freed 168K, 7% free 4507K/4796K, paused 2ms, total 2ms
04-14 02:29:34.831 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
Now, once i click the button to start the new activity, this happens
04-14 02:30:40.562 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 D/AndroidRuntime﹕ Shutting down VM
04-14 02:30:40.562 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0d3cb20)
04-14 02:30:40.602 2264-2264/com.daftnerds.juliusugochukwu.cgpa4 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.daftnerds.juliusugochukwu.cgpa4, PID: 2264
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.daftnerds.juliusugochukwu.cgpa4/com.daftnerds.juliusugochukwu.cgpa4.firstYearSecondSemester2}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.daftnerds.juliusugochukwu.cgpa4.firstYearSecondSemester2.onCreate(firstYearSecondSemester2.java:76)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
change line with
spinner0.setAdapter(new NothingSelectedSpinnerAdapter(each_grade,R.layout.contact_spinner_row_nothing_selected,this));
and clean your project once.
Omg...found the problem. Truly it was line 76. Please don't be annoyed. I initially had 9 spinners in the main activity and 7 in the new activity. I copied the main activity spinner codes and pasted in the new activity. So when it gets to the 8th spinner (line 76), it gives an error since that spinner is not available in the layout. Thanks for all the help suggested guys...really appreciate them.

Categories