-1

フラグメントを使用して、シンプルで永続的なナビゲーション バーを作成しようとしています。問題は、次のエラー出力が表示されることです。

05-23 14:58:02.861: E/AndroidRuntime(882): FATAL EXCEPTION: main
05-23 14:58:02.861: E/AndroidRuntime(882): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo    {org.childrensmuseum.visittcmindy/org.childrensmuseum.visittcmindy.MainActivity}: java.lang.ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.os.Looper.loop(Looper.java:137)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.main(ActivityThread.java:4340)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.reflect.Method.invokeNative(Native Method)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.reflect.Method.invoke(Method.java:511)
05-23 14:58:02.861: E/AndroidRuntime(882):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-23 14:58:02.861: E/AndroidRuntime(882):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-23 14:58:02.861: E/AndroidRuntime(882):  at dalvik.system.NativeStart.main(Native Method)
05-23 14:58:02.861: E/AndroidRuntime(882): Caused by: java.lang.ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity
05-23 14:58:02.861: E/AndroidRuntime(882):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
05-23 14:58:02.861: E/AndroidRuntime(882):  ... 11 more

私の主な活動は次のようになります。

package org.childrensmuseum.visittcmindy;

import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.ImageButton;

public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getWindow().setFormat(PixelFormat.RGBA_8888);
    findViewById(R.id.NavigationBar).getBackground().setDither(true);
    ImageButton homeButton = (ImageButton) findViewById(R.id.home_button);
    homeButton.setColorFilter(Color.argb(255, 90, 179, 0));
}

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


}

私のフラグメントは次のようになります。

package org.childrensmuseum.visittcmindy;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MainNavigation extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    return inflater.inflate(R.layout.navigation_main, container, false);
}
}

最後に、メイン アクティビティの xml ファイルは次のようになります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ImageView 
    android:id="@+id/HomeBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/homescreen_desc"
    android:src="@drawable/homescreen"
    android:scaleType="centerCrop"
    />
<fragment android:name="org.childrensmuseum.visittcmindy.MainNavigation"
    android:id="@+id/NavigationBar"
    android:layout_gravity="bottom" />

</RelativeLayout>

私は何が欠けていますか?

4

1 に答える 1

1

この問題に対する一般的な回答にしようとするために編集されました(この場合、正しい回答は@Raghunandanによって提供されます):

うーん...あなたの MainActivity は「失われました」(ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity):

1.- Eclipse (または使用している IDE) のビルドの問題である可能性があります。プロジェクトをクリーンアップして再構築するか、Eclipse を再起動します。

2.- マニフェスト ファイルに問題がある可能性があります。「AndroidManifest.xml」にアクティビティを追加し、パッケージとアクティビティの名前が正しく記述されていることを確認します (大文字を確認してください)。例は次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.childrensmuseum.visittcmindy">
    <application>
        <activity android:name=".MainActivity"></activity>
    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest>

3.-あなたのケースではないようですが、外部ライブラリがビルドパスに正しく含まれていないことがあります。サードパーティのライブラリを「libs」フォルダーに配置し、それらを再参照する必要があります (右クリック、プロパティ、Java ビルド パス、ライブラリ、Jar の追加...)。

標準 Android ライブラリの一部ではない Maps ライブラリなどの共有ライブラリは、Android マニフェストで宣言する必要があります。AndroidManifest.xml ファイルを開き、要素の子として次を追加します。

<uses-library android:name="com.google.android.maps"/>

4.- @Raghunandan は、Android SDK Tools Rev 22 に更新した場合に備えて、ここで解決策を提供します。

Right click on your project goto properties. Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.
于 2013-05-23T15:20:25.307 に答える