so, I'm getting an error after trying to load a tab in a Master/Flow layout. The tab that makes the app crash is a calculator with two images and a background image.
Here's the error:
04-23 09:21:40.609 1157-1157/endangeredspecies.androidbootcamp.net.finalproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: endangeredspecies.androidbootcamp.net.finalproject, PID: 1157
android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at endangeredspecies.androidbootcamp.net.finalproject.ItemDetailFragment.onCreateView(ItemDetailFragment.java:66)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
And this is where it is telling me the error is (ItemDetailFragment.java:66):
it is "rootView = inflater.inflate(R.layout.price_calculator, container, false);"
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
if (mItem !=null) {
if (mItem.id.equals("1")) {
rootView = inflater.inflate(R.layout.welcome_page, container, false);
} else if (mItem.id.equals("2")) {
rootView = inflater.inflate(R.layout.price_calculator, container, false);
} else if (mItem.id.equals("3")) {
((WebView) rootView.findViewById(R.id.item_Detail)).loadUrl(mItem.item_url);
}
}
return rootView;
}
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#mipmap/calc_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtCalc"
android:id="#+id/textView2"
android:layout_marginTop="47dp"
android:textSize="50dp"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/textView3"
android:textColor="#ff000000" />
<ImageView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/imageView3"
android:src="#mipmap/spiderman_1"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="-10dp" />
<ImageView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:src="#mipmap/hulk"
android:layout_marginTop="279dp"
android:layout_below="#+id/textView2"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtAdults"
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_toEndOf="#+id/imageView4"
android:layout_marginTop="111dp"
android:textSize="30dp"
android:textColor="#ff000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtChildern"
android:id="#+id/textView4"
android:textSize="30dp"
android:layout_below="#+id/textView3"
android:layout_alignStart="#+id/textView3"
android:layout_marginTop="20dp"
android:textColor="#ff000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/txtAdults"
android:layout_above="#+id/textView4"
android:layout_toEndOf="#+id/textView4"
android:layout_marginStart="45dp"
android:textColor="#ff000000"
android:hint="#string/txtHint1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/txtChildren"
android:layout_alignBottom="#+id/textView4"
android:layout_alignStart="#+id/txtAdults"
android:textColor="#ff000000"
android:hint="#string/txtHint2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtDays"
android:id="#+id/textView5"
android:textSize="30dp"
android:layout_below="#+id/textView4"
android:layout_alignStart="#+id/textView4"
android:layout_marginTop="20dp"
android:textColor="#ff000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/txtDays"
android:layout_alignTop="#+id/textView5"
android:layout_alignStart="#+id/txtChildren"
android:textColor="#ff000000"
android:hint="#string/txtHint3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtCalcLbl"
android:id="#+id/btnTotal"
android:layout_marginTop="57dp"
android:hint="#string/txtClickCalc"
android:textSize="20dp"
android:layout_alignTop="#+id/imageView4"
android:layout_toEndOf="#+id/textView4"
android:textColor="#ff000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtTotal"
android:id="#+id/txtResult"
android:layout_below="#+id/imageView3"
android:layout_alignStart="#+id/btnTotal"
android:textSize="30dp"
android:textColor="#ff000000" />
</RelativeLayout>
Related
i just want to fill some infos in the activitymain and then pass an intent to a second activity, at the first it works perfect but when i add some xml layout, when running the app on device and pass the intent it crashes
the main activity
public void move(View view) {
Intent i = new Intent(MainActivity.this, FormActivity.class);
EditText name = findViewById(R.id.name);
EditText animal = findViewById(R.id.animal);
String n = name.getText().toString();
String a = animal.getText().toString();
if (n.isEmpty() || a.isEmpty()) {
Toast.makeText(this, "nom ou animal est vide !", Toast.LENGTH_SHORT).show();
} else {
i.putExtra("KEY_Name", name.getText().toString());
i.putExtra("KEY_Animal", animal.getText().toString());
startActivity(i);
}
}
// and the formactivity or the second
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
Intent i = getIntent();
TextView Text1 = findViewById(R.id.t1);
TextView Text2 = findViewById(R.id.t2);
String name = i.getStringExtra("KEY_Name");
String animal = i.getStringExtra("KEY_Animal");
Text1.setText(name);
Text2.setText(animal);
}
// XML file for activity_main it works perfect
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/dog" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="40dp"
android:src="#drawable/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/hello"
android:textColor="#ffffff"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:layout_constraintVertical_bias="0.075" />
<LinearLayout
android:id="#+id/linear1"
style="#style/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/name"
android:textColor="#ffffff" />
<View
android:layout_width="3dip"
android:layout_height="match_parent"
android:background="#ffffff" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="#string/ex_name"
android:inputType="textCapWords"
android:maxLines="1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#ffffff"
app:layout_constraintBottom_toTopOf="#+id/linear2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/linear2" />
<LinearLayout
android:id="#+id/linear2"
style="#style/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/pet"
android:textColor="#ffffff" />
<View
android:layout_width="3dip"
android:layout_height="match_parent"
android:background="#ffffff" />
<EditText
android:id="#+id/animal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="#string/ex_animal"
android:inputType="textCapWords"
android:maxLines="1" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:onClick="move"
android:text="Suivant"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.096"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear2"
app:layout_constraintVertical_bias="0.344" />
// the activity_form or second that crashes
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/sheep" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:foregroundGravity="center_horizontal"
android:src="#drawable/title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:background="#drawable/list_fluid"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="#+id/t1"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center_horizontal"
android:text="Hello freind!"
android:textColor="#color/green"
android:textSize="24sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:background="#ffffff" />
<TextView
android:id="#+id/t2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="oh, puppy!"
android:textColor="#color/green"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="12dp"
android:text="comment Aidez-Vous ?" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="mon Chat souffre de fièvre"
android:inputType="text"
android:lines="6"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc"
android:textSize="12sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:background="#color/logo"
android:text="envoyer"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
the logcat
10-09 18:03:08.327 29724-29724/com.example.android.workingproject W/ResourceType: Failure getting entry for 0x01080946 (t=7 e=2374) (error -75)
10-09 18:04:20.737 29724-29724/com.example.android.workingproject W/ResourceType: Failure getting entry for 0x01080946 (t=7 e=2374) (error -75)
10-09 18:04:21.538 29724-29724/com.example.android.workingproject E/art: Throwing OutOfMemoryError "Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM"
10-09 18:04:21.608 29724-29724/com.example.android.workingproject E/art: Throwing OutOfMemoryError "Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM"
10-09 18:04:21.628 29724-29724/com.example.android.workingproject E/art: li.han, Prepare to dump hprof for OOM Error !
li.han, Directory [/data/log] could not be write !
10-09 18:04:21.638 29724-29724/com.example.android.workingproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.workingproject, PID: 29724
java.lang.OutOfMemoryError: Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:837)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:656)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4056)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.loadDrawable(Resources.java:3779)
at android.content.res.TypedArray.getDrawable(TypedArray.java:776)
at android.widget.ImageView.<init>(ImageView.java:151)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.android.workingproject.FormActivity.onCreate(FormActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
At least one of the drawables referenced in your second XML file is too big.
Check the following drawables and resize them:
sheep
title
list_fluid
PNGs generally don't need to be very large. Keep them below 1600x1600 if you can, preferably 800x800.
I have a NullpointerException but i can't figure out why! please your help as i'm struggling with it :
Here's my XML resource :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_speciality_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: " />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="add:" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="phone :" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="abc abc abc" />
<TextView
android:id="#+id/textView44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="abc" />
<TextView
android:id="#+id/textView55"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="230020202" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageViewClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/close_selector" />
</RelativeLayout>
Below my Java instructions :
The setContentView is before the use of the actual TextView
final Dialog dialog = new Dialog(searchActivity.this);
dialog.setContentView(R.layout.custom_dialog);``
ImageView closeBtn =(ImageView)findViewById(R.id.imageViewClose);
closeBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
finish();
}
});
Logcat errros :
java.lang.NullPointerException
at com.itraan.Test.searchActivity$2.onItemClick(searchActivity.java:902)
at android.widget.AdapterView.performItemClick(AdapterView.java:308)
at android.widget.AbsListView.performItemClick(AbsListView.java:1483)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3485)
at android.widget.AbsListView$3.run(AbsListView.java:4843)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Thank you in advance.
I am trying to make a custom adapter for my listview, but I keep getting a RessourceNotFoundException on the same line.
Firstly, here is my adapter class code:
public class CreateProgramAdapter extends BaseAdapter {
private final LayoutInflater inflater;
private ArrayList<TrainingPass> trainingPasses;
private List<TrainingPass> items;
private int layoutResourceId;
private Context context;
public CreateProgramAdapter(Context context, List<TrainingPass> items) {
this.context = context;
this.items = items;
inflater = LayoutInflater.from(this.context);
}
#Override
public int getCount() {
return items.size();
}
#Override
public Object getItem(int position) {
return items.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
TrainingPassHolder holder;
if(convertView == null) {
convertView = inflater.inflate(R.layout.adapter_createprogram_trainingpasses_item, null);
holder = new TrainingPassHolder();
convertView.setTag(holder);
} else {
holder = (TrainingPassHolder) convertView.getTag();
}
holder.trainingPass = this.items.get(position);
holder.trainingPassRelativeLayout = (RelativeLayout) row.findViewById(R.id.trainingpass_item_relativelayout);
holder.headlineTxt = (TextView) row.findViewById(R.id.trainingpass_headline);
holder.setNoTxt = (TextView) row.findViewById(R.id.txt_trainingpass_setno);
holder.showHideIcon = (ImageView) row.findViewById(R.id.trainingpass_showhide_imageview);
holder.exerciseSearchField = (EditText) row.findViewById(R.id.trainingpass_exercise_searchfield);
holder.repsTextField = (EditText) row.findViewById(R.id.trainingpass_reps_txtfield);
holder.addSetButton = (Button) row.findViewById(R.id.add_set_button);
holder.addExerciseButton = (Button) row.findViewById(R.id.trainingpass_addexercise_button);
holder.setsListView = (ListView) row.findViewById(R.id.trainingpass_sets_listview);
holder.exercisesListView = (ListView) row.findViewById(R.id.trainingpass_exercises_listview);
holder.trainingPassRelativeLayout.setTag(holder.trainingPass);
holder.headlineTxt.setTag(holder.trainingPass);
holder.setNoTxt.setTag(holder.trainingPass);
holder.showHideIcon.setTag(holder.trainingPass);
holder.exerciseSearchField.setTag(holder.trainingPass);
holder.repsTextField.setTag(holder.trainingPass);
holder.addSetButton.setTag(holder.trainingPass);
holder.addExerciseButton.setTag(holder.trainingPass);
holder.setsListView.setTag(holder.trainingPass);
holder.exercisesListView.setTag(holder.trainingPass);
setupItems(holder);
return convertView;
}
private void setupItems(TrainingPassHolder trainingPassHolder) {
// TODO: set default values for items
}
public static class TrainingPassHolder {
TrainingPass trainingPass;
RelativeLayout trainingPassRelativeLayout;
TextView headlineTxt;
TextView setNoTxt;
ImageView showHideIcon;
EditText exerciseSearchField;
EditText repsTextField;
Button addSetButton;
Button addExerciseButton;
ListView setsListView;
ListView exercisesListView;
}
}
And here is the xml for the view, containing the listview:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.mobileplatformexam.activities.CreateProgramActivity"
android:id="#+id/relativeLayoutCreateProgram">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add training pass"
android:id="#+id/btn_add_trainingpass"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/btn_add_trainingpass_help"
android:layout_toStartOf="#+id/btn_add_trainingpass_help"
android:onClick="addTrainingPass"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\?"
android:id="#+id/btn_add_trainingpass_help"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="addTrainingPassHelp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create program"
android:id="#+id/btn_create_program"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/btn_add_trainingpass_help"
android:layout_alignEnd="#+id/btn_add_trainingpass_help"
android:onClick="createProgram"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView_trainingpasses"
android:layout_above="#+id/btn_create_program"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/btn_add_trainingpass" />
</RelativeLayout>
And the xml file with the item layout for the above listview:
<?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">
<RelativeLayout
android:id="#+id/trainingpass_item_relativelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<TextView
android:id="#+id/trainingpass_headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_alignParentTop="true"
android:text="Trainingpass"
android:textSize="26dp"
android:textColor="#android:color/white"
android:background="#android:color/holo_blue_dark"
android:height="50dp"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:layout_toLeftOf="#+id/trainingpass_showhide_imageview"
android:layout_toStartOf="#+id/trainingpass_showhide_imageview"
android:textIsSelectable="true"
android:textStyle="bold" />
<ImageView
android:id="#+id/trainingpass_showhide_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/abc_spinner_mtrl_am_alpha"
android:layout_alignParentTop="true"
android:background="#android:color/holo_blue_dark"
android:minWidth="50dp"
android:minHeight="50dp"
android:layout_alignBottom="#+id/trainingpass_headline" />
<EditText
android:id="#+id/trainingpass_exercise_searchfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/trainingpass_headline"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/trainingpass_showhide_imageview"
android:layout_alignEnd="#+id/trainingpass_showhide_imageview"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hint="Name of exercise"
android:padding="15dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/txt_trainingpass_setno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set 1"
android:textSize="20dp"
android:textColor="#android:color/black"
android:paddingRight="30dp"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:paddingBottom="10dp"
android:layout_below="#+id/trainingpass_exercise_searchfield"
android:layout_toLeftOf="#+id/trainingpass_reps_txtfield"
android:layout_toStartOf="#+id/trainingpass_reps_txtfield" />
<EditText
android:id="#+id/trainingpass_reps_txtfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Reps"
android:padding="15dp"
android:width="160dp"
android:layout_alignBottom="#+id/txt_trainingpass_setno"
android:layout_toLeftOf="#+id/add_set_button"
android:layout_toStartOf="#+id/add_set_button"
android:layout_marginRight="10dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/add_set_button"
android:text="Add set"
android:layout_alignBottom="#+id/trainingpass_reps_txtfield"
android:layout_alignRight="#+id/trainingpass_exercise_searchfield"
android:layout_alignEnd="#+id/trainingpass_exercise_searchfield"
android:layout_below="#+id/trainingpass_exercise_searchfield" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainingpass_sets_listview"
android:layout_alignLeft="#+id/trainingpass_exercise_searchfield"
android:layout_alignStart="#+id/trainingpass_exercise_searchfield"
android:layout_below="#+id/txt_trainingpass_setno" />
<Button
android:text="Add exercise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainingpass_addexercise_button"
android:layout_below="#+id/trainingpass_sets_listview"
android:layout_alignRight="#+id/add_set_button"
android:layout_alignEnd="#+id/add_set_button"
android:layout_alignLeft="#+id/trainingpass_sets_listview"
android:layout_alignStart="#+id/trainingpass_sets_listview" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainingpass_exercises_listview"
android:layout_below="#+id/trainingpass_addexercise_button"
android:layout_alignLeft="#+id/trainingpass_addexercise_button"
android:layout_alignStart="#+id/trainingpass_addexercise_button" />
</RelativeLayout>
</LinearLayout>
And this is the code for setting the adapter in my activity (extends Activity)
ArrayList<TrainingPass> trainingPasses = new ArrayList<TrainingPass>();
TrainingPass trainingPass = new TrainingPass();
trainingPass.setTrainingPassName("wefwef");
TrainingPass trainingPass2 = new TrainingPass();
trainingPass.setTrainingPassName("rwefhtr");
trainingPasses.add(trainingPass);
trainingPasses.add(trainingPass2);
ListView trainingPassesListView = (ListView)findViewById(R.id.listView_trainingpasses);
CreateProgramAdapter createProgramAdapter = new CreateProgramAdapter(CreateProgramActivity.this, trainingPasses);
trainingPassesListView.setAdapter(createProgramAdapter);
The error i am getting is this:
12661-12661/com.mobileplatformexam E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0x7f04001a
at android.content.res.Resources.getValue(Resources.java:1019)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2107)
at android.content.res.Resources.getLayout(Resources.java:858)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.mobileplatformexam.Adapters.CreateProgramAdapter.getView(CreateProgramAdapter.java:56)
at android.widget.AbsListView.obtainView(AbsListView.java:2466)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
at android.widget.ListView.onMeasure(ListView.java:1155)
at android.view.View.measure(View.java:12807)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:642)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:424)
at android.view.View.measure(View.java:12807)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12807)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:453)
at android.view.View.measure(View.java:12807)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at android.view.View.measure(View.java:12807)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1399)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:690)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:583)
at android.view.View.measure(View.java:12807)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2218)
at android.view.View.measure(View.java:12807)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1068)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2452)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4476)
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:816)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
at dalvik.system.NativeStart.main(Native Method)
The error refers to line 56 in my adapterclass, which is the following line:
convertView = inflater.inflate(R.layout.adapter_createprogram_trainingpasses_item, null);
I really can't seem to find out what may be wrong with the code, so I hope someone can help me out.
Thanks
Thanks to JafarKhQ, I solved the problem.
By changing the layout "adapter_createprogram_trainingpasses_item .xml" to the following, it worked:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/trainingpass_headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_alignParentTop="true"
android:text="Trainingpass"
android:textSize="20dp"
android:textColor="#android:color/white"
android:background="#android:color/holo_blue_dark"
android:height="30dp"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:layout_toLeftOf="#+id/trainingpass_showhide_imageview"
android:layout_toStartOf="#+id/trainingpass_showhide_imageview"
android:textIsSelectable="true"
android:textStyle="bold" />
<ImageView
android:id="#+id/trainingpass_showhide_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/abc_spinner_mtrl_am_alpha"
android:layout_alignParentTop="true"
android:background="#android:color/holo_blue_dark"
android:height="30dp"
android:minWidth="50dp"
android:layout_alignBottom="#+id/trainingpass_headline" />
<EditText
android:id="#+id/trainingpass_exercise_searchfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/trainingpass_headline"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/trainingpass_showhide_imageview"
android:layout_alignEnd="#+id/trainingpass_showhide_imageview"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hint="Name of exercise"
android:padding="15dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/txt_trainingpass_setno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set 1"
android:textSize="20dp"
android:textColor="#android:color/black"
android:paddingRight="30dp"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:paddingBottom="10dp"
android:layout_below="#+id/trainingpass_exercise_searchfield"
android:layout_toLeftOf="#+id/trainingpass_reps_txtfield"
android:layout_toStartOf="#+id/trainingpass_reps_txtfield" />
<EditText
android:id="#+id/trainingpass_reps_txtfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Reps"
android:padding="15dp"
android:width="160dp"
android:layout_alignBottom="#+id/txt_trainingpass_setno"
android:layout_toLeftOf="#+id/add_set_button"
android:layout_toStartOf="#+id/add_set_button"
android:layout_marginRight="10dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/add_set_button"
android:text="Add set"
android:layout_alignBottom="#+id/trainingpass_reps_txtfield"
android:layout_alignRight="#+id/trainingpass_exercise_searchfield"
android:layout_alignEnd="#+id/trainingpass_exercise_searchfield"
android:layout_below="#+id/trainingpass_exercise_searchfield" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainingpass_sets_listview"
android:layout_alignLeft="#+id/trainingpass_exercise_searchfield"
android:layout_alignStart="#+id/trainingpass_exercise_searchfield"
android:layout_below="#+id/txt_trainingpass_setno" />
<Button
android:text="Add exercise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainingpass_addexercise_button"
android:layout_below="#+id/trainingpass_sets_listview"
android:layout_alignRight="#+id/add_set_button"
android:layout_alignEnd="#+id/add_set_button"
android:layout_alignLeft="#+id/trainingpass_sets_listview"
android:layout_alignStart="#+id/trainingpass_sets_listview" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainingpass_exercises_listview"
android:layout_below="#+id/trainingpass_addexercise_button"
android:layout_alignLeft="#+id/trainingpass_addexercise_button"
android:layout_alignStart="#+id/trainingpass_addexercise_button" />
</RelativeLayout>
I have been trying to use the addTextChangedListener for three days, The log says that it is caused by java.lang.NullPointerException. When I comment the addTextChangedListener block the program runs fine.
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class calc extends ActionBarActivity {
EditText text;
private TextView textout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc);
text = (EditText) findViewById(R.id.fs);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
text.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
#Override
public void afterTextChanged(Editable s) {
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.calc, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_calc, container, false);
return rootView;
}
}
}
And here we have the log.
01-09 16:03:12.280 1088-1088/com.fuzato.buckconverter E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.fuzato.buckconverter, PID: 1088
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fuzato.buckconverter/com.fuzato.buckconverter.calc}: 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.fuzato.buckconverter.calc.onCreate(calc.java:39)
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)
The log says that the problem is found in onCreate and it is caused by a java.lang.NullPointerException.
Any thoughts?
Thanks for everything!
Layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="false">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="61dp"
android:layout_marginTop="43dp"
android:id="#+id/gridLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Switching Freq. (Fs)"
android:id="#+id/fs"
android:layout_row="0"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Output Voltage (V2)"
android:id="#+id/V2"
android:layout_row="1"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/V2"
android:layout_row="1"
android:layout_column="1"
android:text="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Volts"
android:id="#+id/textView12"
android:layout_row="1"
android:layout_column="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Input Voltage (V1)"
android:id="#+id/textView3"
android:layout_row="2"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/V1"
android:layout_row="2"
android:layout_column="1"
android:text="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Volts"
android:id="#+id/textView13"
android:layout_row="2"
android:layout_column="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Duty Cycle (k)"
android:id="#+id/k"
android:layout_row="3"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/k"
android:layout_row="3"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Ripple (ΔI)"
android:id="#+id/textView5"
android:layout_row="4"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/deltaI"
android:layout_row="4"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amps"
android:id="#+id/textView15"
android:layout_row="4"
android:layout_column="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Voltage Ripple (ΔV)"
android:id="#+id/textView6"
android:layout_row="5"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/deltaV"
android:layout_row="5"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Volts"
android:id="#+id/textView16"
android:layout_row="5"
android:layout_column="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Max current (Imax)"
android:id="#+id/Imax"
android:layout_row="6"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/Imax"
android:layout_row="6"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amps"
android:id="#+id/textView17"
android:layout_row="6"
android:layout_column="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Min Current (Imin)"
android:id="#+id/Imin"
android:layout_row="7"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/Imin"
android:layout_row="7"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amps"
android:id="#+id/textView18"
android:layout_row="7"
android:layout_column="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inductance (L)"
android:id="#+id/Ind"
android:layout_row="8"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/L"
android:layout_row="8"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mH"
android:id="#+id/textView19"
android:layout_row="8"
android:layout_column="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capacitance (C)"
android:id="#+id/cap"
android:layout_row="9"
android:layout_column="0" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/fs"
android:layout_row="0"
android:layout_column="1"
android:text="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hz"
android:id="#+id/textView11"
android:layout_row="0"
android:layout_column="2" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/C"
android:layout_row="9"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="uF"
android:id="#+id/textView20"
android:layout_row="9"
android:layout_column="2" />
</GridLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/gridLayout"
android:id="#+id/relativeLayout">
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="apply"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/enter"
android:layout_below="#+id/relativeLayout"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="94dp"
android:text="3" />
</RelativeLayout>
I have also tried to debbug it in my phone, I get the same problem.
I'm not entirely sure why you app compiles in the first place, but the problem initially was that your findViewById() method was returning null because it couldn't find a view matching your ID.
Your current issues include:
- Your text object is declared as TextView while it should be an
EditText
- In your layout, your view with id R.id.fs is a TextView when it should be an EditText.
try change TextView text; to EditText text;
I found the problem.
My layout was on fragment_main, sorry!
Thanks for the help!!
Here is the Java Code
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_create_report, container, false);
activity = getActivity();
Spinner spinner = (Spinner) rootView.findViewById(R.id.spinnerComplaintType);
ArrayAdapter<String> adapterComplaint = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, R.array.complaintType);
adapterComplaint.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(adapterComplaint);
spinnerComplaintType.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
complaintType = parent.getItemAtPosition(position).toString();
// Toast.makeText(getApplicationContext(), complaintType, Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
return rootView;
}
Here is the XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="833dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginLeft="24dp"
android:layout_marginTop="54dp"
android:text="Complaint Type: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/spinnerComplaintType"
android:layout_marginTop="15dp"
android:text="Vehicle Type"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinnerVehicleType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView3"
android:layout_toRightOf="#+id/textView2"
android:textColor="#000000" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/spinnerVehicleType"
android:layout_marginTop="21dp"
android:text="Body No:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextBodyNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView4"
android:layout_centerHorizontal="true"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPlate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editTextBodyNo"
android:layout_alignTop="#+id/textView5"
android:ems="10" />
<EditText
android:id="#+id/editTextDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editTextLocation"
android:layout_alignTop="#+id/textView7"
android:ems="10" />
<EditText
android:id="#+id/editTextComplaintDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editTextDate"
android:layout_alignTop="#+id/textView8"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView5"
android:layout_below="#+id/textView5"
android:layout_marginTop="58dp"
android:text="Location"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_below="#+id/textView4"
android:layout_marginTop="55dp"
android:text="Plate No:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView5"
android:layout_below="#+id/editTextLocation"
android:layout_marginTop="30dp"
android:text="Date of Incident"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView7"
android:layout_below="#+id/editTextDate"
android:layout_marginTop="28dp"
android:text="Complaint Details"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editTextLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editTextPlate"
android:layout_alignTop="#+id/textView6"
android:ems="10" />
<ImageView
android:id="#+id/imageViewPhotoReport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/buttonCamera"
android:layout_below="#+id/buttonCamera"
android:src="#drawable/about"
android:visibility="invisible"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:text="File Complaint"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/buttonCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/buttonSend"
android:layout_toLeftOf="#+id/spinnerVehicleType"
android:text="Take Photo" />
<Button
android:id="#+id/buttonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editTextComplaintDetails"
android:layout_marginTop="48dp"
android:layout_toRightOf="#+id/textView1"
android:text="SEND" />
<Button
android:id="#+id/buttonDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editTextComplaintDetails"
android:layout_below="#+id/editTextComplaintDetails"
android:layout_marginTop="20dp"
android:text="pick date" />
<Spinner
android:id="#+id/spinnerComplaintType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView1"
android:layout_toRightOf="#+id/textView3"
android:textColor="#000000" />
</RelativeLayout>
</ScrollView>
Here is the Error
Log Trace
01-04 21:18:36.513: E/AndroidRuntime(3772): FATAL EXCEPTION: main
01-04 21:18:36.513: E/AndroidRuntime(3772): java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Spinner
01-04 21:18:36.513: E/AndroidRuntime(3772): at info.androidhive.slidingmenu.CreateReportFragment.onCreateView(CreateReportFragment.java:31)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:830)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1034)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.app.BackStackRecord.run(BackStackRecord.java:622)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1384)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:428)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.os.Handler.handleCallback(Handler.java:605)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.os.Handler.dispatchMessage(Handler.java:92)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.os.Looper.loop(Looper.java:154)
01-04 21:18:36.513: E/AndroidRuntime(3772): at android.app.ActivityThread.main(ActivityThread.java:4945)
01-04 21:18:36.513: E/AndroidRuntime(3772): at java.lang.reflect.Method.invokeNative(Native Method)
01-04 21:18:36.513: E/AndroidRuntime(3772): at java.lang.reflect.Method.invoke(Method.java:511)
01-04 21:18:36.513: E/AndroidRuntime(3772): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-04 21:18:36.513: E/AndroidRuntime(3772): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-04 21:18:36.513: E/AndroidRuntime(3772): at dalvik.system.NativeStart.main(Native Method)
So I was able to make a Spinner work in a single Activity, but when I transferred the code to a Fragment it obviously didn't work.
I think the Error was from the Instatiation of Spinner.
Use this one for your TextView and Spinner.
<Spinner
android:id="#+id/spinnerComplaintType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="54dp"
android:layout_toRightOf="#+id/buttonSend"
android:textColor="#000000" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignTop="#+id/spinnerComplaintType"
android:layout_marginTop="17dp"
android:text="File Complaint"
android:textAppearance="?android:attr/textAppearanceLarge" />
Also Change
android.R.layout.simple_spinner_item
instead of
android.R.layout.simple_list_item_1
in your Array Adapter.
UPDATE:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.complaintType, android.R.layout.simple_spinner_item);