Fragment Spinner Not working - java

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);

Related

how the second activity crash?

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.

Dialg - ImageView - NullPointerException - setOnClickListener

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.

"InvocationTargetException" Error

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>

TabListener doesn't work

I tried to implement tabs into my app and followed this tutorial:
http://android-er.blogspot.de/2012/06/create-actionbar-in-tab-navigation-mode.html
But now i have the problem that my TabListener does not take the parameters from my tabs.
tab1 class:
package com.example.MainActivity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.MainActivity.R;
public class Tab1 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myFragmentView = inflater.inflate(R.layout.fragment_a, container, false);
return myFragmentView;
}
}
and this is my TabListener:
public class TabListener <T extends Fragment> implements ActionBar.TabListener{
private final Activity myActivity;
private final String myTag;
private final Class myClass;
public TabListener(Activity activity, String tag, Class<T> cls) {
myActivity = activity;
myTag = tag;
myClass = cls;
}
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
// Check if the fragment is already initialized
if (myFragment == null) {
// If not, instantiate and add it to the activity
myFragment = Fragment.instantiate(myActivity, myClass.getName());
ft.add(android.R.id.content, myFragment, myTag);
} else {
// If it exists, simply attach it in order to show it
ft.attach(myFragment);
}
}
#Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
Fragment myFragment = myActivity.getFragmentManager().findFragmentByTag(myTag);
if (myFragment != null) {
// Detach the fragment, because another one is being attached
ft.detach(myFragment);
}
}
#Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
MainActivity:
public class MyActivity extends Activity {
private String string1 = "gahwareawbad password gagaw";
public String datum = new String("");
//STUNDENPLAN-VARIABLEN
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tabA = actionBar.newTab();
tabA.setText("Tab A");
tabA.setTabListener(new TabListener<Tab1>(this, "Tag A", Tab1.class));
actionBar.addTab(tabA);
Tab tabB = actionBar.newTab();
tabB.setText("Tab B");
tabB.setTabListener(new TabListener<Tab2>(this, "Tag B", Tab2.class));
actionBar.addTab(tabB);
Tab tabC = actionBar.newTab();
tabC.setText("Tab C");
tabC.setTabListener(new TabListener<Tab3>(this, "Tag C", Tab3.class));
actionBar.addTab(tabC);
if (savedInstanceState != null) {
int savedIndex = savedInstanceState.getInt("SAVED_INDEX");
getActionBar().setSelectedNavigationItem(savedIndex);
}
// quellcode = (TextView) findViewById(com.example.MainActivity.R.id.TextView01);
geschichte = (TextView) findViewById(com.example.MainActivity.R.id.geschichte);
datum1 = (TextView) findViewById(com.example.MainActivity.R.id.datum1);
}
#Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
outState.putInt("SAVED_INDEX", getActionBar().getSelectedNavigationIndex());
}
}
MainXML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/tabHost">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/einstellungen"
android:layout_width="fill_parent android:layout_height="fill_parent" android:orientation="vertical" android:background="#ffffff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/datum1" android:layout_gravity="center_horizontal"
android:textColor="#000000"
android:background="#f6fff4"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_column="0">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:text="Montag"
android:id="#+id/montagx" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:text="Dienstag"
android:id="#+id/dienstagx" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:text="Mittwoch"
android:id="#+id/mittwochx" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:text="Donnerstag"
android:id="#+id/donnerstagx" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:text="Freitag"
android:id="#+id/freitagx" android:textColor="#000000"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/montag1" android:layout_column="0" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/dienstag1" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/mittwoch1" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/donnerstag1" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/freitag1" android:textColor="#000000"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/montag2" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/dienstag2" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/mittwoch2" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/donnerstag2" android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/freitag2" android:textColor="#000000"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/tableRow">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/montag3"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/dienstag3"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/mittwoch3"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/donnerstag3"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/freitag3"
android:textColor="#000000"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/tableRow2">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/montag4" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/dienstag4" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/mittwoch4" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/donnerstag4" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/freitag4" android:textColor="#000000"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/tableRow3">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/montag5"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/dienstag5"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/mittwoch5"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/donnerstag5"
android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:id="#+id/freitag5"
android:textColor="#000000"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/tableRow4">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/montag6" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/dienstag6" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/mittwoch6" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/donnerstag6" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/freitag6" android:textColor="#000000"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/tableRow5">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/montag7" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/dienstag7" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/mittwoch7" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/donnerstag7" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/freitag7" android:textColor="#000000"/>
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/tableRow6">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/montag8" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/dienstag8" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/mittwoch8" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/donnerstag8" android:textColor="#000000"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/freitag8" android:textColor="#000000"/>
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
03-30 22:09:51.720 441-876/com.android.launcher D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 692ms
03-30 22:09:51.997 441-877/com.android.launcher D/dalvikvm﹕ GC_FOR_ALLOC freed 1576K, 25% free 17107K/22564K, paused 176ms, total 189ms
03-30 22:09:52.027 2952-2952/? D/AndroidRuntime﹕ >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
03-30 22:09:52.057 2952-2952/? D/AndroidRuntime﹕ CheckJNI is ON
03-30 22:09:52.147 2952-2952/? D/dalvikvm﹕ Trying to load lib libjavacore.so 0x0
03-30 22:09:52.187 2952-2952/? D/dalvikvm﹕ Added shared lib libjavacore.so 0x0
03-30 22:09:52.227 2952-2952/? D/dalvikvm﹕ Trying to load lib libnativehelper.so 0x0
03-30 22:09:52.237 2952-2952/? D/dalvikvm﹕ Added shared lib libnativehelper.so 0x0
03-30 22:09:53.419 441-441/com.android.launcher I/Choreographer﹕ Skipped 55 frames! The application may be doing too much work on its main thread.
03-30 22:09:53.542 302-338/system_process W/RecognitionManagerService﹕ no available voice recognition services found for user 0
03-30 22:09:54.067 2952-2952/? D/AndroidRuntime﹕ Calling main entry com.android.commands.am.Am
03-30 22:09:54.077 2952-2952/? D/dalvikvm﹕ Note: class Landroid/app/ActivityManagerNative; has 157 unimplemented (abstract) methods
03-30 22:09:54.107 302-479/system_process I/ActivityManager﹕ START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.MainActivity/.MyActivity} from pid 2952
03-30 22:09:54.147 302-479/system_process W/WindowManager﹕ Failure taking screenshot for (328x546) to layer 21005
03-30 22:09:54.187 2962-2962/com.example.MainActivity D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
03-30 22:09:54.217 302-739/system_process I/ActivityManager﹕ Start proc com.example.MainActivity for activity com.example.MainActivity/.MyActivity: pid=2962 uid=10048 gids={50048, 3003, 1028}
03-30 22:09:54.227 2952-2952/? D/AndroidRuntime﹕ Shutting down VM
03-30 22:09:54.257 2952-2956/? D/dalvikvm﹕ GC_CONCURRENT freed 92K, 17% free 491K/588K, paused 1ms+1ms, total 27ms
03-30 22:09:54.257 2952-2958/? D/jdwp﹕ Got wake-up signal, bailing out of select
03-30 22:09:54.257 2952-2958/? D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
03-30 22:09:54.427 36-201/? E/SurfaceFlinger﹕ ro.sf.lcd_density must be defined as a build property
03-30 22:09:55.067 2962-2962/com.example.MainActivity E/Trace﹕ error opening trace file: No such file or directory (2)
03-30 22:09:57.057 2962-2962/com.example.MainActivity D/AndroidRuntime﹕ Shutting down VM
03-30 22:09:57.057 2962-2962/com.example.MainActivity W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-30 22:09:57.077 2962-2962/com.example.MainActivity E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.MainActivity/com.example.MainActivity.MyActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.MainActivity.MyActivity.onCreate(MyActivity.java:104)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            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:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
03-30 22:09:57.087 302-739/system_process W/ActivityManager﹕ Force finishing activity com.example.MainActivity/.MyActivity
03-30 22:09:57.117 302-739/system_process W/WindowManager﹕ Failure taking screenshot for (328x546) to layer 21010
03-30 22:09:57.397 36-490/? E/SurfaceFlinger﹕ ro.sf.lcd_density must be defined as a build property
03-30 22:09:57.637 302-319/system_process W/ActivityManager﹕ Activity pause timeout for ActivityRecord{40e9e8c0 u0 com.example.MainActivity/.MyActivity}
03-30 22:09:59.227 302-329/system_process I/Choreographer﹕ Skipped 30 frames! The application may be doing too much work on its main thread.
Issue with the Import in MainActivity
change this
import android.app.ActionBar.TabListener;
to
import com.example.MainActivity.TabListener
or change your custom TabListener class name.

Android: addTextChangedListener crash app

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!!

Categories