I am making an app in angular nativescript, I am using web services, but when I try to do a http request in Android 4, it throws this error. But when I do it on Android 9, there are no errors and it makes the insert.
app.module.ts
import { NgModule, NO_ERRORS_SCHEMA } from "#angular/core";
import { NativeScriptModule, NativeScriptHttpClientModule, NativeScriptFormsModule } from "#nativescript/angular";
import { NgShadowModule } from 'nativescript-ng-shadow';
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { LoginComponent } from './components/login/login.component';
import { HeaderComponent } from './components/partials/header/header.component';
import { FooterComponent } from './components/partials/footer/footer.component';
import { IndexComponent } from './components/index/index.component';
import { RegistrarComponent } from './components/registrar/registrar.component';
#NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule,
AppRoutingModule,
NativeScriptHttpClientModule,
NgShadowModule,
NativeScriptFormsModule
],
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
IndexComponent,
RegistrarComponent,
],
providers: [],
schemas: [
NO_ERRORS_SCHEMA
]
})
/*
Pass your application module to the bootstrapModule function located in main.ts to start your app
*/
export class AppModule { }
service
post(url: string, body: Object): Observable<any> {
return this.http.post(this.apiUrl() + url, JSON.stringify(body), { headers: this.getHeaders() })
.pipe(catchError(function (error: any) {
return throwError(error || 'Server error');
}));
}
app.gradle
android {
defaultConfig {
minSdkVersion 17
generatedDensities = []
flavorDimensions "versionCode"
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Thanks for your time
Try to this:- Add HttpClientModule In App Module.
import { NgModule, NO_ERRORS_SCHEMA } from "#angular/core";
import { NativeScriptModule, NativeScriptHttpClientModule,
NativeScriptFormsModule } from "#nativescript/angular";
import { NgShadowModule } from "nativescript-ng-shadow";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { LoginComponent } from './components/login/login.component';
import { HeaderComponent } from
'./components/partials/header/header.component';
import { FooterComponent } from
'./components/partials/footer/footer.component';
import { IndexComponent } from './components/index/index.component';
import { RegistrarComponent } from
'./components/registrar/registrar.component';
import { HttpClientModule } from "#angular/common/http";
#NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule,
AppRoutingModule,
NativeScriptHttpClientModule,
NgShadowModule,
HttpClientModule,
NativeScriptFormsModule
],
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
IndexComponent,
RegistrarComponent,
],
providers: [],
schemas: [
NO_ERRORS_SCHEMA
]
})
/*
Pass your application module to the bootstrapModule function located in
main.ts to start your app
*/
export class AppModule { }
And Add One Line In AndroidManifest.xml File:-
<application
android:usesCleartextTraffic="true">
File Location:- App_Resource->Android->src->main
Related
import { NgModule } from '#angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { Ng2SearchPipeModule } from 'ng2-search-filter';
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
Ng2SearchPipeModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
IntelliJ is giving me the message " Class Ng2SearchPipeModule is not an Angular module ". Is there a way to fix this?
Check Ng2SearchPipeModule to have proper decorator. It has to be NgModule like your app module has.
#NgModule({
declarations: [
...
],
imports: [
...
],
providers: [],
})
export class Ng2SearchPipeModule { }
Also, check if the import path is correct
I have a REST application using Jax-RS and Angular 2, Apache 8.5 and Postgres database using Hibernate.
The problem is when I save a new object, the GET from my list runs before the POST run completely. Here are the codes.
tabela-servicos.component.ts
import { Component, OnInit } from '#angular/core';
import { Servico } from '../servico';
import { CrudServicosService } from '../crud-servicos.service';
#Component({
selector: 'app-tabela-servicos',
templateUrl: './tabela-servicos.component.html',
styleUrls: ['./tabela-servicos.component.css']
})
export class TabelaServicosComponent implements OnInit {
titulo = "Tabela de Serviços";
servicos: Servico[] = [];
constructor(private servicoService: CrudServicosService) {
}
ngOnInit() {
console.log('called ngOnInit')
this.servicoService.getServicos()
.subscribe(s => {
console.log(s);
this.servicos = s;
}, erro => console.log(erro));
}
remover(servico: Servico){
this.servicoService.removerServico(servico)
.subscribe(() => {
let novosServicos = this.servicos.slice(0);
let indice = novosServicos.indexOf(servico);
novosServicos.splice(indice, 1);
this.servicos = novosServicos;
});
}
}
form-servicos.component.ts
import { Component, OnInit } from '#angular/core';
import { CrudServicosService } from '../../app/crud-servicos.service';
import { Servico } from '../../app/servico';
import { Router, ActivatedRoute } from '#angular/router';
#Component({
selector: 'app-form-servicos',
templateUrl: './form-servicos.component.html',
styleUrls: ['./form-servicos.component.css']
})
export class FormServicosComponent implements OnInit {
titulo = "Cadastro de Servicos";
servico: Servico;
codigo;
constructor(private servicoService: CrudServicosService,
private router: Router,
private rota:ActivatedRoute) { }
ngOnInit() {
this.codigo = this.rota.snapshot.params['cod'];
if(isNaN(this.codigo)){
this.servico = new Servico();
} else {
this.servico = Object.assign({},
this.servicoService.getServicoPorCodigo(this.codigo));
}
}
salvarServico(){
if(isNaN(this.codigo)){
this.servicoService.adicionarServico(this.servico)
} else {
this.servicoService.atualizaServico(this.codigo, this.servico);
}
// console.log("waiting 2 seconds to return page list...");
// setTimeout(()=>{
this.router.navigate(['/lista']);
// },2000);
}
cancelar(){
this.router.navigate(['/lista']);
}
}
ServicoResource.java
package resource;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.google.gson.Gson;
import dao.ServicoDAO;
import model.Servico;
#Path("servico")
public class ServicoResource {
private static ServicoDAO servicoDao = new ServicoDAO();
#GET
#Path("servicos")
#Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public Response test() {
List<Servico> serv = servicoDao.getList();
System.out.println("GET Objectos from Jax-RS");
System.out.println("");
return Response.ok(serv).build();
}
#Path("servicos/delete/{id}")
#DELETE
public Response removeProduto(#PathParam("id") long id){
System.out.println("DELETE Object ID: " + id + " Jax-RS ");
System.out.println("");
servicoDao.remover(id);
return Response.ok().build();
}
#POST//consume o objeto enviado pro back-end
#Consumes(MediaType.APPLICATION_JSON)
public Response adiciona(String conteudo){
Gson gson = new Gson();
Servico s = gson.fromJson(conteudo, Servico.class);
servicoDao.salvar(s);
System.out.println("POST Object Jax-RS");
System.out.println("");
return Response.status(200).build();
}
}
When I reload the list page, after the saved object, it appears.
When I use the code below in the form-servicos.component.ts class, it works, but I know this is a bad practice.
console.log ("waiting 2 seconds to return page list ...");
setTimeout (() => {
This.router.navigate (['/ list']);
}, 2000);
Does anyone know how to resolve this problem from the list being requested before the object is persisted ???
(Posted on behalf of the OP).
This was solved.
adicionarServico(servico: Servico){
console.log("Called persist POST "+JSON.stringify(servico));
return this.http.post(this.baseUrl + '/servico', JSON.stringify(servico), {headers: this.headers});
}
I changed my crud-service.ts to return an Observable < Responde > and using it in:
salvarServico(){
this.servicoService.adicionarServico(this.servico)
.subscribe(() => {
console.log("Saved Success");
this.router.navigate(['/lista']);
});
}
I am creating a mod but the texture of a block (the only one) loads only in the inventory and when it gets dropped, hope you can help me, I'm using the 1.8 MDK.
Blockstates:
{
"variants"": {
"normal": {"model": "horsenexus:horse_block"},
}
}
Models, block:
{
"parent": "block/cube_all",
"textures": {
"down": "horsenexus:blocks/horse_block_down",
"up": "horsenexus:blocks/horse_block_top",
"north": "horsenexus:blocks/horse_block_north",
"east": "horsenexus:blocks/horse_block_east",
"south": "horsenexus:blocks/horse_block_south",
"west": "horsenexus:blocks/horse_block_west"
}
}
Models, item:
{
"parent": "horsenexus:block/horse_block",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}
And the codes:
package com.crazyhoorse961.core.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
public class HorseBlock extends Block{
public HorseBlock(Material materialIn) {
super(materialIn);
this.setHardness(5.6F);
this.setResistance(56.34F);
this.setStepSound(this.soundTypeSnow);
}
}
And the last one:
package com.crazyhoorse961.core.init;
import com.crazyhoorse961.core.Reference;
import com.crazyhoorse961.core.blocks.HorseBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class Horse_Block {
public static Block horse_block;
public static void init()
{
horse_block = new HorseBlock(Material.clay).setUnlocalizedName("horse_block");
}
public static void register()
{
GameRegistry.registerBlock(horse_block, horse_block.getUnlocalizedName().substring(5));
}
public static void registerRenders()
{
registerRender(horse_block);
}
public static void registerRender(Block block)
{
Item item = Item.getItemFromBlock(block);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}
Thank you for trying to help me, have a good day.
Try changing the following line in your "Models, block" code
"parent": "block/cube_all",
into:
"parent": "block/cube",
As far as I'm aware 'cube_all' is only used when you use the same texture for all sides of your block.
I am having an item block rendering issue, as when I place the block, it renders correctly, but when I hold it in my hand, it has a missing texture/model.
An image of what I see is in the link: http://i.stack.imgur.com/atq1L.png
I have checked many times for the reason, and there is no error message in the console, there does not appear to be any problems with the JSON formatting, and there seems to be no problem in the code.
*By the way, the code for the block class is not too important because it is just a class that extends *Block.class, then gives the super with Material.stone
Here is my code for my blocks class:
package com.kraftymods.luckyblocks.init;
import com.kraftymods.luckyblocks.blocks.LuckyBlock;
import com.kraftymods.luckyblocks.blocks.itemblocks.LuckyBlockItem;
import com.kraftymods.luckyblocks.main.Reference;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class Blocks {
public static Block luckyblock;
public static void init(){
luckyblock = new LuckyBlock().setUnlocalizedName("luckyblock")[enter image description here][1].setCreativeTab(CreativeTabs.tabMisc);
}
public static void register(){
GameRegistry.registerBlock(luckyblock, LuckyBlockItem.class, luckyblock.getUnlocalizedName().substring(5));
}
public static void registerRenders(){
registerRender(luckyblock);
}
private static void registerRender(Block block){
Item item = Item.getItemFromBlock(block);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}
Here is the code for my JSON files:
Blockdata:
{
"variants": {
"normal": { "model": "luckyblocks:luckyblock" }
}
}
Block Model:
{
"parent": "block/cube_all",
"textures": {
"all": "luckyblocks:blocks/luckyblock"
}
}
Item Model:
{
"parent": "luckyblocks:block/luckyblock",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}
I appreciate the time you took to read this
Please make a class for clientside purposes in which you register your renderers
I have this for example:
public final class BlockRenderRegister {
public static void registerBlockRenderer() {
register(BlocksLibrary.blockDarkStone);
}
public static void register(Block block) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(Item.getItemFromBlock(block),
0,
new ModelResourceLocation(
ModHooks.MODID.toLowerCase() + ":" + BlocksLibrary.DARKSTONE,
"inventory"
)
);
}
}
And for loading your blocks I also suggest a seperate class(just for maintenance purposes
public class BlockLoader {
/**
* Loads all blocks into memory
* and populates the BlocksLibary
* with decent values.
*/
public static void loadBlocks() {
GameRegistry.registerBlock(
BlocksLibrary.blockDarkStone = new BlockDarkStone(Material.rock),
BlocksLibrary.DARKSTONE
);
}
}
I register the blocks in the PreInit event so the game knows my blocks.
#EventHandler
public void preInit(FMLPreInitializationEvent e) {
BlockLoader.loadBlocks();
}
And I call this from the FMLInitializationEvent in my main mod class to register the renderers.
#EventHandler
public void init(FMLInitializationEvent event) {
BlockRenderRegister.registerBlockRenderer();
}
I need to implement the below function_score query using Java APIs. I couldn't find any official documentation for function_score query in the Java API section of elasticsearch
"function_score": {
"functions": [
{
"boost_factor": "3",
"filter": {
"terms" : {"course_cd" : ["writ100", "writ112", "writ113"] }
}
}
],
"query": {
"match" : {
"party_id" : "12"
}
}
}
Please help!
Thanks to Jörg
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import java.util.Arrays;
import static org.elasticsearch.client.Requests.searchRequest;
import static org.elasticsearch.index.query.FilterBuilders.termsFilter;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.factorFunction;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
public class FunctionScoreTest {
public void testFunctionScore() {
SearchRequest searchRequest = searchRequest()
.source(searchSource().query(new FunctionScoreQueryBuilder(matchQuery("party_id", "12"))
.add(termsFilter("course_cd", Arrays.asList("writ100", "writ112", "writ113")), factorFunction(3.0f))));
}
}