images with same size and resolution in gridview not run - android

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.

Related

Android - user setting fragment

My user settings fragment does not work
It´s really simple - thus it should work.
Menu user settings -> onOptionsItemSelected-> new Intent -> startActivityForResult(intent, key) -> now it should use the fragment.xml.
UserPreferencesFragment.java
public class UserPreferencesFragment extends PreferenceFragment {
private static String SETTINGS_NAME_KEY = "name";
private static String SETTINGS_EMAIL_KEY = "name";
public static String getName(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_NAME_KEY, "");
}
public static String getEmail(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getString(SETTINGS_EMAIL_KEY, "");
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//adding the preferences from the xml
//so this will in fact be the whole view.
addPreferencesFromResource(R.xml.prefs);
}
}
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".......UserPreferencesActivity">
<LinearLayout android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textStyle="bold"
android:textSize="#dimen/h1"
android:text="#string/user_name" />
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/h1"
android:text="" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginRight="10dp"
android:textSize="#dimen/h1"
android:text="#string/user_email" />
<TextView
android:id="#+id/userEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/h1"
android:text="" />
</LinearLayout>
</LinearLayout>
Now all should be well, but I get a massive exception which is posted in its whole.
03-26 11:42:58.584 31714-31714/xx.xx.xxxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: xx.xx.xxxx, PID: 31714
java.lang.RuntimeException: Unable to start activity ComponentInfo{xx.xx.xxxx/xx.xx.xxxx.UserPreferencesActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class resources
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class resources
at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:443)
at android.preference.GenericInflater.inflate(GenericInflater.java:318)
at android.preference.GenericInflater.inflate(GenericInflater.java:264)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:273)
at android.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:301)
at xx.xx.xxxx.UserPreferencesFragment.onCreate(UserPreferencesFragment.java:41)
at android.app.Fragment.performCreate(Fragment.java:2198)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
at android.app.BackStackRecord.run(BackStackRecord.java:793)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)
at android.app.FragmentController.execPendingActions(FragmentController.java:325)
at android.app.Activity.performStart(Activity.java:6252)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.preference.resources" on path: DexPathList[[zip file "/data/app/xx.xx.xxxx-2/base.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_dependencies_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_0_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_1_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_2_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_3_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_4_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_5_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_6_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_7_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_8_apk.apk", zip file "/data/app/xx.xx.xxxx-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/xx.xx.xxxx-2/lib/x86_64, /vendor/lib64, /system/lib64]]
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.preference.GenericInflater.createItem(GenericInflater.java:376)
at android.preference.GenericInflater.onCreateItem(GenericInflater.java:419)
at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
at android.preference.GenericInflater.inflate(GenericInflater.java:318)
at android.preference.GenericInflater.inflate(GenericInflater.java:264)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:273)
at android.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:301)
at xx.xx.xxxx.UserPreferencesFragment.onCreate(UserPreferencesFragment.java:41)
at android.app.Fragment.performCreate(Fragment.java:2198)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
at android.app.BackStackRecord.run(BackStackRecord.java:793)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)
at android.app.FragmentController.execPendingActions(FragmentController.java:325)
at android.app.Activity.performStart(Activity.java:6252)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: android.preference.resources
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 26 more
Caused by: java.lang.NoClassDefFoundError: Class not f
The root layout of your prefs.xml file must be <PreferenceScreen> not <LinearLayout>, you're using wrong file i guess
You need to use:
setContentView(R.layout.fragment);
in onCreate() before you try to add your prefs I think.
Hope this helps

Why is assigning an OnClickListener to AutoCompleteTextView giving a NullPointerException?

Whenever I assign an android:onClick attribute to an AutoCompleteTextView, my application immediately crashes upon loading the activity. I've tested AutoCompleteTextView without assigning an onClick method and it seems to work fine, as does assigning onClick to other views (including EditText, Spinners, TextViews, Buttons and ImageButtons). I've managed to narrow down the error to specifically to line 24 (setContentView(R.layout.activity_main)). Can anyone shed some light on this?
MainActivity.java
package com.example.matt.testapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
public AutoCompleteTextView actv;
public String[] continents = {"North America",
"South America",
"Antarctica",
"Europe",
"Africa",
"Asia",
"Australia"
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actv = (AutoCompleteTextView) findViewById(R.id.actv);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, continents);
actv.setAdapter(adapter);
}
public void actvClick (View view) {}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent" >
<AutoCompleteTextView
android:id="#+id/actv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="actvClick" >
</AutoCompleteTextView>
</LinearLayout>
Logcat
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.matt.testapp/com.example.matt.testapp.MainActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class AutoCompleteTextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class AutoCompleteTextView
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class AutoCompleteTextView
Caused by: java.lang.NullPointerException: Attempt to write to field 'android.view.View$OnClickListener android.widget.AutoCompleteTextView$PassThroughClickListener.mWrapped' on a null object reference
at android.widget.AutoCompleteTextView$PassThroughClickListener.-set0(Unknown Source:0)
at android.widget.AutoCompleteTextView.setOnClickListener(AutoCompleteTextView.java:307)
at android.view.View.<init>(View.java:5008)
at android.widget.TextView.<init>(TextView.java:824)
at android.widget.EditText.<init>(EditText.java:88)
at android.widget.AutoCompleteTextView.<init>(AutoCompleteTextView.java:220)
at android.widget.AutoCompleteTextView.<init>(AutoCompleteTextView.java:193)
at android.widget.AutoCompleteTextView.<init>(AutoCompleteTextView.java:172)
at android.support.v7.widget.AppCompatAutoCompleteTextView.<init>(AppCompatAutoCompleteTextView.java:68)
at android.support.v7.widget.AppCompatAutoCompleteTextView.<init>(AppCompatAutoCompleteTextView.java:64)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:130)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.matt.testapp.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
This looks like to be a bug in AutoCompleteTextView.
What happens:
Inflating the XML invokes AutoCompleteTextView constructor, and it invokes View constructor.
View constructor sees the onClick attribute and calls setOnClickListener().
AutoCompleteTextView has overridden setOnClickListener() which writes to an internal mPassThroughClickListener field. It is only initialized at the end of AutoCompleteTextView constructor, and this init code has not been run yet.
Reference
To work around it, remove the onClick attrtibute from your XML and call setOnClickListener() programmatically in your code.
I filed a bug about this in Android issue tracker.

