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
Related
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.
First of all, I'm starting at Android, so maybe I'm asking a stupid question. Oh, and sorry for my English.
I have an Activity that receives an Object when it starts (in the previous activity's Intent) and I want to set severals views (ImageView and TextViews) in the Java file. I have looked for the way to do it, and this is what I think I need.
The XML file:
<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:orientation="vertical"
android:id="#+id/party"
tools:context=".activities.PartyActivity">
<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:orientation="horizontal"
tools:context=".activities.PartyActivity"
android:id="#+id/head">
<!--Party-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/photo"/>
<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:orientation="vertical"
tools:context=".activities.PartyActivity">
<!--Dia/hora-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/date"/>
<!--Dirección-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/currentCity"
android:id="#+id/direction"/>
<!--Precio-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/currentCity"
android:id="#+id/price"/>
</RelativeLayout>
</RelativeLayout>
<!--Descripcion-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/head"
android:id="#+id/description"/>
<!--Mapa-->
And this is the class:
public class PartyActivity extends Activity {
private RelativeLayout partyLayout;
private Party party;
private ImageView photoView;
private TextView dateView;
private TextView directionVew;
private TextView priceView;
private TextView descriptionView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_party);
partyLayout = (RelativeLayout)findViewById(R.id.party);
party = (Party)getIntent().getExtras().getSerializable("Party");
setParty();
}
private void setParty(){
partyLayout.removeAllViews();
photoView = (ImageView)findViewById(R.id.photo);
dateView = (TextView)findViewById(R.id.date);
directionVew = (TextView)findViewById(R.id.direction);
priceView = (TextView)findViewById(R.id.price);
descriptionView = (TextView)findViewById(R.id.description);
photoView.setImageBitmap(party.getPhoto());
dateView.setText(Session.getInstance().getDateFormat().format(party.getDate().getTime()));
directionVew.setText(party.getDirection());
priceView.setText(party.getPrice().toString());
descriptionView.setText(party.getDescripcion());
setContentView(photoView);
setContentView(dateView);
setContentView(directionVew);
setContentView(priceView);
setContentView(descriptionView);
}
When I try to go to the activity, the application shuts down. I have debugged it and the Party object has been received correctly, but in the setParty method it throws this exception:
04-08 14:21:08.619 14680-14680/trebolete.keloke E/AndroidRuntime: FATAL EXCEPTION: main
Process: trebolete.keloke, PID: 14680 java.lang.RuntimeException: Unable to start activity ComponentInfo{trebolete.keloke/trebolete.keloke.activities.PartyActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
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: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
at trebolete.keloke.activities.PartyActivity.setParty(PartyActivity.java:46)
at trebolete.keloke.activities.PartyActivity.onCreate(PartyActivity.java:33)
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)
If I remove the line partyLayout.removeAllViews(); it throws this exception:
04-09 13:47:44.101 2576-2576/trebolete.keloke E/AndroidRuntime: FATAL EXCEPTION: main
Process: trebolete.keloke, PID: 2576
java.lang.RuntimeException: Unable to start activity ComponentInfo{trebolete.keloke/trebolete.keloke.activities.PartyActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
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: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4309)
at android.view.ViewGroup.addView(ViewGroup.java:4145)
at android.view.ViewGroup.addView(ViewGroup.java:4117)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:423)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:404)
at android.app.Activity.setContentView(Activity.java:2186)
at trebolete.keloke.activities.PartyActivity.setParty(PartyActivity.java:52)
at trebolete.keloke.activities.PartyActivity.onCreate(PartyActivity.java:33)
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)
Any help?
As you have already set parent view in onCreate() function.
setContentView(R.layout.activity_party);
Will set the parent layout for the current activity.Which you have already initailzed this in onCreate() function of activity.
All these views(
photoView, dateView, directionVew,
priceView , descriptionView
) are child layouts of activity_party . You don't need to perform setContentView() on these views.
Those views will automatically display your updated data , which you have updated in following line of codes :
photoView.setImageBitmap(party.getPhoto());
dateView.setText(Session.getInstance().getDateFormat().format(party.getDate().getTime()));
directionVew.setText(party.getDirection());
priceView.setText(party.getPrice().toString());
descriptionView.setText(party.getDescripcion());
Since you called partyLayout.removeAllViews(); you removed all views from the layout. That's why findViewById() returns null.
This question already has answers here:
How to solve java.lang.OutOfMemoryError trouble in Android
(7 answers)
Closed 6 years ago.
my activity is continuously crashing, this just shows only text on UI, please tell me what I am doing wrong.This is showing error in XML file but according to me the XML file is fine, I am not able to find the bug in XML file.
Here is my code
public class PlacedOrderConfirmation extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.place_order_confirmation);
TextView placed_successful_txt= (TextView)findViewById(R.id.placed_successful_txt);
Intent intent = getIntent();
String edit_order_id = intent.getStringExtra("EDIT_OR_PLACE") != null ? intent.getStringExtra("EDIT_OR_PLACE") : "";
if(edit_order_id!=null && edit_order_id.length()>0){
placed_successful_txt.setText("YOUR ORDER HAS BEEN\nUPDATED SUCCESSFULLY");
}
Button notification_icon = (Button) findViewById(R.id.notification_icon);
ImageView btnContinue = (ImageView) findViewById(R.id.cont);
notification_icon.getLayoutParams().height = (int) (Utility.getDeviceHeight(this) * .04);
notification_icon.getLayoutParams().width = (int) (Utility.getDeviceHeight(this) * .04);
btnContinue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(PlacedOrderConfirmation.this, ContractorDashboard.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
});
}
}
the XML file
<?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:background="#drawable/bg_summary"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorAccent"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/confirmation"
android:textColor="#color/white"
android:textSize="#dimen/medium_text" />
<Button
android:id="#+id/notification_icon"
android:layout_width="wrap_content"
android:visibility="invisible"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:background="#drawable/notification_icon" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/congratulation"
android:textSize="42sp"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"/>
<TextView
android:id="#+id/placed_successful_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/orderplaced"
android:textSize="#dimen/text_large"
android:textStyle="bold"
android:layout_margin="20dp"
android:textColor="#color/green"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/emailsent"
android:textSize="#dimen/text_small"
android:layout_marginTop="20dp"
android:textColor="#color/gray_base"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="40dp"
android:text="#string/click"
android:textSize="#dimen/text_large"
android:layout_centerVertical="true"
android:textColor="#color/white"
/>
<ImageView
android:layout_width="70dp"
android:layout_height="35dp"
android:id="#+id/cont"
android:layout_marginTop="10dp"
android:background="#drawable/forward_arrow"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
This is the logcat
10-20 10:48:08.394 24918-24918/com.loadarmy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.loadarmy, PID: 24918
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.loadarmy/com.loadarmy.contractor.PlacedOrderConfirmation}: android.view.InflateException: Binary XML file line #89: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #89: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:623)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1940)
at com.loadarmy.contractor.PlacedOrderConfirmation.onCreate(PlacedOrderConfirmation.java:19)
at android.app.Activity.performCreate(Activity.java:5242)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:597)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1940)
at com.loadarmy.contractor.PlacedOrderConfirmation.onCreate(PlacedOrderConfirmation.java:19)
at android.app.Activity.performCreate(Activity.java:5242)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:601)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:434)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.createFromResourceStream(Resources.java:2503)
at android.content.res.Resources.loadDrawable(Resources.java:2155)
at android.content.res.MiuiResources.loadDrawable(MiuiResources.java:393)
at android.content.res.Resources.loadDrawable(Resources.java:2062)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3558)
at android.widget.ImageView.<init>(ImageView.java:123)
at android.widget.ImageView.<init>(ImageView.java:119)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:597)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:672)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1940)
at com.loadarmy.contractor.PlacedOrderConfirmation.onCreate(PlacedOrderConfirmation.java:19)
at android.app.Activity.performCreate(Activity.java:5242)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
You set background images to your LinearLayout and Button of your xml. one of those images are giving OutOfMemoryError try reducing size of your image or change it.
You are getting OutOfMemoryError
Thrown when the Java Virtual Machine cannot allocate an object because
it is out of memory, and no more memory could be made available by the
garbage collector.
This error showing when the application attempts to add more data into the heap space area, but there is not enough room for it.
Reduce Image Resolution at first and set android:largeHeap="true" in your manifest .
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.
I am getting the following error in Android Studio and I am unable to resolve it:
07-06 19:44:41.798 4491-4491/com.example.first_app D/AndroidRuntime: Shutting down VM
07-06 19:44:41.799 4491-4491/com.example.first_app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.first_app, PID: 4491
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first_app/com.example.first_app.welcome}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.view.View.toString()' on a null object reference
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: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.view.View.toString()' on a null object reference
at com.example.first_app.welcome.onCreate(welcome.java:22)
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)
07-06 19:44:44.696 4491-4497/com.example.first_app W/art: Suspending all threads took: 46.612ms
07-06 19:44:46.517 4491-4491/com.example.first_app I/Process: Sending signal. PID: 4491 SIG: 9
THIS IS THE ERROR I M INCURRING
CODE FOR welcome.java
public class welcome extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
TextView my_msg;
String name;
my_msg= (TextView)findViewById(R.id.textView3);
name= "Welcome " +findViewById(R.id.textView2).toString();
my_msg.setText(name);
}
}
XML CODE FOR welcome.xml ...Please refer it..it only shows the message on screen "welcome Name"..the name is entered by user through activity_form.java
<?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:weightSum="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView3"
android:layout_gravity="center"
android:layout_weight="1" />
</LinearLayout>
First the way to solve your exception to type cast the View and getText from that View
(TextView) findViewById(R.id.textView2).getText().toString();
So the final String will look like
name= "Welcome " + (TextView) findViewById(R.id.textView2).getText().toString();
SUGGESTION
Use proper naming conventions for views, Rather than naming view1 view2 etc