Cannot read property setState of undefined

This will be a very quick guide for the above error.

This is common to have on the react using class or stateful component.

Take the following example


import React, {Component} from 'react';
class App extends Component {
    constructor() {
        super();
        this.state = {name: "default"};
    }

    keyHandler(event) {
        this.setState({name: event.target.value})
    }

    render() {
        return (
            
The name is {this.state.name}
<input id="name" onKeyUp={this.keyHandler} /≶
); } }

if you have something like the above one, where you haven’t bind the method to the class, then the error will happen.

Just adding

this.keyHandler = this.keyHandler.bind(this);

in the constructor will handle the issue.

You don’t have permission to access / on this server. Apache error

Apache refusing to serve with you don’t have permission to access error

Here are things to fix the problem

Have your config in your apache config like this:


       ServerName someWebname.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        
                Options All
                AllowOverride All
                require all granted
        

1. Make sure the directory you are accessing has at least 755 permission mode
2. Make sure to restart the server after you change the configs
3. Check if you have .htaccess file with different setting
4. In some cases, make sure the directory is accessible by apache – www-data.

The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path error in java webapp

If you are using eclipse, this might be due to project facet, right click on the project, go to project facet and select Runtimes and check the server you have configured.

if the app you are running is not spring or other web app framework that already comprised of servlet, then you need to add servlet to the build path.

You can add the servlet either through dependency management tools like gradle and maven or you can add it to the project lib file and compile it.

Also, you can add the dependency to servlet in your pom and get rid of the problem.


<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>

spring boot

Spring Data error: getOutputStream() has already been called for this response

Spring data with spring boot error when using mapping

Spring boot has made life of the java developers a bliss. Thanks a million for the dedicated guys in spring.

Saying that, if you are working typical database related project with spring boot, you might have some error like this


java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:624) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211) ~[tomcat-embed-core-8.5.16.jar!/:8.5.16]
Continue reading Spring Data error: getOutputStream() has already been called for this response

No Persistence provider for EntityManager named Hibernate error

No Persistence provider for EntityManager named

If you are working on hibernate, then there are two ways to provide the configuration to it. Either you would be using hibernate.cfg.xml or persistence.xml

In both cases, hibernate would be using the information like the connection string information and classes associated with tables.

If you are using persistence.xml and you are getting No Persistence provider for EntityManager named error, then there the following would be an issue and here is how you solve those.
Continue reading No Persistence provider for EntityManager named Hibernate error

apache error

Java Tomcat error: can not access a member of class with modifiers

Class org.apache.catalina.core.DefaultInstanceManager can not access a member of class with modifiers “” sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)

If you are on tomcat/or anyother webserver for J2EE and getting this error, then the most probable servlet you have would look like this


package package;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

class MyServletClass extends HttpServlet {
...
...
...
}

The fix:

You have missed the class modifier public

public class MyServletClass

Should solve the problem

You asked to pull from the remote but did not specify the branch github error

asked to pull from remote but did not specify the branch github error

Mostly, you got a new repository or even existing one and you are trying to interact with it.

The above problem would be happening this time.

Git would allow you to have many branches of the same repository. So when you try to interact with the repository and you didn’t specify which branch then this would be the problem.

Because this is not the default configured remote
for your current branch, you must specify a branch on the command line

The tasks you are trying to do might be

git pull
git push or even others.

Solution

The first thing you want to do would be to check what branch you are in.

git branch

If you see master in there * master then do

git pull origin master

This would take care of the problem

Maven error Annotations are not supported in -source 1.3

The Error

Are you using annotations in your project?

If so, you will get this error if you try to do mvn compile or mvn install.

You may have also seen this if you are building your project on eclipse as well.

The solution

The default maven relies on JDK 1.3 for its building the project and you might be using a JDK above 1.3. Also, JDK 1.3 does not implement annotations.

The solution is to tell the maven the current non-1.3 JDK you are using on you pom.xml file.


<project>
.
.

  <build> 
    <plugins> 
      <plugin> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>2.3.2</version> 
        <configuration> 
          <source>1.8</source> 
          <target>1.8</target> 
        </configuration> 
      </plugin> 
     </plugins> 
   </build> 
</project>

For the source and target you will provide your current JDK you are using.

resources can not be added

eclipse j2ee error There are No resources that can be added or removed from the server

Eclipse showing There are No resources that can be added or removed from the server when adding project

If you are trying to test the java web application (j2ee) on your local machine with built in eclipse support and getting error, then it is related to project facet.

Here is how you can solve the error There are No resources that can be added or removed from the server coming from eclipse

1. right click on your web project in eclispe

2. Select properties
properties

3. Select Project facets
project-facets

4. Select Dynamic Web Module
select-dynamic-web-module

5. Click on apply and then click on OK

This will solve the problem.

See also: How to resolve class pass error when working with maven