android.view.InflateException - cannot find reason

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.

My android app crashes everytime in ADT API:23

Project name:Fragment2
ADT 2.1.3
AVD API:23
WINDOWS 10
MainActivity.java:
package com.example.deepaksingh.fragment2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/fragment2"
android:name="com.example.deepaksingh.fragment2.Fragment2"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="#layout/fragment2" />
<fragment
android:id="#+id/fragment1"
android:name="com.example.deepaksingh.fragment2.Fragment1"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="#layout/fragment1" />
</LinearLayout>
Fragment1.java:
package com.example.deepaksingh.fragment2;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.View;
import android.view.LayoutInflater;
import android.app.Fragment;
public class Fragment1 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment1,container, false);
}
}
fragment1.xml
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#0000ff"
>
<TextView
android:id="#+id/textview1"
android:text="#string/first_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
Fragment2.java
package com.example.deepaksingh.fragment2;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.View;
import android.view.LayoutInflater;
import android.app.Fragment;
public class Fragment2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment2,container, false);
}
}
fragment2.xml
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff0000"
>
<Textview
android:id="#+id/textview2"
android:text="Second Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
AndroidMAnifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.deepaksingh.fragment2">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LOGCAT:
////////////////////////////////////////////////////////////
09-16 14:36:29.365 6887-6887/com.example.deepaksingh.fragment2 W/System: ClassLoader referenced unknown path: /data/app/com.example.deepaksingh.fragment2-2/lib/x86
09-16 14:36:29.459 6887-6887/com.example.deepaksingh.fragment2 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
09-16 14:36:29.539 6887-6887/com.example.deepaksingh.fragment2 D/AndroidRuntime: Shutting down VM
09-16 14:36:29.540 6887-6887/com.example.deepaksingh.fragment2 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.deepaksingh.fragment2, PID: 6887
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.deepaksingh.fragment2/com.example.deepaksingh.fragment2.MainActivity}: android.view.InflateException: Binary XML file line #6: Binary XML file line #9: Binary XML file line #9: Error inflating class Textview
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #6: Binary XML file line #9: Binary XML file line #9: Error inflating class Textview
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.deepaksingh.fragment2.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class Textview
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.deepaksingh.fragment2.Fragment2.onCreateView(Fragment2.java:14)
at android.app.Fragment.performCreateView(Fragment.java:2220)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:949)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1228)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2201)
at android.app.FragmentController.onCreateView(FragmentController.java:98)
at android.app.Activity.onCreateView(Activity.java:5546)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:36)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.deepaksingh.fragment2.MainActivity.onCreate(MainActivity.java:12) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class Textview
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at com.example.deepaksingh.fragment2.Fragment2.onCreateView(Fragment2.java:14) 
at android.app.Fragment.performCreateView(Fragment.java:2220) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:949) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126) 
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1228) 
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2201) 
at android.app.FragmentController.onCreateView(FragmentController.java:98) 
at android.app.Activity.onCreateView(Activity.java:5546) 
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:36) 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.deepaksingh.fragment2.MainActivity.onCreate(MainActivity.java:12) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Textview" on path: DexPathList[[zip file "/data/app/com.example.deepaksingh.fragment2-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.deepaksingh.fragment2-2/lib/x86, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassL
09-16 14:36:34.205 6887-6887/com.example.deepaksingh.fragment2 I/Process: Sending signal. PID: 6887 SIG: 9
<?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:layout_width="match_parent
android:layout_height="match_parent" >
<fragment
android:id="#+id/fragment2"
android:name="com.example.deepaksingh.fragment2.Fragment2"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="#layout/fragment2" />
<fragment
android:id="#+id/fragment1"
android:name="com.example.deepaksingh.fragment2.Fragment1"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="#layout/fragment1" />
</LinearLayout>
Problem is in your xml file.
i think clean build should work.

Android: Can't inflate class fragment

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.

Categories

Resources