0

私は android Tablet Devices を使用しています。その中で、私はレイアウト1とレイアウト2の2つのレイアウトを持っています.私のタブレットでは、画面の前半に1つのレイアウト(layout1)を設定し、画面の後半に2番目のレイアウト(layout)を設定しました.私のレイアウトlayout1はImageView.その Imageview をクリックすると、xml で既に設計したレイアウトが既存のレイアウト 1 を置き換える必要があります。

私はこのように試しました:

  package com.example.androidoverlapp;



import android.os.Bundle;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends Activity implements OnClickListener {
ImageView i;LinearLayout l;View viewToLoad;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.homepage);
       i=(ImageView)findViewById(R.id.gprs);
       l=(LinearLayout)findViewById(R.id.homepageoverlappable);
       i.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
    l.removeAllViews();
    viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.activity_main, null);
    l.addView(viewToLoad);

    }



}

しかし、それは強制的に閉じます。

Logcat の出力:

03-13 16:04:41.461: I/Process(309): Sending signal. PID: 309 SIG: 9
03-13 16:05:53.056: D/dalvikvm(331): GC freed 652 objects / 53680 bytes in 145ms
03-13 16:05:58.796: D/AndroidRuntime(331): Shutting down VM
03-13 16:05:58.826: W/dalvikvm(331): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-13 16:05:58.826: E/AndroidRuntime(331): Uncaught handler: thread main exiting due to uncaught exception
03-13 16:05:58.866: E/AndroidRuntime(331): java.lang.NullPointerException
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.LayoutInflater.from(LayoutInflater.java:171)
03-13 16:05:58.866: E/AndroidRuntime(331):  at com.example.androidoverlapp.MainActivity.onClick(MainActivity.java:28)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.View.performClick(View.java:2364)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.View.onTouchEvent(View.java:4179)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.View.dispatchTouchEvent(View.java:3709)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
03-13 16:05:58.866: E/AndroidRuntime(331):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
03-13 16:05:58.866: E/AndroidRuntime(331):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
03-13 16:05:58.866: E/AndroidRuntime(331):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.os.Looper.loop(Looper.java:123)
03-13 16:05:58.866: E/AndroidRuntime(331):  at android.app.ActivityThread.main(ActivityThread.java:4363)
03-13 16:05:58.866: E/AndroidRuntime(331):  at java.lang.reflect.Method.invokeNative(Native Method)
03-13 16:05:58.866: E/AndroidRuntime(331):  at java.lang.reflect.Method.invoke(Method.java:521)
03-13 16:05:58.866: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-13 16:05:58.866: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-13 16:05:58.866: E/AndroidRuntime(331):  at dalvik.system.NativeStart.main(Native Method)
03-13 16:05:58.916: I/dalvikvm(331): threadid=7: reacting to signal 3
03-13 16:05:58.916: E/dalvikvm(331): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
03-13 16:06:00.739: I/Process(331): Sending signal. PID: 331 SIG: 9

この問題を解決する方法を教えてください。

4

0 に答える 0