I have a program that will show some data to a fragment with a recyclerview and using json file for the data, i have tried this before and it's working properly, but when i use a bottom navigation, i meet this exception
java.lang.RuntimeException: Unable to start activity ComponentInfo{smktelkom.student.profil/smktelkom.student.profil.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.lang.RuntimeException: Exception inflating smktelkom.student.profil:navigation/navigasinya line 41
at androidx.navigation.NavInflater.inflate(NavInflater.java:131)
at androidx.navigation.NavController.setGraph(NavController.java:419)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: java.lang.IllegalArgumentException: smktelkom.student.profil.More.MoreFragment must be a subclass of class android.support.v4.app.Fragment
at androidx.navigation.NavDestination.parseClassFromName(NavDestination.java:111)
at androidx.navigation.fragment.FragmentNavigator$Destination.onInflate(FragmentNavigator.java:310)
at androidx.navigation.NavInflater.inflate(NavInflater.java:143)
at androidx.navigation.NavInflater.inflate(NavInflater.java:172)
at androidx.navigation.NavInflater.inflate(NavInflater.java:122)
at androidx.navigation.NavController.setGraph(NavController.java:419)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:221)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2331)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1386)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1659)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1905)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3715)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:114)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:39)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:68)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at smktelkom.student.profil.MainActivity.onCreate(MainActivity.kt:13)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
and this is my class file and navigation file in case you need it
package smktelkom.student.profil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI.onNavDestinationSelected
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// navigation_bottom.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
navigation_bottom.setOnNavigationItemSelectedListener { item ->
onNavDestinationSelected(item, Navigation.findNavController(this, R.id.my_nav_host_fragment))
}
}
}
yeah this MainActivity is just this nothing else and the exception is linking to this class and i can't find the problem
this is the navigation file
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="#+id/navigasinya"
app:startDestination="#id/navigation_profil">
<fragment
android:id="#+id/navigation_profil"
android:name="smktelkom.student.profil.Profil.ProfilFragment"
android:label="#string/title_profil"
tools:layout="#layout/fragment_profil">
<action
android:id="#+id/action_navigation_profil_to_main2Activity"
app:destination="#id/main2Activity"
app:enterAnim="#anim/nav_default_pop_enter_anim"
app:exitAnim="#anim/nav_default_exit_anim"
app:popEnterAnim="#anim/nav_default_pop_enter_anim"
app:popExitAnim="#anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="#+id/navigation_hobi"
android:name="smktelkom.student.profil.Hobi.HobiFragment"
android:label="#string/title_hobi"
tools:layout="#layout/fragment_hobi">
<action
android:id="#+id/action_navigation_hobi_to_main3Activity"
app:destination="#id/main3Activity"
app:enterAnim="#anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="#+id/navigation_makanan"
android:name="smktelkom.student.profil.Makanan.MakananFragment"
android:label="#string/title_makanan"
tools:layout="#layout/fragment_makanan">
<action
android:id="#+id/action_navigation_makanan_to_main4Activity"
app:destination="#id/main4Activity"
app:enterAnim="#anim/nav_default_pop_enter_anim" />
</fragment>
<fragment
android:id="#+id/navigation_more"
android:name="smktelkom.student.profil.More.MoreFragment"
android:label="#string/title_more"
tools:layout="#layout/fragment_more">
<action
android:id="#+id/action_navigation_more_to_main5Activity"
app:destination="#id/main5Activity"
app:enterAnim="#anim/nav_default_pop_enter_anim" />
</fragment>
<activity
android:id="#+id/main2Activity"
android:name="smktelkom.student.profil.Main2Activity"
android:label="activity_main2"
tools:layout="#layout/activity_main2" />
<activity
android:id="#+id/main5Activity"
android:name="smktelkom.student.profil.Main5Activity"
android:label="activity_main5"
tools:layout="#layout/activity_main5" />
<activity
android:id="#+id/main3Activity"
android:name="smktelkom.student.profil.Main3Activity"
android:label="activity_main3"
tools:layout="#layout/activity_main3" />
<activity
android:id="#+id/main4Activity"
android:name="smktelkom.student.profil.Main4Activity"
android:label="activity_main4"
tools:layout="#layout/activity_main4" />
</navigation>
i have searching another problem that's same like me and their answer is to put the android:name below the id and i've already tried it and still nothing fixed
this is my fragment class
package smktelkom.student.profil.More
import android.annotation.TargetApi
import android.app.Fragment
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_more.*
import org.json.JSONArray
import org.json.JSONObject
import smktelkom.student.profil.News
import smktelkom.student.profil.NewsAdapter
import smktelkom.student.profil.R
import java.io.InputStream
class MoreFragment : Fragment() {
private val TAG : String = "News"
private lateinit var linearLayoutManager:LinearLayoutManager
private lateinit var mAdapter: NewsAdapter
#TargetApi(Build.VERSION_CODES.M)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_more, container, false)
recyclerView.layoutManager = LinearLayoutManager(context)
val jsonString:String = readJsonFromKotlinFile()
val newsList : ArrayList<News> = parseJsonStringToNewsList(jsonString)
mAdapter = NewsAdapter(newsList)
recyclerView.adapter = mAdapter
return view
}
private fun parseJsonStringToNewsList(jsonString: String): ArrayList<News> {
val newsList :ArrayList<News> = ArrayList<News>(0)
val newsArray = JSONArray(jsonString)
var i = 0
var numIterations = newsArray.length()
while(i < numIterations){
val newsObject:JSONObject = newsArray.getJSONObject(i)
val news = News()
news.news_title = newsObject.getString("news_title")
news.news_image_url = newsObject.getString("news_image_url")
news.news_source = newsObject.getString("news_source")
news.news_detail = newsObject.getString("news_detail")
news.news_url = newsObject.getString("news_url")
news.id = newsObject.getInt("id")
newsList.add(news)
i++
}
return newsList
}
private fun readJsonFromKotlinFile(): String {
var inputString = ""
try {
val inputStream:InputStream = activity.assets.open("news_data_file.json")
inputString = inputStream.bufferedReader().use{it.readText()}
Log.d(TAG,inputString)
} catch (e:Exception){
Log.d(TAG, e.toString())
}
return inputString
}
}
well, i think there's no problem with this class because the exception didn't mention it. Just in case you need it
and this is my fragment XML file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="#color/colorKuning"
tools:context="smktelkom.student.profil.More.MoreFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</android.support.constraint.ConstraintLayout>
I've tried to search this problem but there's no question like my problem is.
I hope everyone can help me.
Thank You
Related
I am encountering problem inflating image in collapsing toolbar layout. I have tried compressing images online but none seems to work out for us An image with size equals to 2 mb gets uploaded but different image with size in kbs shows the following error..
2mb image
Image which is in kb
mainactivity
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.admin.myapplication.HajjAndUmrah"
android:background="#fcfcfc">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="350dp"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingtoolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:background="#drawable/aprilumrahmin">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarid"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
MainActivity.java
package com.example.admin.myapplication;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
public class HajjAndUmrah extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hajj_and_umrah);
final CollapsingToolbarLayout collapsingToolbarLayout=(CollapsingToolbarLayout) findViewById(R.id.collapsingtoolbar);
AppBarLayout appBarLayout=(AppBarLayout) findViewById(R.id.appbar);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean isshow= true;
int scrollRange =-1;
#Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (scrollRange==-1){
scrollRange=appBarLayout.getTotalScrollRange();
}
if (scrollRange+verticalOffset==0){
collapsingToolbarLayout.setTitle("Hajj and Umrah");
isshow=true;
}else if (isshow){
collapsingToolbarLayout.setTitle(" ");
isshow=false;
}
}
});
}
}
Logcat
--------- beginning of crash
04-21 05:00:56.086 2029-2029/com.example.admin.myapplication
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.admin.myapplication, PID: 2029
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.myapplication/com.example.admin.myapplication.HajjAndUmrah}: android.view.InflateException: Binary XML file line #18: Error inflating class android.support.design.widget.CollapsingToolbarLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class android.support.design.widget.CollapsingToolbarLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.admin.myapplication.HajjAndUmrah.onCreate(HajjAndUmrah.java:17)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.admin.myapplication.HajjAndUmrah.onCreate(HajjAndUmrah.java:17)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 3920012 byte allocation with 3092004 free bytes and 2MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474)
at android.content.res.Resources.loadDrawable(Resources.java:2381)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3737)
at android.view.ViewGroup.<init>(ViewGroup.java:497)
at android.widget.FrameLayout.<init>(FrameLayout.java:115)
at android.widget.FrameLayout.<init>(FrameLayout.java:111)
at android.support.design.widget.CollapsingToolbarLayout.<init>(CollapsingToolbarLayout.java:147)
at android.support.design.widget.CollapsingToolbarLayout.<init>(CollapsingToolbarLayout.java:143)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.admin.myapplication.HajjAndUmrah.onCreate(HajjAndUmrah.java:17)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
my app couldn't start it crashes immediately after i installed it and i couldn't understand the error!
i have created two recylcerView for two fragments which are attached in the main activity xml file
Error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.invincible.fragfrag, PID: 14384
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.invincible.fragfrag/com.invincible.fragfrag.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path: DexPathList[[zip file "/data/app/com.invincible.fragfrag-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path:
MainActivity:
package com.invincible.fragfrag;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.findFragmentById(R.id.table_number_list) == null) {
TableNumber tableNumber=TableNumber.getTableNumber("number");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_number_list,tableNumber);
transaction.commit();
}
if (fragmentManager.findFragmentById(R.id.table_values) == null) {
TableValue tableValue=TableValue.getTableValue("value");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_values,tableValue);
transaction.commit();
}
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
}
main xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.invincible.fragfrag.MainActivity">
<android.support.v7.app.AlertController.RecycleListView
android:id="#+id/recycler_view_one"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.app.AlertController.RecycleListView>
<android.support.v7.app.AlertController.RecycleListView
android:layout_marginTop="5dp"
android:id="#+id/recycler_view_two"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.app.AlertController.RecycleListView>
</LinearLayout>
plz help me out what's the error and how to handle two fragment with two recyclerview in one activity.
THANK YOU for your concern!
android.support.v7.widget.RecyclerView
use this code in your xml file to create a listview. Simple!
You probably want to use android.support.v7.widget.RecyclerView.
Additional info that you don't need to know
RecycleListView is a nested class of android.support.v7.app.AlertController. One would refer to it as android.support.v7.app.AlertController$RecycleListView (the dollar sign). This is why it crashed at this point.
RecycleListView extends ListView not RecyclerView. That's why it would later crash with ClassCastException when you would try to use it in Java.
RecycleListView is an internal class of appcompat-v7 not to be used in your project.
I made the same mistake. Try to replace
android.support.v7.app.AlertController.RecycleListView
with
android.support.v7.widget.RecyclerView
Ok, so I'm trying to inflate a DialogPreference in a PreferenceFragment which is nested in an AppCompatActivity. Whenever I try to go to the Activity hosting said PreferenceFragment, this error occurs.
01-14 09:40:37.002 29689-29689/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.santinocampos.android.count, PID: 29689
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.santinocampos.android.count/com.myname.android.count.Settings.SettingsActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #4: Error inflating class (not found)com.santinocampos.android.count.Settings.OptionDialogPreference
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 #16: Binary XML file line #4: Error inflating class (not found)com.santinocampos.android.count.Settings.OptionDialogPreference
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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.santinocampos.android.count.Settings.SettingsActivity.onCreate(SettingsActivity.java:20)
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 #4: Error inflating class (not found)com.santinocampos.android.count.Settings.OptionDialogPreference
at android.support.v7.preference.PreferenceInflater.createItemFromTag(PreferenceInflater.java:300)
at android.support.v7.preference.PreferenceInflater.rInflate(PreferenceInflater.java:358)
at android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:167)
at android.support.v7.preference.PreferenceInflater.inflate(PreferenceInflater.java:117)
at android.support.v7.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:115)
at android.support.v7.preference.PreferenceFragmentCompat.addPreferencesFromResource(PreferenceFragmentCompat.java:366)
at com.santinocampos.android.count.Settings.SettingsFragment.onCreate(SettingsFragment.java:19)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1230)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1332)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2288)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:80)
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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.santinocampos.android.count.Settings.SettingsActivity.onCreate(SettingsActivity.java:20)
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 "com.myname
Here's my DialogPreferenceClass
import android.content.Context;
import android.preference.DialogPreference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import com.myname.android.count.R;
import java.util.Set;
/**
* Created by thedr on 1/13/2017.
*/
public class MyDialogPreference extends DialogPreference {
public static final int KEY = R.string.preference_phoneNumber;
private EditText mPhoneNumberEditText;
public MyDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setPersistent(false);
setKey(getContext().getString(KEY));
String summary = getSharedPreferences().getString(SettingsActivity.PHONE_NUMBER_KEY, "");
setSummary(summary);
}
public void onBindDialogView(View view) {
super.onBindDialogView(view);
mPhoneNumberEditText = ((EditText) view.findViewById(R.id.editText_changeNumber));
}
public void onDialogClosed(boolean positive) {
getSharedPreferences()
.edit()
.putString(SettingsActivity.PHONE_NUMBER_KEY, mPhoneNumberEditText.getText().toString())
.apply();
super.onDialogClosed(positive);
persistBoolean(positive);
}
}
Here's my Preference xml where the inflation fails
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.myname.android.count.Settings.OptionDialogPreference
android:key="#string/preference_phoneNo"
android:dialogIcon="#android:drawable/ic_dialog_alert"
android:title="Reset Quests"
android:summary="Reset all quest-progress."
android:dialogMessage="Are you sure you wish to reset your quest progress? This action cannot be undone!"
android:positiveButtonText="Clear Quests"
android:negativeButtonText="Cancel"
/>
</PreferenceScreen>
Here's my PreferenceFragment
package com.myname.android.count.Settings;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.v7.preference.*;
import com.santinocampos.android.count.R;
/**
* Created by thedr on 1/13/2017.
*/
public class SettingsFragment extends PreferenceFragmentCompat {
private static final String TAG = "SettingsFragment";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
}
#Override
public void onDisplayPreferenceDialog(Preference preference) {
super.onDisplayPreferenceDialog(preference);
if (preference.getKey().equals(getContext().getString(MyDialogPreference.KEY))) {
}
}
#Override
public void onCreatePreferences(Bundle bundle, String s) {
}
public static String getTagString() {
return TAG;
}
}
And here's my host activity
public class SettingsActivity extends AppCompatActivity {
public static final String PHONE_NUMBER_KEY = "PHONE_NUMBER";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar toolbar = ((Toolbar) findViewById(R.id.toolbar_settings));
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.settings_title);
}
}
Im trying to add a custom View to Round Android Wear and am getting the following error from logcat:
12-31 19:27:27.211 2212-2212/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.crashoveride007.roundwatchcanvas, PID: 2212
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.crashoveride007.roundwatchcanvas/com.example.crashoveride007.roundwatchcanvas.MainActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class com.example.crashoveride007.roundwatchcanvas.MyView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.example.crashoveride007.roundwatchcanvas.MyView
at android.view.LayoutInflater.createView(LayoutInflater.java:616)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at android.app.Activity.setContentView(Activity.java:2145)
at com.example.crashoveride007.roundwatchcanvas.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
at java.lang.Class.getConstructor(Class.java:531)
at java.lang.Class.getConstructor(Class.java:495)
at android.view.LayoutInflater.createView(LayoutInflater.java:580)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at android.app.Activity.setContentView(Activity.java:2145)
at com.example.crashoveride007.roundwatchcanvas.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Here is the MyView Custom View Class:
package com.example.crashoveride007.roundwatchcanvas;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
/**
* Created by Crash.Overide.007 on 2/24/16.
*/
public class MyView extends View{
Paint myPaint;
Bitmap image;
public MyView(Context context) {
super(context);
image = BitmapFactory.decodeResource(getResources(),R.drawable.ok);
myPaint = new Paint();
myPaint.setColor(Color.WHITE);
myPaint.setStrokeWidth(10);
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(image,137,0,null);
}
}
The MainActivity Class:
package com.example.crashoveride007.roundwatchcanvas;
import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView mTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.round_activity_main);
final RelativeLayout main = (RelativeLayout) findViewById(R.id.roundWatch);
}
}
And The XML for round_activity_main:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/roundWatch"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.crashoveride007.roundwatchcanvas.MainActivity"
tools:deviceIds="wear_round">
<com.example.crashoveride007.roundwatchcanvas.MyView
android:id="#+id/myView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Can anyone help me in removing this error and move over how to work with canvas in a wear activity?
Thank you.
You need to provide additional constructors for your view to inflate properly. At a minimum, you'll need one that takes both a Context and an AttributeSet as parameters, like this:
public MyView(Context context) {
this(context, null);
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
...
}
According to the View documentation, this "second form should parse and apply any attributes defined in the layout file."
You generally ought to override the other two standard View constructors as well:
http://developer.android.com/reference/android/view/View.html#pubctors
I've been trying to show a PreferenceFragment inside of a dialogFragment but im not sure how...
I tried to put the preferencefragment in a layout
<?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">
<fragment
android:id="#+id/settings_fragment"
android:name="com.example.test.Fragments.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
then using it in the onCreateView
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreate(savedInstanceState);
val view = inflater!!.inflate(R.layout.dialog_preference, container, false)
return view
}
On my main activity im calling it like this:
override fun onClick(view: View) {
val id = view.id
when (id) {
R.id.btnSettings -> {
val dialog = SettingsDialog();
dialog.onCancel(object : DialogInterface {
override fun cancel() {
setTheme()
}
override fun dismiss() {
}
})
dialog.show(fragmentManager, null);
}
}
}
The first time i call it, it shows up but on the second try. It crashes..
Is there another way to show a PreferenceFragment in a dialog?
Could someone please let me know how to do that?
Thank you
This is the error message im getting
android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.example.test.Dialog.SettingsDialog.onCreateView(SettingsDialog.kt:20)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:834)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #5: Duplicate id 0x7f0e0080, tag null, or parent id 0xffffffff with another fragment for com.example.test.Fragments.SettingsFragment
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2120)
at android.app.Activity.onCreateView(Activity.java:5328)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:34)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.example.test.Dialog.SettingsDialog.onCreateView(SettingsDialog.kt:20)
at android.app.Fragment.performCreateView(Fragment.java:2053)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.BackStackRecord.run(BackStackRecord.java:834)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I found the answer in another post:
Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment
So when i added this to my onDestroyView
override fun onDestroyView() {
super.onDestroyView()
val frag = fragmentManager.findFragmentById(R.id.settings_fragment) as SettingsFragment?;
if (frag != null)
fragmentManager.beginTransaction().remove(frag).commit();
}
Everything works fine. If anyone can think of a better way to create a preference dialog please do let me know