我正忙着使用非常基本的条码扫描器应用程序。我正在使用Angular / Nativescript,而且我正在使用nativescript-barcodescanner插件。条码扫描器插件在几小时前工作正常。我在app.component.ts中更改了一些内容,但没有特定于插件的内容。现在当我构建我的应用程序时,我可以在构建过程中看到它找到并使用插件但是在部署到genymotion模拟器后,我得到以下错误。我已经删除/重新安装了插件和Android平台,没有任何变化...知道我还能尝试/看看还有什么?从错误消息中可以看出它在app / tns_modules上寻找插件但我在app中没有tns_modules文件夹(不确定它是否在另一个目录中移动/构建......
我的错误:
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException:
Error calling module function
Error calling module function
Error: com.tns.NativeScriptException: Failed to find module: "nativescript-BarcodeScanner", relative to: /app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:220)
com.tns.Module.resolvePath(Module.java:60)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:244)
com.tns.Runtime.run(Runtime.java:238)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:17)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
android.app.ActivityThread.access$1500(ActivityThread.java:135)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:
我的app.module.ts:
import { NgModule } from "@angular/core";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptModule } from "nativescript-angular/platform";
import { HttpModule } from '@angular/http';
import { BarcodeScanner } from "nativescript-BarcodeScanner";
import { AppComponent } from "./app.component";
import { RestService } from './services/rest.service';
@NgModule({
imports : [
NativeScriptModule,
NativeScriptFormsModule,
HttpModule
],
declarations : [
AppComponent
],
providers : [
RestService,
BarcodeScanner],
bootstrap : [AppComponent]
})
export class AppModule {}
我的app.component.ts:
import { Component, Input, OnInit } from "@angular/core";
import { BarcodeScanner } from "nativescript-BarcodeScanner";
import { ProductModel } from './models/product';
import { RestService } from './services/rest.service';
@Component({
selector: "my-app",
templateUrl : "./app.component.html"
})
export class AppComponent implements OnInit {
public barcode: number;
public textBarcode: number;
@Input() product: ProductModel;
public constructor(private restService: RestService, private barcodeScanner: BarcodeScanner) {
}
submitTextBarcode() {
this.restService.getProduct(this.textBarcode)
.subscribe(
(res) => {
this.product = new ProductModel(res.BaseURI, res.CustomError, res.ProviderName, res.RequestFormData, res.RequestURI, res.ResponseCode, res.AvgQty1, res.AvgQty2, res.AvgQty3, res.BarCode, res.Description, res.POSDescription, res.POSPrice, res.ProductCode, res.PurchCount, res.StockOnHand); },
(res) => {
console.log("failure" + res);
}
);
}
submitBarcode(barcode: number){
this.restService.getProduct(barcode)
.subscribe(
(res) => {
this.product = new ProductModel(res.BaseURI, res.CustomError, res.ProviderName, res.RequestFormData, res.RequestURI, res.ResponseCode, res.AvgQty1, res.AvgQty2, res.AvgQty3, res.BarCode, res.Description, res.POSDescription, res.POSPrice, res.ProductCode, res.PurchCount, res.StockOnHand);
//console.log("returned product description: " + this.product.Description);
//console.log(res);
},
(res) => {
console.log("failure" + res);
}
);
//console.log("product: " + product);
}
public scan() {
this.barcodeScanner.scan({
formats : "EAN_13",
cancelLabel : "Stop scanning",
message : "Go scan something Use the volume buttons to turn on the flash",
preferFrontCamera : false,
showFlipCameraButton : false
}).then((result) => {
this.barcode = +result.text;
this.submitBarcode(this.barcode);
}, (errorMessage) => {
console.log("Error no scan" + errorMessage);
});
}
public ngOnInit() {
}
}
答案 0 :(得分:2)
对你的导入使用小写..它适用于我这边,所以我认为Angular-CLi对from "nativescript-BarcodeScanner";
中的CamelCase不满意