如何编辑我的课程

时间:2016-12-04 07:45:08

标签: c# visual-studio class oop constructor

我正在学习C#中的OOP,我在编码过程中遇到了问题。我想用构造函数创建一个类,它将通过public class Klasa { int zarobki; string nazwisko; string stanowisko; public Klasa(string a, string b, string c) { a = (Console.ReadLine()); b = (Console.ReadLine()); c = (Console.ReadLine()); zarobki = int.Parse(a); nazwisko = b; stanowisko = c; } } 读取属性。不幸的是,我得到了一个我无法理解的奇怪错误。

这是我的班级:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: ir.mototel.mototel, PID: 4899
                  java.lang.OutOfMemoryError: Failed to allocate a 490012 byte allocation with 316664 free bytes and 309KB until OOM
                      at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                      at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                      at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
                      at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
                      at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
                      at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
                      at android.content.res.Resources.loadDrawable(Resources.java:2540)
                      at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
                      at android.widget.ImageView.<init>(ImageView.java:152)
                      at android.widget.ImageView.<init>(ImageView.java:140)
                      at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:60)
                      at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
                      at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
                      at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1017)
                      at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1076)
                      at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                      at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at com.sepandar.xengine.singleVideo.view.DetailFragment.onCreateView(DetailFragment.java:182)
                      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
                      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
                      at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1643)
                      at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
                      at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
                      at android.support.v4.view.ViewPager.populate(ViewPager.java:1272)
                      at android.support.v4.view.ViewPager.populate(ViewPager.java:1120)
                      at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1646)
                      at android.view.View.measure(View.java:18788)
                      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                      at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                      at android.view.View.measure(View.java:18788)
                      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                      at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
                      at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
                      at android.view.View.measure(View.java:18788)
                      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                      at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:703)
                      at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:770)
                      at android.view.View.measure(View.java:18788)
                    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.

编译后,我收到以下错误:

  

“严重性代码说明项目文件行抑制状态   错误CS7036没有给出对应的参数   需要'Klasa.Klasa的正式参数'a'(字符串,字符串,   ')ConsoleApplication17 c:\ users \ dell \ documents \ visual studio   2015 \ Projects \ ConsoleApplication17 \ ConsoleApplication17 \ Program.cs 13有效   ”

1 个答案:

答案 0 :(得分:0)

你应该从其他地方调用构造函数。在控制台应用程序中像这样:

void Main()
{
    var a = (Console.ReadLine());
    var b = (Console.ReadLine());
    var c = (Console.ReadLine());
    Klasa k = new Klasa(a,b,c);
}

然后你的课应该是这样的:

public class Klasa
{
    int zarobki;
    string nazwisko;
    string stanowisko;
    public Klasa(string a, string b, string c)
    {
        zarobki = int.Parse(a);
        nazwisko = b;
        stanowisko = c;
    }
}

这解决了你的问题,但你在结构上被误导了。我认为你应该在开始阅读代码之前先阅读一本书或一篇文章。