Reputation: 1
Hey Guys i am relativly new to android development and working on my first project. I followed some YouTube tutorials like this one, to implement a Recyclerview in a fragment. The data for the item is read from a SQLite Database. Before inserting the testdata my App opens and does not crash but as soon as i have inserted one row of data the app instantly crashes when i try to open that fragment.I hope you can help me and sorry for the long apendix.
2020-12-02 22:03:58.259 26079-26079/com.example.moneymanager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.moneymanager, PID: 26079
android.view.InflateException: Binary XML file line #22 in com.example.moneymanager:layout/transaction_list_item: Binary XML file line #22 in com.example.moneymanager:layout/transaction_list_item: Error inflating class Linearlayout
Caused by: android.view.InflateException: Binary XML file line #22 in com.example.moneymanager:layout/transaction_list_item: Error inflating class Linearlayout
Caused by: java.lang.ClassNotFoundException: android.view.Linearlayout
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.view.LayoutInflater.createView(LayoutInflater.java:815)
at android.view.LayoutInflater.createView(LayoutInflater.java:776)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:913)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:930)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:950)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at com.example.moneymanager.TransactionAdapter.onCreateViewHolder(TransactionAdapter.kt:31)
at com.example.moneymanager.TransactionAdapter.onCreateViewHolder(TransactionAdapter.kt:13)
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7078)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6235)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1762)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1762)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:530)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
2020-12-02 22:03:58.260 26079-26079/com.example.moneymanager E/AndroidRuntime: at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:786)
at android.view.View.layout(View.java:22085)
at android.view.ViewGroup.layout(ViewGroup.java:6290)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3333)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2810)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1930)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7988)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1154)
at android.view.Choreographer.doCallbacks(Choreographer.java:977)
at android.view.Choreographer.doFrame(Choreographer.java:893)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1139)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Linearlayout" on path: DexPathList[[zip file "/data/app/com.example.moneymanager-r4ktffjKddVGd51sWsQfMg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.moneymanager-r4ktffjKddVGd51sWsQfMg==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 75 more
2020-12-02 22:03:58.300 26079-26079/com.example.moneymanager I/Process: Sending signal. PID: 26079 SIG: 9
This is my Adapter class:\
class TransactionAdapter(var mContext: Context, var mCursor: Cursor) :
RecyclerView.Adapter<TransactionAdapter.TransactionViewHolder>() { // this line is mentioned in the
error --> line 13
lateinit var mData:List<ListItem>
class TransactionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val amountText: TextView
val dateText: TextView
val categorieText: TextView
init {
amountText = view.findViewById(R.id.tvAmount)
dateText = view.findViewById(R.id.tvDate)
categorieText = view.findViewById(R.id.tvCategorie)
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TransactionViewHolder {
val inflater = LayoutInflater.from(mContext)
val view: View = inflater.inflate(R.layout.transaction_list_item, parent, false) // also this
line is mentioned --> line 31
return TransactionViewHolder(view)
}
override fun onBindViewHolder(holder: TransactionViewHolder, position: Int) {
if (!mCursor.moveToPosition(position)) {
return
}
val amount: String =
mCursor.getString(mCursor.getColumnIndex(TransactionList.TransactionEntry.COLUMN_AMOUNT))
val date: String =
mCursor.getString(mCursor.getColumnIndex(TransactionList.TransactionEntry.COLUMN_CREATEDAT))
val categorie: String =
mCursor.getString(mCursor.getColumnIndex(TransactionList.TransactionEntry.COLUMN_CATEGORIE))
holder.amountText.text = amount
holder.dateText.text = date.toString()
holder.categorieText.text = categorie
}
override fun getItemCount(): Int {
return mCursor.getCount()
}
fun swapCursor(newCursor: Cursor) {
if (mCursor != null) {
mCursor.close()
}
mCursor = newCursor
if (newCursor != null) {
notifyDataSetChanged()
}
}
}
//--------------------------------------------------------------------- this is my Fragment class:
class ListFragment:Fragment(R.layout.fragment_list) {
private lateinit var transactionDB: SQLiteDatabase
private lateinit var adapter:TransactionAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val dbHelper = TransactionDBHelper(activity)
transactionDB = dbHelper.writableDatabase
}
private fun addTransactionItem(){
transactionDB.execSQL("INSERT INTO transactionList (type, amount, categorie, createdAt)
VALUES('r', 10, 'test', CURRENT_TIMESTAMP)")
adapter.swapCursor(getAllItems())
}
private fun getAllItems(): Cursor {
return transactionDB!!.query(
TransactionList.TransactionEntry.TABLE_NAME,
null,
null,
null,
null,
null,
TransactionList.TransactionEntry.COLUMN_CREATEDAT + " DESC")
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_list, container, false)
val rvRecyclerView = view.findViewById<RecyclerView>(R.id.rvRecyclerView)
rvRecyclerView.layoutManager = LinearLayoutManager(activity)
adapter = TransactionAdapter(activity!!, getAllItems())
rvRecyclerView.adapter = this.adapter
addTransactionItem() // inserting one row of test data
return view
}
}
Upvotes: 0
Views: 186
Reputation: 54204
You have a typo in your layout file: the second "L" in LinearLayout
should be capitalized but you have it lowercase. Replace <Linearlayout ...>
with <LinearLayout ...>
. You'll also have to fix the closing tag.
Upvotes: 1
Reputation: 152817
You have a typo. The name of the layout is LinearLayout
with two capital L
s, not Linearlayout
.
Upvotes: 1