我在MainActivity上有这个代码,我继续错误地开始表达错误,错误“;”在我的OnActivitys参数上预期和预期你将如何解决这个问题。我正在研究Room上的这个教程和关于codelabs https://codelabs.developers.google.com/codelabs/android-room-with-a-view/index.html?index=..%2F..%2Findex#13的观点,但如果我将它复制粘贴到编辑器中它仍然会给我一个错误。请提前帮助和谢谢。我还检查了这个,但仍然没有工作Error Message on Main Activity: 'illegal start of expression'
package com.example.jenso.paperseller;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class MainActivity extends AppCompatActivity {
CustomerDatabase database;
FloatingActionButton fab;
private CustomerViewModel mCustomerViewModel;
public static final int NEW_CUSTOMER_ACTIVITY_REQUEST_CODE = 1;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
RecyclerView recyclerView = findViewById(R.id.recycler);
final PapperRecyclerAdapter adapter = new PapperRecyclerAdapter(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
mCustomerViewModel = ViewModelProviders.of(this).get(CustomerViewModel.class);
mCustomerViewModel.getmAllCustomers().observe(this, new Observer<List<Customer>>() {
@Override
public void onChanged(@Nullable List<Customer> customers) {
adapter.setCustomer(customers);
}
});
public void onActivityResult(final int requestCode, final int resultCode, final Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == NEW_CUSTOMER_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
Customer customer = new Customer(data.getStringExtra(CreateCustomer.EXTRA_REPLY), data.getStringExtra(CreateCustomer.SECOND_REPLY),data.getStringExtra(CreateCustomer.THIRD_REPLY),data.getStringExtra(CreateCustomer.FOURTH_REPLY));
mCustomerViewModel.insert(customer);
} else {
Toast.makeText(
getApplicationContext(),
R.string.empty_not_saved,
Toast.LENGTH_LONG).show();
}
}
fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, CreateCustomer.class);
startActivityForResult(intent, NEW_CUSTOMER_ACTIVITY_REQUEST_CODE);
}
});
recyclerView.setAdapter(adapter);
}
}