question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error: <identifier> expected topLevelClass = BaseFragment<T, D>.class

See original GitHub issue

Hi Everybody, So I mentioned this yesterday on stackoverflow here i Have issues when try to use inject ViewModel to BaseFragment with by viewModels() extension so i used Factory to inject it when i do that my BaseFragment Have tow generic type and it show me that error

error: <identifier> expected topLevelClass = BaseFragment<T, D>.class ^error: [Hilt]

and the Generated Class is BaseFragment_GeneratedInjector :

@OriginatingElement(
    topLevelClass = BaseFragment<T, D>.class
)

@GeneratedEntryPoint
@InstallIn(FragmentComponent.class)
@Generated("dagger.hilt.android.processor.internal.androidentrypoint.InjectorEntryPointGenerator")
public interface BaseFragment_GeneratedInjector {
  void injectBaseFragment(BaseFragment baseFragment);
}

so i try this workgound in this issues

and it show same error and new Error says :

**``` [Hilt] Processing did not complete. See error above for details.error: [Hilt] @AndroidEntryPoint class expected to extend Hilt_ContactUsFragment. Found: BaseFragment


and my baseFragment is so simple : 

`@AndroidEntryPoint
abstract class BaseFragment<T : ViewModel,D : ViewDataBinding>() : Fragment() {


lateinit var viewModel: T by viewModels()


 }`

thanks in Advanced 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
bcorsocommented, Aug 12, 2020

Hey @ayoubdevv,

Thanks for reporting this issue!

This is definitely a bug on our end. We shouldn’t be including the type parameters in @OriginatingElement(topLevelClass = BaseFragment<T, D>.class). I’ll send out a fix.

In the mean time, you should be able to work around this issue by putting the @AndroidEntryPoint annotation on the subclass instead. So something like this should work around the issue since the subclass doesn’t have type parameters itself.

// Put the annotation here instead of on the base class.
@AndroidEntryPoint
class MyFragment: BaseFragment<MyViewModel, MyViewDataBinding>() {
  ...
}
1reaction
bcorsocommented, Sep 29, 2021

@8991hnim it’s likely that this is due to missing transitive dependencies in the classpath during compilation. Hilt has the aggregating task flag to fix these issues automatically. Can you try enabling the flag by adding the following in your application’s build.gradle file:

hilt {
    enableAggregatingTask = true
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

<identifier> expected android Hilt - kotlin - Stack Overflow
You can fix this by moving @AndroidEntryPoint from abstract class with parameters into child class without type parameters.
Read more >
How to Handle the <Identifier> Expected Error in Java - Rollbar
The expected error in Java occurs when an expression statement is written outside of a constructor/method/instance initialization block.
Read more >
CS 111: Common Java Errors - CS-People by full name
1 error found: File: Test.java [line: 7] Error: Test.java:7: cannot find symbol symbol : variable my_method location: class Test
Read more >
How to Fix Java Error – Identifier Expected - Hello Code
The identifier expected error is a compilation error, which means the code doesn't comply with the syntax rules of the Java language. For ......
Read more >
Solutions to Exercises - Springer Link
compiler reports an error because the subclass constructor attempts to ... only appear in the upper levels of class hierarchies, where they are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found