Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';t指定对象的新值';s参数_Java_Android_Xml - Fatal编程技术网

Java Can';t指定对象的新值';s参数

Java Can';t指定对象的新值';s参数,java,android,xml,Java,Android,Xml,这是我的问题。在将另一个对象的参数与数据库对象的参数进行比较后,我无法指定新的参数值。我需要指定测试车的新值。make或make。XML代码似乎很好,所以问题应该在代码中。 这是我的密码: package com.j.caradvisor; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity;

这是我的问题。在将另一个对象的参数与数据库对象的参数进行比较后,我无法指定新的参数值。我需要指定测试车的新值。makemake。XML代码似乎很好,所以问题应该在代码中。 这是我的密码:

package com.j.caradvisor;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.j.models.Car;

public class Result extends AppCompatActivity {

    int i=0;
    int doors;
    String make;
    String model;
    String layout;
    String trunk;
    String gearbox;
    int price;
    int expeople;
    Car test_car = new Car(1, "testmake", "testmodel", "test_layuot", "testtrunk", "testgearbox", 1, 1);
    String final_car=make+""+model;
    TextView resultt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        resultt = (TextView) findViewById(R.id.result);
        test_car = getIntent().getParcelableExtra("test_car");
        doors = test_car.getDoors();
        make = test_car.getMake();
        model = test_car.getModel();
        trunk = test_car.getTrunk();
        gearbox = test_car.getGearbox();
        price = test_car.getPrice();
        expeople = test_car.getExpeople();
        this.getPackageName();
        //resultt.setText(final_car);
    }
    public void data(View view) {
        Car[] car;
        car = new  Car[12];
        car[0] = new Car(4, "Volkswagen", "Passat", "4 door saloon", "Spacious", "Both", 25000, 5);
        car[1] = new Car(2, "Mazda", "MX-5", "Roadster", "Small", "Both", 20000, 2);
        car[2] = new Car(2, "BMW", "2 series", "2 door coupe", "Spacious", "Both", 20000, 4);
        car[3] = new Car(3, "Volkswagen", "Golf", "3 door hatchback", "Spacious", "Both", 20000, 4);
        car[4] = new Car(5, "Peugeot", "308", "5 door hatchback", "Spacious", "Both", 20000, 5);
        car[5] = new Car(5, "Peugeot","508","Estate", "Spacious", "Both", 25000, 5);
        car[6] = new Car(5, "Ford", "S-Max", "Minivan", "Spacious", "Both", 28000,7);
        car[7] = new Car(5, "Ford", "Transit", "Van", "Spacious", "Manual", 20000, 9);
        car[8] = new Car(3, "Jeep", "Wrangler", "3 door SUV", "Spacious", "Automatic", 40000, 4);
        car[9] = new Car(5, "KIA", "Sportage", "5 door SUV", "Spacious", "Both", 25000, 5);
        car[10] = new Car(4, "Audi", "A7", "4 door coupe", "Spacious", "Both", 60000, 4);
        car[11] = new Car(5, "Peugeot", "208", "5 door hatchback", "Small", "Both", 14000, 5);
        for (Car aCar : car) {
            if ((test_car.getDoors() == aCar.getDoors())
                    && (test_car.getLayout().equals(aCar.getLayout()))
                    && (test_car.getTrunk().equals(aCar.getTrunk()))
                    && (test_car.getGearbox().equals(aCar.getGearbox()))
                    && (test_car.getPrice() <= aCar.getPrice())
                    && (test_car.getExpeople() <= aCar.getExpeople())) {

                test_car.setMake(aCar.getMake());
                make = test_car.getMake();
                //model=car[i].getModel();
                //test_car.setMake(make);
                //test_car.setModel(model);
                //resultt.setText(make);
                //resultt.setText(test_car.getMake());
            }
        }
        //resultt.setText(test_car.getMake());
        resultt.setText(make);
    }

    public void map_search(View view) {
        String uri = "http://maps.google.com/maps?saddr=" +test_car.getMake();
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        intent.setPackage("com.google.android.apps.maps");
        startActivity(intent);
    }
}
package com.j.caradvisor;
导入android.content.Intent;
导入android.net.Uri;
导入android.os.Bundle;
导入android.support.v7.app.AppActivity;
导入android.view.view;
导入android.widget.TextView;
进口com.j.models.Car;
公共类结果扩展了AppCompatActivity{
int i=0;
内部门;
串制;
弦模型;
字符串布局;
线状树干;
串齿轮箱;
国际价格;
输入专家;
汽车测试车=新车(1,“测试制造”、“测试模型”、“测试拉约”、“测试行李箱”、“测试变速箱”,1,1);
字符串final_car=make+“”+model;
文本视图结果;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u结果);
resultt=(TextView)findViewById(R.id.result);
测试车=getIntent().getParcelableExtra(“测试车”);
doors=测试车。getDoors();
make=测试车。getMake();
model=test_car.getModel();
trunk=test_car.getTrunk();
变速箱=测试车。获取变速箱();
price=test_car.getPrice();
expople=测试车。getexpople();
这个.getPackageName();
//结果setText(最终车辆);
}
公共无效数据(视图){
汽车[]汽车;
汽车=新车[12];
汽车[0]=新车(4辆,“大众”、“帕萨特”、“四门轿车”、“宽敞”、“双开”,25000辆,5辆);
汽车[1]=新车(2辆,“马自达”、“MX-5”、“跑车”、“小型”、“两者”,20000辆,2辆);
汽车[2]=新车(2辆,“宝马”、“2系”、“双门轿跑车”、“宽敞”、“双开”,20000,4);
汽车[3]=新车(3辆,“大众”、“高尔夫”、“三门掀背车”、“宽敞”、“双开”,20000辆,4辆);
汽车[4]=新车(5辆,“标致”、“308”、“5门掀背车”、“宽敞”、“双开”,20000,5);
汽车[5]=新车(5辆,“标致”、“508”、“地产”、“宽敞”、“两者皆有”、25000、5);
汽车[6]=新车(5辆,“福特”、“S-Max”、“小型货车”、“宽敞”、“两者皆有”,28000,7);
汽车[7]=新车(5辆,“福特”、“公交”、“厢式车”、“宽敞”、“手动”,20000辆,9辆);
汽车[8]=新车(3辆,“吉普”、“牧马人”、“三门SUV”、“宽敞”、“自动”,40000辆,4辆);
汽车[9]=新车(5辆,“起亚”、“运动型”、“5门SUV”、“宽敞型”、“双开型”、25000辆、5辆);
汽车[10]=新车(4辆,“奥迪”、“A7”、“四门双门轿跑车”、“宽敞”、“双门”,60000,4);
汽车[11]=新车(5辆,“标致”、“208”、“5门掀背车”、“小型”、“双开”,14000,5);
用于(汽车aCar:Car){
如果((test_car.getDoors()==aCar.getDoors())
&&(test_car.getLayout().equals(aCar.getLayout()))
&&(test_car.getTrunk().equals(aCar.getTrunk()))
&&(test_car.getGearbox()等于(aCar.getGearbox())
&&(test_car.getPrice()
if((test_car.getDoors()==aCar.getDoors())

它似乎总是返回false,因为您的测试车设置为1(我假设车[0]是门),所以

永远不要跑,这也取决于你付出的意图

test\u car=getIntent().getParcelableExtra(“test\u car”);


你有什么实际问题?汽车是可变类型吗?很小的观察结果:
test\u-Car
实例化中的“test\u-layout”拼写错误;“o”和“u”需要切换位置。Charles,谢谢,但它对一般的codeStultuske没有任何影响,我已经在专门的类中声明了所有的setter和getter。因此它是可变的。问题在于将make参数从数组的对象分配给String make或test_car.set.make。它只是不进行分配,而是返回默认值testm如果从以前的活动中,所有东西都包装得很好,我已经对它进行了测试。汽车[0]是汽车阵列的第一个对象。问题是,与“测试汽车”和“汽车[I]”参数相比,如果你的测试汽车有相同数量的门、相同的行李箱、相同的布局和变速箱(汽车[0]、汽车[3]、汽车[4]、汽车[5]),你想改变品牌(汽车[1])以及价格和预期人数(车[6],车[7])小于或等于测试的数量,对吗?
test_car.setMake(aCar.getMake());
make = test_car.getMake();`