I am trying to understand how fragments work, but i haven't had sucess so far.
This is only an example nothing usefull.
when i try to add a fragment to the layout I get always the same error.
I don't know what is missing
Fragment Class
package com.app.danieltavares.teste;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class TestFragment extends Fragment{
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.testefrag,container,false);
}
}
ActivityClass
package com.app.danieltavares.teste;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Layout Fragment
<?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">
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="diusdb"/>
</LinearLayout>
Layout that uses the fragments
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.app.danieltavares.teste.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.app.danieltavares.teste.TestFragment"
tools:layout="#layout/testefrag"></fragment>
</RelativeLayout>
Logcat
08-23 18:35:21.867 15308-15308/com.app.danieltavares.teste E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.danieltavares.teste, PID: 15308
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.danieltavares.teste/com.app.danieltavares.teste.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #16: Must specify unique android:id, android:tag, or have a parent with an id for com.app.danieltavares.teste.TestFragment
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2282)
at android.app.FragmentController.onCreateView(FragmentController.java:98)
at android.app.Activity.onCreateView(Activity.java:5884)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:34)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:80)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at com.app.danieltavares.teste.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #16: Must specify unique android:id, android:tag, or have a parent with an id for com.app.danieltavares.teste.TestFragment
Add an android:id attribute to the <fragment> element in your layout file.
Related
There are 3 causes of errors that I get in my logcat
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException
below is my logcat.
Process: pnj.uas.aufar, PID: 4529
java.lang.RuntimeException: Unable to start activity ComponentInfo{pnj.uas.aufar/pnj.uas.aufar.TambahCatatanActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.google.android.material.textfield.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2914)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3049)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:706)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at pnj.uas.aufar.TambahCatatanActivity.onCreate(TambahCatatanActivity.java:27)
at android.app.Activity.performCreate(Activity.java:7140)
at android.app.Activity.performCreate(Activity.java:7131)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2894)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3049)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:241)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215)
2022-01-22 07:32:04.703 4529-4529/pnj.uas.aufar E/AndroidRuntime: at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:113)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:474)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:433)
... 28 more
Below file for TambahCatatanActivity.java
package pnj.uas.aufar;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class TambahCatatanActivity extends AppCompatActivity {
EditText edJudul, edJumlah, edTanggal;
Button btnSimpan;
RealmHelper realm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tambah_catatan);
realm = new RealmHelper(TambahCatatanActivity.this);
edJudul = findViewById(R.id.ed_judul);
edJumlah = findViewById(R.id.ed_jumlah);
edTanggal = findViewById(R.id.ed_tanggal);
btnSimpan = findViewById(R.id.btn_simpan);
edTanggal.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//date picker
final Calendar calendar = Calendar.getInstance();
int nowYear = calendar.get(Calendar.YEAR);
int nowMonth = calendar.get(Calendar.MONTH);
int nowDay = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(TambahCatatanActivity.this, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Calendar cal = Calendar.getInstance();
cal.set(year, month, dayOfMonth);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
edTanggal.setText(dateFormat.format(cal.getTime()));
}
}, nowYear, nowMonth, nowDay);
dialog.show();
}
});
btnSimpan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CatatanModel catatan = new CatatanModel();
catatan.setId((int) realm.getNextId());
catatan.setJudul(edJudul.getText().toString());
catatan.setJumlahhutang(edJumlah.getText().toString());
catatan.setTanggal(edTanggal.getText().toString());
realm.insertData(catatan);
}
});
}
}
And the last one is the file for activity_tambah_catatan.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".TambahCatatanActivity">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/ed_judul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hutang Anda" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/ed_jumlah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Jumlah Hutang"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/ed_tanggal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="Tanggal Jatuh Tempo" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/btn_simpan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
android:text="Simpan"
android:textColor="#android:color/white" />
</LinearLayout>
build.gradle add implementation com.google.android.material:material:1.3.0
I'm trying to work on a code that displays images
The code is correct and some images were displayed but when i press image after comment "i wrote it for enplane "
application well be stopped
all images have the same size and resolution
I do not know where the error...
Grid_activities1
package com.children_activities;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
public class Grid_activities1 extends AppCompatActivity {
GridView gridView;
Integer[] image_grid={R.drawable.month1,R.drawable.month2,
R.drawable.month3,R.drawable.month4,
R.drawable.month5,R.drawable.month6,
R.drawable.month7,
// R.drawable.month8,
// R.drawable.month9,
// R.drawable.month10,
// R.drawable.month11,
// R.drawable.month12,
R.drawable.month16
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grid_activities1);
gridView=findViewById(R.id.gridview);
GridAdapter gridAdapter=new GridAdapter(getApplication(),image_grid);
gridView.setAdapter(gridAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
Intent intent=new
Intent(Grid_activities1.this,Image_show.class);
intent.putExtra("images",image_grid[position]);
//intent.putExtra("text",info[position]);
startActivity(intent);
}
});
}
}
logcat with error
2019-01-13 11:42:11.675 19394-19394/com.children_activities E/AndroidRuntime:
FATAL EXCEPTION: main
Process: com.children_activities, PID: 19394
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.children_activities/com.children_activities.Image_show}:
android.view.InflateException: Binary XML file line #2: Binary XML file line
#2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:652)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:724)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:792)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.inflate(LayoutInflater.java:496)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.children_activities.Image_show.onCreate(Image_show.java:15)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 24471564 byte allocation with 5218424 free bytes and 4MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:700)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:535)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1179)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:770)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621)
at android.content.res.Resources.loadDrawable(Resources.java:1727)
at android.content.res.TypedArray.getDrawable(TypedArray.java:945)
at android.view.View.<init>(View.java:4516)
at android.view.ViewGroup.<init>(ViewGroup.java:579)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
2019-01-13 11:42:11.675 19394-19394/com.children_activities E/AndroidRuntime: at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
... 25 more
image_show.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backg"
tools:context=".Image_show"
tools:layout_editor_absoluteY="25dp">
<ImageView
android:id="#+id/selected_image"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_marginTop="63dp" />
<TextView
android:id="#+id/txt_show"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="142dp"
android:gravity="center"
android:text="hii"
android:textColor="#782ad4"
android:textSize="35dp"
android:textStyle="bold" />
</RelativeLayout>
OutOfMemoryError is the main error , this happens as result of big images sizes in your case results in memory leak.
you can add android:largeHeap="true" and android:hardwareAccelerated="false" in the application tag in the manifest.xml
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
The problem is with your drawable. Try moving your #dawable/backgto the res/drawable-xhdpi/ folder.
This is my fragment inputtext_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inputtextfragm"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/inputtext_layout"
android:visibility="invisible"
android:layout_height="wrap_content"
android:layout_width="match_parent"
...>
...
</LinearLayout>
</fragment>
inputText fragment in java:
package de.company.android.inputtext;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class InputTextFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
try {
return inflater.inflate(R.layout.inputtext_fragment, container, false);
}
catch (Throwable t) {
t.printStackTrace();
return null;
}
}
}
This is the activity layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
tools:context="de.company.android.testview.MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
...
<fragment
android:id="#+id/console"
android:name="de.company.android.inputtext.InputTextFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
I get the following error on launch, when the content view of the activity is set onCreate():
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.company.android.testview, PID: 573
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.company.android.testview/de.company.android.testview.MainActivity}: android.view.InflateException: Binary XML file line #153: Binary XML file line #153: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #153: Binary XML file line #153: Error inflating class fragment
...
Caused by: java.lang.IllegalStateException: Fragment de.company.android.inputtext.InputTextFragment did not create a view.
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2253)
at android.app.FragmentController.onCreateView(FragmentController.java:99)
at android.app.Activity.onCreateView(Activity.java:6085)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:766)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:479)
at android.app.Activity.setContentView(Activity.java:2400)
at de.company.android.testview.MainActivity.onCreate(MainActivity.java:1697)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
This is the error logged inside catch:
W/System.err: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
W/System.err: at de.company.android.inputtext.InputTextFragment.onCreateView(InputTextFragment.java:23)
W/System.err: at android.app.Fragment.performCreateView(Fragment.java:2281)
W/System.err: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
W/System.err: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1142)
W/System.err: at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1246)
W/System.err: at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2223)
W/System.err: at android.app.FragmentController.onCreateView(FragmentController.java:99)
W/System.err: at android.app.Activity.onCreateView(Activity.java:6085)
W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:766)
W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
W/System.err: at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
W/System.err: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
...
W/System.err: Caused by: java.lang.NullPointerException
W/System.err: at java.lang.VMClassLoader.findLoadedClass(Native Method)
W/System.err: at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:362)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:499)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
W/System.err: at android.app.Fragment.instantiate(Fragment.java:620)
W/System.err: at android.app.Fragment.instantiate(Fragment.java:598)
W/System.err: at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2214)
W/System.err: at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:192)
W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:766)
W/System.err: ... 33 more
I cannot find out what is wrong. The activity and the fragment are in different modules, but everything is configured right so that the de.company.android.inputtext utils are correctly referenced.
Your input_text_fragment.xml should not be inside of a Fragment tag. It should be inside the appropriate type of Layout. The fragment tag goes only in main_activity.xml where you want the fragment to appear.
Remove the fragment from inputtext_fragment.xml layout,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inputtext_layout"
android:visibility="invisible"
android:layout_height="wrap_content"
android:layout_width="match_parent"
...>
...
</LinearLayout>
Caused by: java.lang.IllegalStateException: Fragment de.company.android.inputtext.InputTextFragment did not create a view.
You can't return a null view in onCreateView.
I am trying to add a bottom navigation view of support library in my app. Here is the code below. I am getting error like
Caused by: android.view.InflateException: Binary XML file line #52: Binary XML file line #52: Error inflating class android.support.design.widget.BottomNavigationView
But my xml code is looking fine also. And the gradle dependency version of support and appcompat are also equal. I couldn't figure out the error. Can someone help me to figure out the issue?
XML code is
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:design="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/rl_container">
</RelativeLayout>
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottom_navigation"
android:layout_alignParentBottom="true"
app:itemIconTint="#color/drawer_item"
app:itemBackground="#color/brand_black"
app:itemTextColor="#color/drawer_item"
app:menu="#menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
And my java code is
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
///getSupportActionBar().setDisplayShowTitleEnabled(true);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
BnavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
SharedPreferences sP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String user = sP.getString("user", null);
sessionManager = SessionManager.getInstance(this);
if(user == null ) {
finish();
startActivity(new Intent(getApplicationContext(), Splash.class));
return;
}
BnavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
onDrawerMenuItemClicked(item);
return true;
}
});
Error report is given below
04-22 11:23:13.665 5112-5112/me.entri.entrime E/AndroidRuntime: FATAL EXCEPTION: main
Process: me.entri.entrime, PID: 5112
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.entri.entrime/me.entri.entrime.activities.Home}: android.view.InflateException: Binary XML file line #52: Binary XML file line #52: Error inflating class android.support.design.widget.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2680)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: android.view.InflateException: Binary XML file line #52: Binary XML file line #52: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: android.view.InflateException: Binary XML file line #52: Error inflating class android.support.design.widget.BottomNavigationView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at me.entri.entrime.activities.Home.onCreate(Home.java:87)
at android.app.Activity.performCreate(Activity.java:6688)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.internal.BottomNavigationItemView.initialize(android.support.v7.view.menu.MenuItemImpl, int)' on a null object reference
and my gradle dependencies are
compile 'com.android.support:support-v13:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
Use only this dependency:
compile 'com.android.support:design:25.0.1'
Remove other two dependencies:
compile 'com.android.support:support-v13:25.0.1' compile
'com.android.support:support-v4:25.0.1'
my app couldn't start it crashes immediately after i installed it and i couldn't understand the error!
i have created two recylcerView for two fragments which are attached in the main activity xml file
Error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.invincible.fragfrag, PID: 14384
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.invincible.fragfrag/com.invincible.fragfrag.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path: DexPathList[[zip file "/data/app/com.invincible.fragfrag-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path:
MainActivity:
package com.invincible.fragfrag;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.findFragmentById(R.id.table_number_list) == null) {
TableNumber tableNumber=TableNumber.getTableNumber("number");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_number_list,tableNumber);
transaction.commit();
}
if (fragmentManager.findFragmentById(R.id.table_values) == null) {
TableValue tableValue=TableValue.getTableValue("value");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_values,tableValue);
transaction.commit();
}
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
main xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.invincible.fragfrag.MainActivity">
<android.support.v7.app.AlertController.RecycleListView
android:id="#+id/recycler_view_one"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.app.AlertController.RecycleListView>
<android.support.v7.app.AlertController.RecycleListView
android:layout_marginTop="5dp"
android:id="#+id/recycler_view_two"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.app.AlertController.RecycleListView>
</LinearLayout>
plz help me out what's the error and how to handle two fragment with two recyclerview in one activity.
THANK YOU for your concern!
android.support.v7.widget.RecyclerView
use this code in your xml file to create a listview. Simple!
You probably want to use android.support.v7.widget.RecyclerView.
Additional info that you don't need to know
RecycleListView is a nested class of android.support.v7.app.AlertController. One would refer to it as android.support.v7.app.AlertController$RecycleListView (the dollar sign). This is why it crashed at this point.
RecycleListView extends ListView not RecyclerView. That's why it would later crash with ClassCastException when you would try to use it in Java.
RecycleListView is an internal class of appcompat-v7 not to be used in your project.
I made the same mistake. Try to replace
android.support.v7.app.AlertController.RecycleListView
with
android.support.v7.widget.RecyclerView