好吧,我不知道我在做什麼錯在這裏。看了很多方向後,我不知道爲什麼它不起作用。一個解釋和幫助將不勝感激。包括LogCat日誌。充氣意見問題。嘗試將視圖添加到佈局。 ClassCastException異常
activity_camera.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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CameraActivity" >
<Button
android:id="@+id/buttonMenu"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/capture"
android:layout_alignBottom="@+id/capture"
android:layout_alignParentLeft="true"
android:layout_marginLeft="22dp"
android:text="menu" />
<Button
android:id="@+id/capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
android:onClick="onClick"
android:text="Take pic" />
</RelativeLayout>
這是給我一個錯誤
protected void onCreate(Bundle savedInstanceState) {
mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE); mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE);
super.onCreate(savedInstanceState);
RelativeLayout RL = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.activity_camera, null);
mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
RL.addView(mTextureView);
setContentView(RL);
logcat中的片段:
E/AndroidRuntime( 784): FATAL EXCEPTION: main
E/AndroidRuntime( 784): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
E/AndroidRuntime( 784): at android.widget.RelativeLayout$DependencyGraph.findRoots(RelativeLayout.java:1723)
E/AndroidRuntime( 784): at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1670)
E/AndroidRuntime( 784): at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:382)
E/AndroidRuntime( 784): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:403)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
E/AndroidRuntime( 784): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
E/AndroidRuntime( 784): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
E/AndroidRuntime( 784): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
E/AndroidRuntime( 784): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
E/AndroidRuntime( 784): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 784): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
E/AndroidRuntime( 784): at android.view.View.measure(View.java:15848)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
E/AndroidRuntime( 784): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
E/AndroidRuntime( 784): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
E/AndroidRuntime( 784): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
E/AndroidRuntime( 784): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
E/AndroidRuntime( 784): at android.view.Choreographer.doFrame(Choreographer.java:532)
E/AndroidRuntime( 784): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
E/AndroidRuntime( 784): at android.os.Handler.handleCallback(Handler.java:730)
E/AndroidRuntime( 784): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 784): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 784): at android.app.ActivityThread.main(ActivityThread.java:5103)
E/AndroidRuntime( 784): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 784): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime( 784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
E/AndroidRuntime( 784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 784): at dalvik.system.NativeStart.main(Native Method)
發佈你的activity_camera.xml –
爲什麼你有這個重複:'mPreferences = getSharedPreferences(「CurrentUser」,MODE_PRIVATE); mPreferences = getSharedPreferences(「CurrentUser」,MODE_PRIVATE);'? – Dyna
呵呵,我甚至不會注意到,在將它從一個活動轉移到另一個時,意外。 – TooTiredToDrink