Categories
discuss

Trouble trying to build app with Jenkins and latest android plugin 3.0.0-alpha8

I have the Android studio 3.0 Canary preview and am able to build fine there. When I try to build on jenkins with gradlew I receive

Could not find com.android.databinding:baseLibrary:3.0.0-alpha8.

I thought maybe the google() repo wasn’t working but you’d think that would error out itself so I replaced

google()

with

maven { url 'https://maven.google.com' }

and I still get the same error. The only reference that I have in my build.gradle for databinding is

android {
   dataBinding.enabled = true
}

my gradle wrapper has a distribution url of

distributionUrl=https://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip

does anyone have an Idea of what I’m doing wrong or let me know if you need more information.

Answer

Same error here.

It’s because you use Android Studio Canary Version.

Build Tools are include in package directly:

android-studiogradlem2repositorycomandroidtoolsbuildgradle3.0.0-alpha9
Categories
discuss

Property ‘entries’ does not exist on type ‘ObjectConstructor’

I’m working on an ng2 implementation. I’m using the following function call to convert an object to an array:

var authors = Object.entries(responseObject.Authors);

This is a standard js function. However, the ts compiler returns the following error:

"Property 'entries' does not exist on type 'ObjectConstructor'"

Based on a quick google it appears that the solution may be to change the compilerOptions target property from es5 to es6. However, after some previous research for a previous issue, I thought that I was able to leverage es6 functionality by including the additional “lib” property on my tsconfig.json below:

  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../Scripts/",
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "moduleResolution": "node",
    "lib": [
      "es2015",
      "dom"
    ]
  }

I also tried changing the target property to es2015 and then rebuilt the project and executed “typescriptUsingTsConfig” but I still get the same error. Any idea what I can do here in order to leverage the Object.entries() function?

Answer

You’re quite correct that changing target is the wrong approach and changing lib is the correct approach, however you have specified the wrong version of the language. According to MDN, Object.entries was officially added in the ES2017 specification.

"lib": ["es2017"]

is therefore what you must specify instead*.

If you wish to add only the declarations for the methods of the Object function that were added in ES2017, TypeScript allows you to specify a more granular value.

"lib": ["es2017.object"]

As noted by Alexander Bird, by default, the implicit value of the "lib" option is dependent on the value specified for "target" if present.

For example:

"target": "es2017"

Will cause the correspondingly prefixed "lib.*" to be included by default unless "lib" is specified explicitly.

Note that you will likely wish to add a polyfill of the implementation itself, such as the this one, to ensure this works in older runtimes.

Note: as an alternative you can specify any later version

"lib": ["es2020"]

or naturally even

"lib": ["esnext"] 

This last will include the declarations for the very latest standard library features known to the TypeScript language. As it represents a moving target, this option should be used with care since polyfilling all of the corresponding runtime is by definition a complex task that will require research and may involve loading different polyfills depending on your target runtime.

Additionally, the array nature of the "lib" option allows you to combine multiple values to match your runtime. For example, to match es2015 capable web browsers with the addition of these object methods as provided by a polyfill, you can write

"lib": ["es2015", "es2017.object", "dom"]

See the TypeScript Handbook for additional details.

Note: a few commenters asked why it would be wrong to change --target instead of --lib as both would enable the code to type check? The reason is that --target changes how the code is transpiled. For example, "target": "es2017" means that async functions won’t be transformed for older runtimes. It is incorrect because the intent was to enable the use of additional libraries, not to change the output syntax and it is therefore important to distinguish between syntactic features and library features.

Categories
discuss

package javax.jnlp is declared in module java.jnlp, which is not in the module graph

I have a project that uses Java webstart technology. I decided to upgrade the Java version from 8 to 9. However, I faced the following error on compiling:

error: package javax.jnlp is not visible
import javax.jnlp.DownloadServiceListener;
        ^
(package javax.jnlp is declared in module java.jnlp, which is not in the module graph)

I tried to include C:Program FilesJavajdk-9libjavaws.jar to the classpath, but still the same issue remains.

Answer

It looks like java.jnlp is not resolved by default for code on the class path (much like Java EE modules). The solution is to add it explicitly with --add-modules java.jnlp (both javac and java accepts that parameter).

This option is discussed in JEP 261: Module System or in this blog post.

Categories
discuss

Avoid passing null as the view root (when inflating custom layout in AlertDialog)

Trying to inflate a custom layout for an AlertDialog, but keep getting this waring. I’ve seen several different solutions to this but don’t know which is correct for my scenario. What is the actual correct way of getting rid of this null warning?

Avoid passing null as the view root (need to resolve layout parameters on the inflated layout’s root element)

@Override
public void onClick(View v) {
  AlertDialog alertDialog = new 
  AlertDialog.Builder(getActivity()).create();

  LayoutInflater inflater = getActivity().getLayoutInflater();
  View content = inflater.inflate(R.layout.dialog_customd, null);
  alertDialog.setView(content);

  alertDialog.show();
}

Answer

Do it like this:

View content = inflater.inflate(R.layout.dialog_customd, parent, false);
Categories
discuss

React cannot read property map of undefined

I am very new to react and I am trying to bring in data from a rails api but I am getting the error TypeError: Cannot read property 'map' of undefined

If i use the react dev tools I can see the state and I can see the contacts if I mess around with it in the console using $r.state.contacts Can someone help with what I have done wrong? my component looks like this:

import React from 'react';
import Contact from './Contact';

class ContactsList extends React.Component {
  constructor(props) {
    super(props)
    this.state = {}
  }

  componentDidMount() {
    return fetch('http://localhost:3000/contacts')
      .then(response => response.json())
      .then(response => {
        this.setState({
          contacts: response.contacts
        })
      })
      .catch(error => {
        console.error(error)
      })
  }

  render(){
    return(
     <ul>
        {this.state.contacts.map(contact => { return <Contact contact{contact} />})}
      </ul>
    )
  }
}

export default ContactsList;

Answer

Cannot read property ‘map’ of undefined, Why?

Because this.state is initially {}, and contacts of {} will be undefined. Important point is, componentDidMount will get called after initial rendering and it is throwing that error during first rendering.

Possible Solutions:

1- Either define the initial value of contacts as [] in state:

constructor(props) {
  super(props)
    this.state = {
       contacts: []
    }
}

2- Or put the check before using map on it:

{this.state.contacts && this.state.contacts.map(....)

For checking array, you can also use Array.isArray(this.state.contacts).

Note: You need to assign unique key to each element inside map, check the DOC.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..