I'm developing an Android app but as I am a newbie so can't figure out the solution to the problem. My application crashes when I install it on my Phone (Android 4.3) while it runs fine on the emulator. Though, I know that it crashes when I initialize my Bluetooth Adapter mBluetoothAdapter, but dont know the solution.
public class MainActivity extends ActionBarActivity {
protected static final int REQUEST_ENABLE_BT = 1;
Button btnConnect;
int seekVal;
SeekBar seek ;
TextView editText1;
BluetoothAdapter mBluetoothAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnConnect = (Button)findViewById(R.id.btnConnect);
editText1 = (TextView)findViewById(R.id.editText1);
seekVal = 0;
seek = (SeekBar)findViewById(R.id.seekBar1);
editText1.setText(String.valueOf(0));
// Crashes when Bluetooth Adapter is initialized
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// App runs when the above line is commented out
try{
if (mBluetoothAdapter == null) {
Toast.makeText(getApplicationContext(), "Your device does not support bluetooth device. Sorry but the application will exit now!", Toast.LENGTH_SHORT).show();
btnConnect.setEnabled(false);
}
else
{
if (mBluetoothAdapter.isEnabled()) {
btnConnect.setEnabled(false);
}
}
}
catch(Exception ex)
{
}
btnConnect.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
}
Here is a part of my MANIFEST
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="21" />
<permission android:name="android.permission.BLUETOOTH"></permission>
Here is my LogCat
01-10 14:55:56.142: E/ResourceType(1027): Style contains key with bad entry: 0x01010479
01-10 14:55:56.392: I/dalvikvm(1027): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
01-10 14:55:56.392: W/dalvikvm(1027): VFY: unable to resolve virtual method 11341: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
01-10 14:55:56.404: D/dalvikvm(1027): VFY: replacing opcode 0x6f at 0x0000
01-10 14:55:56.412: I/dalvikvm(1027): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
01-10 14:55:56.412: W/dalvikvm(1027): VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
01-10 14:55:56.423: D/dalvikvm(1027): VFY: replacing opcode 0x6f at 0x0000
01-10 14:55:56.423: I/dalvikvm(1027): Could not find method android.view.ViewGroup.onWindowSystemUiVisibilityChanged, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onWindowSystemUiVisibilityChanged
01-10 14:55:56.423: W/dalvikvm(1027): VFY: unable to resolve virtual method 11349: Landroid/view/ViewGroup;.onWindowSystemUiVisibilityChanged (I)V
01-10 14:55:56.423: D/dalvikvm(1027): VFY: replacing opcode 0x6f at 0x0008
01-10 14:55:56.442: I/dalvikvm(1027): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
01-10 14:55:56.442: W/dalvikvm(1027): VFY: unable to resolve virtual method 9035: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
01-10 14:55:56.453: D/dalvikvm(1027): VFY: replacing opcode 0x6e at 0x000e
01-10 14:55:56.662: I/dalvikvm(1027): Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
01-10 14:55:56.671: W/dalvikvm(1027): VFY: unable to resolve virtual method 11344: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
01-10 14:55:56.671: D/dalvikvm(1027): VFY: replacing opcode 0x6f at 0x0007
01-10 14:55:56.711: I/dalvikvm(1027): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
01-10 14:55:56.711: W/dalvikvm(1027): VFY: unable to resolve virtual method 366: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-10 14:55:56.711: D/dalvikvm(1027): VFY: replacing opcode 0x6e at 0x0002
01-10 14:55:56.722: I/dalvikvm(1027): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
01-10 14:55:56.722: W/dalvikvm(1027): VFY: unable to resolve virtual method 388: Landroid/content/res/TypedArray;.getType (I)I
01-10 14:55:56.722: D/dalvikvm(1027): VFY: replacing opcode 0x6e at 0x0002
01-10 14:55:58.262: D/dalvikvm(1027): GC_CONCURRENT freed 196K, 5% free 7098K/7431K, paused 8ms+5ms
01-10 14:55:58.492: D/gralloc_goldfish(1027): Emulator without GPU emulation detected.
Basically the problem was of insufficient user permission in the Manifest
https://stackoverflow.com/a/11469502/1584140 helped me to use try catch for getting the actual error.
Finally I solved my issue by setting up the permissions like this.
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
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
Hi everyone I am new in Java programming and in the android studio environment and I need your help.
I am building an application that demands storing records of appointments into a database. I have created navigation between the activity's and I have also create a class named DBhandler which is about create update and delete records so far so good but the moment I add the following part of code in the activity that is about to create a new row in the database:
DBHandler db = new DBHandler(this);
db.NewApointment(new Apointments(23123,text2,text3,text4,text5));
Intent sendIntent = new Intent(Create_Apointment.this, Records.class);
startActivity(sendIntent);
The application for some reason stops working. I did research for my problem but I did not found anything similar to my problem, could it be a bug of android studio or am I missing something? I will show you my whole code just make to easier to you
This is my main activity
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void CreateApo(View view)
{
Intent i = new Intent(MainActivity.this, Create_Apointment.class);
startActivity(i);
}
public void Edit_Apointment(View v)
{
Intent intent = new Intent(MainActivity.this, Records.class);
startActivity(intent);
}
}
This is the activity which is used to store a new appointment
public class Create_Apointment extends AppCompatActivity {
EditText editText=(EditText) findViewById(R.id.editText);
EditText editText2=(EditText) findViewById(R.id.editText2);
EditText editText3=(EditText) findViewById(R.id.editText3);
EditText editText4=(EditText) findViewById(R.id.editText4);
String text2= editText.getText().toString();
String text3= editText2.getText().toString();
String text4= editText3.getText().toString();
String text5= editText4.getText().toString();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create__apointment);
}
public void back(View view)
{
Intent i = new Intent(Create_Apointment.this, MainActivity.class);
startActivity(i);
}
public void Create(View view)
{
DBHandler db = new DBHandler(this);
db.NewApointment(new Apointments(23123,text2,text3,text4,text5));
Intent sendIntent = new Intent(Create_Apointment.this, Katagrafes.class);
startActivity(sendIntent);
}
}
The following code is for the management of the database
public class DBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION=1;
//DATABASE NAME
private static final String DATABASE_NAME="APOINTMENTINFO";
private static final String APOINTMENT_TABLE="APOINTMENTS";
//Column NAMES
private static final String KEY_ID="id";
private static final String KEY_NAME="Name";
private static final String KEY_ADDRESS="Address";
private static final String KEY_PLACE="Place";
private static final String KEY_WRA="WRA";
public DBHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db)
{
String Create_APOINTMENTS_TABLE= "CREATE TABLE"+ APOINTMENT_TABLE + "(" + KEY_ID +"INTERGER PRIMARY KEY,"+ KEY_NAME + "TEXT," +KEY_ADDRESS + "TEXT," + KEY_PLACE+"TEXT,"+ KEY_WRA+"TEXT" + ")";
db.execSQL(Create_APOINTMENTS_TABLE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion)
{
db.execSQL("DROP TABLE IF EXISTS " + APOINTMENT_TABLE );
onCreate(db);
}
//add-insert new apointment
public void NewApointment(Apointments apointments)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values= new ContentValues();
values.put(KEY_NAME, apointments.getName()); //ONOMA RADEVOY
values.put(KEY_ADDRESS, apointments.getAddress());// adress
values.put(KEY_PLACE, apointments.getPlace());//meros
values.put(KEY_WRA, apointments.getWraRad());//wra
db.insert(APOINTMENT_TABLE, null ,values);
db.close();
}
// read 1 record
public Apointments getApointment(int id )
{
SQLiteDatabase db= this.getReadableDatabase();
Cursor cursor = db.query(APOINTMENT_TABLE, new String[]{KEY_ID, KEY_NAME,KEY_ADDRESS,KEY_PLACE,KEY_WRA},KEY_ID+"=?",new String[]{String.valueOf(id)},null,null,null,null );
if (cursor !=null)
cursor.moveToFirst();
Apointments contact = new Apointments(Integer.parseInt(cursor.getString(0)),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4));
//return apointment
return contact;
}
public List<Apointments> getAllApointments()
{
List<Apointments> apointmentsList= new ArrayList<Apointments>();
//selection of all querys
String selectQuery = "SELECT * FROM "+ APOINTMENT_TABLE;
SQLiteDatabase db= this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery,null);
if (cursor.moveToFirst())
{
do {
Apointments apointments = new Apointments(Integer.parseInt(cursor.getString(0)),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4));
}while (cursor.moveToNext());
}
return apointmentsList;
}
public int updateApointment(Apointments apointments)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME,apointments.getName());
values.put(KEY_ADDRESS,apointments.getName());
values.put(KEY_PLACE,apointments.getPlace());
values.put(KEY_WRA,apointments.getWraRad());
//update row
return db.update(APOINTMENT_TABLE,values, KEY_ID + " =?", new String[] {String.valueOf(apointments.getId())} );
}
//delete records
public void deleteapoitnments (Apointments apointments)
{
SQLiteDatabase db= this.getWritableDatabase();
db.delete(APOINTMENT_TABLE,KEY_ID+"=?", new String[]{String.valueOf(apointments.getId())} );
db.close();
}
}
Also I have create a class named "appointments" to refer an appointment as an object in my application.
public class Apointments {
private int id;
private String Name;
private String Address;
private String Place;
private String WraRad;
public Apointments(int id, String Name, String Address, String Place, String WraRad )
{
this.id=id;
this.Name=Name;
this.Address=Address;
this.Place=Place;
this.WraRad=WraRad;
}
public void setId(int id) {
this.id = id;
}
public void setName(String Name) {
this.Name=Name;
}
public void setAddress(String Address) {
this.Address=Address;
}
public void setPlace(String Place) {
this.Place=Place;
}
public void setWraRad(String WraRad) {
this.WraRad=WraRad;
}
public int getId()
{
return id;
}
public String getName()
{
return Name;
}
public String getAddress()
{
return Address;
}
public String getPlace()
{
return Place;
}
public String getWraRad()
{
return WraRad;
}
}
My logCat says the following:
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0ac7
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getReferrer, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 74: Landroid/app/Activity;.getReferrer ()Landroid/net/Uri;
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0b3b
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.content.ContextWrapper.getSystemServiceName, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 517: Landroid/content/ContextWrapper;.getSystemServiceName (Ljava/lang/Class;)Ljava/lang/String;
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0bb8
08-30 16:34:26.479 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.isVoiceInteractionRoot, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 98: Landroid/app/Activity;.isVoiceInteractionRoot ()Z
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0be0
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.isDestroyed, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 93: Landroid/app/Activity;.isDestroyed ()Z
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0beb
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve check-cast 236 (Landroid/os/UserHandle;) in Lcom/example/dim/myapplication/Create_Apointment;
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0c3b
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.content.ContextWrapper.getExternalMediaDirs, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 504: Landroid/content/ContextWrapper;.getExternalMediaDirs ()[Ljava/io/File;
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0c68
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve check-cast 236 (Landroid/os/UserHandle;) in Lcom/example/dim/myapplication/Create_Apointment;
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0ca4
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getMediaController, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 68: Landroid/app/Activity;.getMediaController ()Landroid/media/session/MediaController;
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0cac
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.finishAffinity, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 48: Landroid/app/Activity;.finishAffinity ()V
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0cb2
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getSearchEvent, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 77: Landroid/app/Activity;.getSearchEvent ()Landroid/view/SearchEvent;
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0d2b
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/FragmentActivity;.onReallyStop ()V from Lcom/example/dim/myapplication/Create_Apointment;)
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.support.v4.app.FragmentActivity.onReallyStop, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 2396: Landroid/support/v4/app/FragmentActivity;.onReallyStop ()V
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0d6b
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.isVoiceInteraction, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 97: Landroid/app/Activity;.isVoiceInteraction ()Z
08-30 16:34:26.489 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0ddb
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.requestVisibleBehind, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 169: Landroid/app/Activity;.requestVisibleBehind (Z)Z
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e40
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.shouldShowRequestPermissionRationale, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 199: Landroid/app/Activity;.shouldShowRequestPermissionRationale (Ljava/lang/String;)Z
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e55
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.onProvideAssistData, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 141: Landroid/app/Activity;.onProvideAssistData (Landroid/os/Bundle;)V
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e6a
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.finishAndRemoveTask, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 50: Landroid/app/Activity;.finishAndRemoveTask ()V
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0e92
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.content.Context.getColor, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 425: Landroid/content/Context;.getColor (I)I
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0ee9
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.onNavigateUp, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 131: Landroid/app/Activity;.onNavigateUp ()Z
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0efa
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.reportFullyDrawn, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 167: Landroid/app/Activity;.reportFullyDrawn ()V
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0f17
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getParentActivityIntent, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 72: Landroid/app/Activity;.getParentActivityIntent ()Landroid/content/Intent;
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0f1d
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve check-cast 53 (Landroid/app/assist/AssistContent;) in Lcom/example/dim/myapplication/Create_Apointment;
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x1f at 0x0f5b
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.finishAfterTransition, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication W/dalvikvm: VFY: unable to resolve virtual method 49: Landroid/app/Activity;.finishAfterTransition ()V
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication D/dalvikvm: VFY: replacing opcode 0x6f at 0x0f7f
08-30 16:34:26.499 12295-12295/com.example.dim.myapplication I/dalvikvm: Could not find method android.app.Activity.getContentScene, referenced from method com.example.dim.myapplication.Create_Apointment.access$super
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.dim.myapplication/com.example.dim.myapplication.Create_Apointment}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
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:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.app.AppCompatDelegateImplBase.(AppCompatDelegateImplBase.java:68)
at android.support.v7.app.AppCompatDelegateImplV7.(AppCompatDelegateImplV7.java:145)
at android.support.v7.app.AppCompatDelegateImplV11.(AppCompatDelegateImplV11.java:28)
at android.support.v7.app.AppCompatDelegateImplV14.(AppCompatDelegateImplV14.java:41)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:188)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:170)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:502)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:174)
at com.example.dim.myapplication.Create_Apointment.(Create_Apointment.java:13)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
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:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Any suggestions would be very helpful feel free to comment if something of my question is wrong
Thanks in advance
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).
I am new to Android so please explain this in detail
I am building an App which displays 2 simple Tabs.
My code is:
ActionBarImpl.java
package com.adhish.tabs1;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.util.Log;
public class ActionBarImpl extends ActionBarActivity {
public static Context myContext;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_bar);
myContext = getApplicationContext();
try
{
ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tab1 = actionbar.newTab().setText("Tab 1");
Tab tab2 = actionbar.newTab().setText("Tab 2");
Fragment fragment1 = new FirstFragment();
Fragment fragment2 = new SecondFragment();
tab1.setTabListener(new MyTabsListener(fragment1));
tab2.setTabListener(new MyTabsListener(fragment2));
actionbar.addTab(tab1);
actionbar.addTab(tab2);
}
catch (Exception e)
{
Log.e("Error !", e.toString());
Log.e("StackTrace..",e.getStackTrace().toString());
}
}
}
MyTabsListener.java
#SuppressLint("NewApi")
public class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
//Create fragment for Activity
public MyTabsListener(Fragment fragment)
{
this.fragment = fragment;
}
#Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction transaction)
{
Toast.makeText(ActionBarImpl.myContext, "You have clicked again !", Toast.LENGTH_SHORT).show();
}
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction transaction)
{
transaction.replace(R.id.actionbar, fragment);
}
#Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction transaction)
{
transaction.remove(fragment);
}
}
FirstFragment and SecondFragment.java
#SuppressLint("NewApi")
public class FirstFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first, container, false);
}
}
The Fragments contain a TextView to Display.
But whenever i run the App, I cannot see any of the tabs at all.
I don't understand why, because the code is according to Android Black Book.
PLEASE HELP
EDIT: LogCat
03-02 16:16:12.111 25889-25889/com.adhish.tabs1 E/dalvikvm﹕ dvmPauseGc(AppLaunch) called - cookie=0x1cc7 (f=0x1)
03-02 16:16:12.121 25889-25889/com.adhish.tabs1 I/PersonaManager﹕ getPersonaService() name persona_policy
03-02 16:16:12.156 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:48 height:48 bitmap id is 180
03-02 16:16:12.181 25889-25889/com.adhish.tabs1 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
03-02 16:16:12.181 25889-25889/com.adhish.tabs1 W/dalvikvm﹕ VFY: unable to resolve virtual method 11352: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
03-02 16:16:12.181 25889-25889/com.adhish.tabs1 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-02 16:16:12.181 25889-25889/com.adhish.tabs1 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
03-02 16:16:12.181 25889-25889/com.adhish.tabs1 W/dalvikvm﹕ VFY: unable to resolve virtual method 11358: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
03-02 16:16:12.181 25889-25889/com.adhish.tabs1 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
03-02 16:16:12.186 25889-25889/com.adhish.tabs1 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
03-02 16:16:12.186 25889-25889/com.adhish.tabs1 W/dalvikvm﹕ VFY: unable to resolve virtual method 9046: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
03-02 16:16:12.186 25889-25889/com.adhish.tabs1 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
03-02 16:16:12.191 25889-25889/com.adhish.tabs1 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
03-02 16:16:12.191 25889-25889/com.adhish.tabs1 W/dalvikvm﹕ VFY: unable to resolve virtual method 372: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-02 16:16:12.191 25889-25889/com.adhish.tabs1 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-02 16:16:12.191 25889-25889/com.adhish.tabs1 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-02 16:16:12.191 25889-25889/com.adhish.tabs1 W/dalvikvm﹕ VFY: unable to resolve virtual method 394: Landroid/content/res/TypedArray;.getType (I)I
03-02 16:16:12.191 25889-25889/com.adhish.tabs1 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-02 16:16:12.191 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:72 height:72 bitmap id is 181
03-02 16:16:12.196 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:42 height:126 bitmap id is 182
03-02 16:16:12.201 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:18 height:18 bitmap id is 183
03-02 16:16:12.201 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:18 height:18 bitmap id is 184
03-02 16:16:12.206 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:18 height:18 bitmap id is 185
03-02 16:16:12.211 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:72 height:72 bitmap id is 186
03-02 16:16:12.216 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:72 height:72 bitmap id is 187
03-02 16:16:12.226 25889-25889/com.adhish.tabs1 E/Error !﹕ java.lang.NullPointerException
03-02 16:16:12.226 25889-25889/com.adhish.tabs1 E/StackTrace..﹕ [Ljava.lang.StackTraceElement;#42820020
03-02 16:16:12.321 25889-25889/com.adhish.tabs1 I/﹕ PLATFORM VERSION : JB-MR-2
03-02 16:16:12.361 25889-25889/com.adhish.tabs1 I/HWUI﹕ EGLImpl-HWUI Protected EGL context created
03-02 16:16:12.466 25889-25889/com.adhish.tabs1 D/OpenGLRenderer﹕ Enabling debug mode 0
03-02 16:16:12.491 25889-25889/com.adhish.tabs1 D/skia﹕ GFXPNG PNG bitmap created width:72 height:72 bitmap id is 188
03-02 16:16:12.531 25889-25889/com.adhish.tabs1 E/dalvikvm﹕ dvmResumeGc(0x1cc7, 0) called (f=0x1)
PLEASE HELP
Firstly your activity extends ActionBarActivity, so to get ActionBar should be:
ActionBar actionbar = getSupportActionBar()
And in your TabListener better use codes like:
private ActionBarActivity mActivity;
private String mTag;
//constructor
public MyTabsListener(ActionBarActivity activity, String tag, Fragment fragment)
{
this.fragment = fragment;
mActivity = activity;
mTag = tag;
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// Check if the fragment is already initialized
FragmentTransaction mft = mActivity.getSupportFragmentManager().beginTransaction();
Fragment mFragment = mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
if(mFragment != null)
{
mft.attach(fragment).commit();
}
else
{
mft.add(R.id.actionbar, fragment, mTag).commit();
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
FragmentTransaction mft = mActivity.getSupportFragmentManager().beginTransaction();
mFragment = mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
if (mFragment != null) {
mft.detach(mFragment).commit();
}
besides, you need change your MyTabsListener calling codes in your activity's onCreate:
tab1.setTabListener(new MyTabsListener(this, "Frist_Frag", fragment1));
tab2.setTabListener(new MyTabsListener(this, "Second_Frag", fragment2));
First_Frag and Second_Frag are fragment tags, you can use yours.