我从其中一个模板创建了一个基本的 Android Studio 应用程序,并试图从 onCreate 中的预构建处理程序调用一个线程(可运行)。我所做的只是添加扩展 Runnable 的类,然后在处理程序中使用该类。无法弄清楚为什么我会收到编译错误:
找不到符号方法开始
这是唯一的错误,就行了
new Thread(example.start());
代码是:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
static class GetExample implements Runnable
{
public void run()
{
Log.i("GetExample class", "Inside GetExample::run()");
return;
}
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
Log.i("Inside onCreate()", "TestBed -- onClick() invoked");
try
{
GetExample example = new GetExample();
new Thread(example.start());
}
catch (IOException ex)
{
Log.i("Inside onCreate()", "TestBed -- IOException occurred");
}
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
. . .