Android Studio,在不同的文件中调用不同的类

时间:2014-11-02 02:04:38

标签: java android android-studio

我已经编写了下面的代码片段来引用名为Forecast Fragment的类,并运行应用程序。但是在第33行,我收到了错误#34;无法解析符号' android' "

package com.example.sunshinepre_beta;

import android.os.Bundle;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState == null) {
        int commit = getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new com.example.android.sunshinepre_beta.app.ForecastFragment())
                .commit();
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}


}     

1 个答案:

答案 0 :(得分:0)

new com.example.android.sunshinepre_beta.app.ForecastFragment()替换为new ForecastFragment()

同时将ForecastFragment.java移动到MainActivity所在的同一文件夹中。