Related
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
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 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).
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.
This question already has answers here:
How can I fix 'android.os.NetworkOnMainThreadException'?
(66 answers)
Closed 8 years ago.
I'm new to android application development and i want to send three parameters Latitude ,
Longitude and Bimari(which i am mentioning in
my code below) to phpMyAdmin server via internet.
The problem is that after selecting bimari from
spinner when i click send button my app crashes.
My server side is working correctly.Can anyone
please tell me why i can't send my data to server ?
Thanks alot for reading !
MainActivity.java is as follows:-
public final static String EXTRA_MESSAGE = "com.example.sushma.myfirstapp.MESSAGE";
String nn, nn1, nn2, nn3, nn4, nn5, nnf; // used to make URL
String sss1, sss2; // used to convert lat and long to string
String s; // used to save bimari as string
double lat, lng;
LocationManager lm;
String provider;
Location l;
private View view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Criteria c = new Criteria();
provider = lm.getBestProvider(c, false);
l = lm.getLastKnownLocation(provider);
if (l != null) {
//get latitude and longitude of the location
lng = l.getLongitude();
lat = l.getLatitude();
} else {
System.out.println("No lat/long");
}
{
LinearLayout l1 = new LinearLayout(this);
l1.setBackgroundResource(R.drawable.ambulance);
setContentView(R.layout.activity_main);
}
}
public void ongobuttonclick(View view) {
this.view = view;
Spinner sp = (Spinner) findViewById(R.id.problems);
s = sp.getSelectedItem().toString();
sss1 = String.valueOf(lng);
sss2 = String.valueOf(lat);
nn = "http://192.168.2.8/tech/new_predict.php?Latitude=";
nn1 = sss2;
nn2 = "&Longitude=";
nn3 = sss1;
nn4 = "&Bimari=";
nn5 = s;
nnf = nn + nn1 + nn2 + nn3 + nn4 + nn5;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httPost = new HttpPost(nnf);
System.out.println(nnf);
new Thread(new Runnable() {
#Override
public void run() {
try {
httpclient.execute(httPost);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
#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_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Logcat
01-26 19:32:22.859 14247-14247/com.example.sushma.myfirstapp E/ViewRootImpl﹕ sendUserActionEvent() mView == null
01-26 19:32:29.085 14247-14247/com.example.sushma.myfirstapp D/AndroidRuntime﹕ Shutting down VM
01-26 19:32:29.085 14247-14247/com.example.sushma.myfirstapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40da9930)
01-26 19:32:29.105 14247-14247/com.example.sushma.myfirstapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3804)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3799)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:842)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.example.sushma.myfirstapp.MainActivity.ongobuttonclick(MainActivity.java:176)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3799)
at android.view.View.performClick(View.java:4439)
at android.widget.Button.performClick(Button.java:139)
at android.view.View$PerformClick.run(View.java:18395)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
NewLogcat
01-26 22:45:48.807 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
01-26 22:45:48.807 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11750: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 11756: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 9401: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
01-26 22:45:48.867 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 534: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp W/dalvikvm﹕ VFY: unable to resolve virtual method 556: Landroid/content/res/TypedArray;.getType (I)I
01-26 22:45:48.887 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
01-26 22:45:48.947 23318-23318/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_FOR_ALLOC freed 157K, 13% free 8676K/9872K, paused 24ms, total 24ms
01-26 22:45:48.957 23318-23318/com.example.sushma.myfirstapp I/dalvikvm-heap﹕ Grow heap (frag case) to 10.654MB for 1228816-byte allocation
01-26 22:45:48.967 23318-23329/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_FOR_ALLOC freed 1K, 11% free 9875K/11076K, paused 14ms, total 14ms
01-26 22:45:49.007 23318-23323/com.example.sushma.myfirstapp E/dalvikvm﹕ adjustAdaptiveCoef max=4194304, min=1048576, ut=568
01-26 22:45:49.007 23318-23323/com.example.sushma.myfirstapp D/dalvikvm﹕ GC_CONCURRENT freed 4K, 11% free 9871K/11076K, paused 16ms+3ms, total 40ms
01-26 22:45:49.257 23318-23318/com.example.sushma.myfirstapp D/libEGL﹕ loaded /system/lib/egl/libGLES_hawaii.so
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ mem_init ++
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ gHwMemAllocator client 3
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ **** Using ION allocator ****
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ registered SIGUSR1[10] for pid[23318]
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ HwMemAllocatorImpl Static Counters 0 0
01-26 22:45:49.267 23318-23318/com.example.sushma.myfirstapp D/﹕ HwMemAllocatorImpl[490a9dcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/﹕ mem_init 490a9dcc--
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/ION﹕ config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/MM_DEVICE﹕ Waiting for mm thread to come up
01-26 22:45:49.277 23318-23346/com.example.sushma.myfirstapp D/MM_DEVICE﹕ mm_device_thread starting
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateContext() config: 18 context: 0x4f3c4db8, VC context 1, Thread 23318
01-26 22:45:49.277 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ Set SWAP INTERVAL 0
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4beeea48, VC surface: 1, Thread: 23318
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:49.287 23318-23318/com.example.sushma.myfirstapp D/OpenGLRenderer﹕ Enabling debug mode 0
01-26 22:45:50.849 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ Get MotionRecognitionManager
01-26 22:45:50.959 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ Set SWAP INTERVAL 0
01-26 22:45:50.969 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4c0f1be8, VC surface: 2, Thread: 23318
01-26 22:45:50.969 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:50.989 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:50.999 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:51.079 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ unregisterIRListener() is called
01-26 22:45:51.089 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:52.150 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4c0f1be8, 0x4c0f1be8) Thread: 23318
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/AbsListView﹕ onDetachedFromWindow
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(NULL) Thread: 23318
01-26 22:45:52.791 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglDestroySurface() surface: 0x4c0f1be8, android window 0x4c05c8f8, Thread: 23318
01-26 22:45:52.811 23318-23318/com.example.sushma.myfirstapp D/HAWAII_EGL﹕ eglMakeCurrent(0x4f3c4db8, 0x4beeea48, 0x4beeea48) Thread: 23318
01-26 22:45:52.871 23318-23318/com.example.sushma.myfirstapp E/ViewRootImpl﹕ sendUserActionEvent() mView == null
01-26 22:45:53.802 23318-23318/com.example.sushma.myfirstapp I/System.out﹕ http://192.168.2.8/tech/new_predict.php?Latitude=31.310573780338718&Longitude=75.55498407042245&Bimari=Bones
01-26 22:45:56.945 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.2.8 refused
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at com.example.sushma.myfirstapp.MainActivity$1.run(MainActivity.java:173)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.lang.Thread.run(Thread.java:856)
01-26 22:45:56.955 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ Caused by: java.net.ConnectException: failed to connect to /192.168.2.8 (port 80): connect failed: EHOSTUNREACH (No route to host)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:114)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at java.net.Socket.connect(Socket.java:842)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ ... 8 more
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ Caused by: libcore.io.ErrnoException: connect failed: EHOSTUNREACH (No route to host)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.Posix.connect(Native Method)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:112)
01-26 22:45:56.965 23318-23498/com.example.sushma.myfirstapp W/System.err﹕ ... 13 more
You tried execute httpclient.execute(httPost); method in UI thread. You can not do this.
You can use AsyncTask to resolve this issue.
public void ongobuttonclick(View view) {
...
//your code
//use AsyncTask if you want ot inform ui thread
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httPost = new HttpPost(nnf);
new AsyncTask<HttpPost, Void, HttpResponse>() {
//YourParams, YourProgress, YourResult can be Void
#Override
protected HttpResponse doInBackground(HttpPost... params) {
HttpResponse response = null;
try {
response = httpclient.execute(params[0]);
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
#Override
protected void onPostExecute(HttpResponse response) {
if(response != null){
//do sth in UI thread
}
}
}.execute(httPost);
//or in new thread if you doesn't want ot inform ui thread
new Thread(new Runnable() {
#Override
public void run() {
try {
httpclient.execute(httPost);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}