ActivityNotFoundException:无法找到在清单中声明的​​显式活动类

时间:2018-01-02 16:17:46

标签: java android activitynotfoundexception

我试图通过Intent发送内容(我认为这是我的错误的原因),我经常得到<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="btn-group"> <a href="#" class="btn blue" data-target="language" aria-expanded="false">Show language</a> <a href="#" class="btn blue" data-target="top_search" aria-expanded="false">Show search</a> <a href="#" class="btn blue" data-target="navigation" aria-expanded="false">Search navigation</a> </div> <div class="slideout-container"> <section id="top_search" class="container-box" aria-expanded="false"> Section search </section> <section id="language" class="container-box" aria-expanded="false"> Section language </section> <section id="navigation" class="main-navigation container-box" role="navigation" aria-expanded="false"> Navigation </section> </div>。 这是将数据发送到ActivityNotFoundException的类(称为温度的字符串)

我在堆栈上发现了类似的问题,其中有人写道问题是在活动通过其生命周期方法之前实例化意图引起的,但我不确定这是否是一个问题,我该怎么做才能解决它

Tab1.class

我已在AndroidManifest.xml中声明了此活动:

public class ChooseLayout extends AppCompatActivity implements View.OnClickListener {

    EditText editText;
    Button button;
    Weather weather;
    Parser parser = new Parser();
    SharedPreferences sharedPreferences;
    String temperature, preassure,WindSpeed,WindDirection,Humidity,ViewDescription;
    boolean isChecked = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.choose_layout);
        editText = (EditText) findViewById(R.id.editText);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!isOnline()) {
                    Toast.makeText(getApplicationContext(), "Cannot connect to network, data will be restore from file with last downloaded data...", Toast.LENGTH_LONG).show();
                } else {
                    Thread t = new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                weather = parser.getWeatherForLocation(editText.getText() + "");
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        editText.setText(weather.getCity() + ",  " + weather.getCountry());
                                         temperature = weather.getTemperature();
                                    }
                                });
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    t.start();
                }
                Intent intent = new Intent(getApplicationContext(),Tab1.class);
                intent.putExtra("temperature", temperature);
                startActivity(intent);


            }
        });
        sharedPreferences = getSharedPreferences("file_name", MODE_PRIVATE);
    }

1 个答案:

答案 0 :(得分:0)

您可以在活动中添加或替换片段。

然后在您的活动中对add片段执行此操作:

FragmentManager manager = getSupportFragmentManager();
Tab1 tab1 = new Tab1();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(android.R.id.content, tab1);
transaction.commit();

replace片段执行此操作:

FragmentManager manager = getSupportFragmentManager();
Tab1 tab1 = new Tab1();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(android.R.id.content, tab1);
transaction.commit();

要从fragment传递数据,您可以使用Bundle作为

Bundle bundle = new Bundle();
bundle.putString("your_tag", your_string);
FragmentManager manager = getSupportFragmentManager();
Tab1 tab1 = new Tab1();
tab1.setArguments(bundle);
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(android.R.id.content, tab1);
transaction.commit();

要了解更多fragment-transaction,请查看此https://developer.android.com/reference/android/app/FragmentTransaction.html