React Native项目无法运行

时间:2018-08-14 07:58:51

标签: node.js react-native npm

当我在React Native中创建新项目并尝试在android仿真器中运行时,它将返回错误。我无法理解的问题是什么。emulator screen

2 个答案:

答案 0 :(得分:0)

比较新创建的项目和旧项目的package.json文件。在package.json文件中,将所有新项目的本机版本更改为旧项目。然后删除node_modules文件夹并运行npm install。然后运行新项目。我认为应该可以。

答案 1 :(得分:0)

最新的react native版本似乎存在一些问题。

使用以下命令创建项目。

using Foundation;
using System;
using UIKit;
using SQLite;
using System.Collections.Generic;
using System.IO;

namespace One
{
public partial class StudentDataBaViewController : UITableViewController
{
    private string pathToDatabase;
    private List<Student> students;

    public StudentDataBaViewController (IntPtr handle) : base (handle)
    {
        students = new List<Student>();
    }

    /*public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
    {
        if (segue.Identifier == "StuSegue")
        { // set in Storyboard
            var navctlr = segue.DestinationViewController as AddStudentViewController;
            if (navctlr != null)
            {
                var source = TableView.Source as StudentDataBaViewController;
                var rowPath = TableView.IndexPathForSelectedRow;
                var item = source.GetItem(rowPath.Row);
                navctlr.SetTask(this, item); // to be defined on the TaskDetailViewController
            }
        }
    } 
    */

    //connect to student_da.db database file and create a table named Student
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        //path of the database
        var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        pathToDatabase = Path.Combine(documentsFolder, "student_db.db");

        //connect database and create table
        using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
        {
            connection.CreateTable<Student>();
        }
     }

    //used to relaod or update new elements entered on the list
    public override void ViewDidAppear(bool animated)
    {
        base.ViewDidAppear(animated);

        students = new List<Student>();

        using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
        {
            var query = connection.Table<Student>();

            foreach (Student student in query)
            {
                students.Add(student);
                TableView.ReloadData();

            }
        }
    }

    public override nint RowsInSection(UITableView tableView, nint section)
    {
        return students.Count;
    }

    //make elements to be display on the database list
    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        UITableViewCell cell = tableView.DequeueReusableCell("student");
        var data = students[indexPath.Row];

        cell.TextLabel.Text = data.StudentName;
        cell.DetailTextLabel.Text = data.StudentId;

        return cell;
    }

    public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
    {
        return true;
    }

    public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, Foundation.NSIndexPath indexPath)
    {
        switch (editingStyle)
        {
            case UITableViewCellEditingStyle.Delete:
                // remove the item from the underlying data source
                students.RemoveAt(indexPath.Row);
                // delete the row from the table
                tableView.DeleteRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Fade);


                break;
            case UITableViewCellEditingStyle.None:
                Console.WriteLine("CommitEditingStyle:None called");
                break;
        }
    }

}

public class Student
{
    [PrimaryKey]
    public string StudentId
    {
        get;
        set;
    }

    public string StudentName
    {
        get;
        set;
    }

    public string StudentPassword
    {
        get;
        set;
    }

    public bool StudentAttendence
    {
        get;
        set;
    }
}
}