2

앱이 시작될 때 XML- 파일에서 "클래스 조각을 부 풀리는 중 오류가 발생했습니다"오류가 발생합니다. 왜 그런지 모르겠다 고요?Android.view.InflateException : 시작시 클래스 조각이 부 풀릴 때 오류 발생 (onCreate 오류 없음)

나는이 오류가 발생하지 않는 다른 프로젝트에서 사용되는 유사한 파일과 함께 오류의 원인이되는 클래스 파일을 대체하려고 시도했지만 도움이되지 않았습니다. 따라서 문제가 클래스에없는 것 같습니다. 파일,하지만 다른 곳?

오류 :

01-09 23:16:52.054: E/AndroidRuntime(558): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.exempelfragmentsgrund/com.example.exempelfragmentsgrund.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment 

라인 XML- 파일 행 15 :

<fragment android:name="com.example.exempelfragmentgrund.VisaFragment" 
       android:id="@+id/fragment_container_stor" 
       android:layout_weight="3" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" /> 

VisaFragment.java onCreateView : 여기

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState){ 

    if (savedInstanceState != null){ 
     mCurrentPosition = savedInstanceState.getInt(ARG_POSITION); 
    } 

    return inflater.inflate(R.layout.om_sida, container, false);   
} 

는 전체 파일 :

오류 통나무 :

01-09 23:39:24.804: D/dalvikvm(595): GC_FOR_ALLOC freed 46K, 3% free 8843K/9027K, paused 38ms 
01-09 23:39:24.815: I/dalvikvm-heap(595): Grow heap (frag case) to 9.232MB for 513744-byte allocation 
01-09 23:39:24.884: D/dalvikvm(595): GC_FOR_ALLOC freed <1K, 3% free 9344K/9543K, paused 43ms 
01-09 23:39:24.974: D/dalvikvm(595): GC_CONCURRENT freed <1K, 3% free 9344K/9543K, paused 3ms+3ms 
01-09 23:39:25.014: D/AndroidRuntime(595): Shutting down VM 
01-09 23:39:25.014: W/dalvikvm(595): threadid=1: thread exiting with uncaught exception (group=0x40014760) 
01-09 23:39:25.034: E/AndroidRuntime(595): FATAL EXCEPTION: main 
01-09 23:39:25.034: E/AndroidRuntime(595): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.exempelfragmentsgrund/com.example.exempelfragmentsgrund.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.ActivityThread.access$1500(ActivityThread.java:122) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.os.Handler.dispatchMessage(Handler.java:99) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.os.Looper.loop(Looper.java:132) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.ActivityThread.main(ActivityThread.java:4025) 
01-09 23:39:25.034: E/AndroidRuntime(595): at java.lang.reflect.Method.invokeNative(Native Method) 
01-09 23:39:25.034: E/AndroidRuntime(595): at java.lang.reflect.Method.invoke(Method.java:491) 
01-09 23:39:25.034: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 
01-09 23:39:25.034: E/AndroidRuntime(595): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 
01-09 23:39:25.034: E/AndroidRuntime(595): at dalvik.system.NativeStart.main(Native Method) 
01-09 23:39:25.034: E/AndroidRuntime(595): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.view.LayoutInflater.inflate(LayoutInflater.java:479) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.view.LayoutInflater.inflate(LayoutInflater.java:391) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.view.LayoutInflater.inflate(LayoutInflater.java:347) 
01-09 23:39:25.034: E/AndroidRuntime(595): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:223) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.Activity.setContentView(Activity.java:1780) 
01-09 23:39:25.034: E/AndroidRuntime(595): at com.example.exempelfragmentsgrund.MainActivity.onCreate(MainActivity.java:13) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712) 
01-09 23:39:25.034: E/AndroidRuntime(595): ... 11 more 
01-09 23:39:25.034: E/AndroidRuntime(595): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.exempelfragmentgrund.VisaFragment: make sure class name exists, is public, and has an empty constructor that is public 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.Fragment.instantiate(Fragment.java:500) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.Fragment.instantiate(Fragment.java:468) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.Activity.onCreateView(Activity.java:4132) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664) 
01-09 23:39:25.034: E/AndroidRuntime(595): ... 20 more 
01-09 23:39:25.034: E/AndroidRuntime(595): Caused by: java.lang.ClassNotFoundException: com.example.exempelfragmentgrund.VisaFragment in loader dalvik.system.PathClassLoader[/data/app/com.example.exempelfragmentsgrund-1.apk] 
01-09 23:39:25.034: E/AndroidRuntime(595): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251) 
01-09 23:39:25.034: E/AndroidRuntime(595): at java.lang.ClassLoader.loadClass(ClassLoader.java:540) 
01-09 23:39:25.034: E/AndroidRuntime(595): at java.lang.ClassLoader.loadClass(ClassLoader.java:500) 
01-09 23:39:25.034: E/AndroidRuntime(595): at android.app.Fragment.instantiate(Fragment.java:490) 
01-09 23:39:25.034: E/AndroidRuntime(595): ... 23 more 

(레이아웃/대형) activity_main.XML :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:baselineAligned="false" 
    android:orientation="horizontal"  
    android:background="@color/menyBGColor" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <fragment android:name="com.example.exempelfragmentsgrund.MenyFragment" 
       android:id="@+id/meny_fragment" 
       android:layout_weight="1" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" /> 

    <fragment android:name="com.example.exempelfragmentgrund.VisaFragment" 
       android:id="@+id/fragment_container_stor" 
       android:layout_weight="3" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" /> 

</LinearLayout> 

VisaFragment.java :

package com.example.exempelfragmentsgrund; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentTransaction; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 

public class VisaFragment extends Fragment { 

    static final String ARG_POSITION = "position"; 
    int mCurrentPosition = -1; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState){ 

     if (savedInstanceState != null){ 
      mCurrentPosition = savedInstanceState.getInt(ARG_POSITION); 
     } 

     return inflater.inflate(R.layout.om_sida, container, false);   
    } 

    @Override 
    public void onStart(){ 
     super.onStart(); 
System.out.println("VisaFragment onStart");  

     Bundle argument = getArguments(); 
     if (argument != null){ 
      visaFragmentArgument(argument.getInt(ARG_POSITION)); 
     }else if (mCurrentPosition != -1){ 
      visaFragmentArgument(mCurrentPosition); 
     } 
    } 

    public void visaFragmentArgument(int position) { 
System.out.println("VisaFragment VisaFragmentArgument"); 


       TextView infoText = (TextView) getActivity().findViewById(R.id.fragmentTextView); 
     infoText.setText(getResources().getStringArray(R.array.adressLista)[position]); 
       //ArrayLista.infoText[position]); 
     TextView infoTitel = (TextView) getActivity().findViewById(R.id.fragmentTextViewTitel); 
     infoTitel.setText(getResources().getStringArray(R.array.infoTextTitel)[position]);     
     } 

    @Override 
    public void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 

     outState.putInt(ARG_POSITION, mCurrentPosition); 
    } 
} 

om_sida.XML :

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="@dimen/infoTextPadding" 
    android:background="@color/visaSidaBGColor" > 

     <TextView 
     android:id="@+id/fragmentTextViewTitel" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="left" 
     android:layout_marginTop="16dp" 
     android:textSize="36sp" /> 

    <TextView 
     android:id="@+id/fragmentTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/fragmentTextViewTitel" 
     android:layout_marginTop="20dp" 
     android:textSize="18sp" /> 

</RelativeLayout> 

MainActivity.java

-
package com.example.exempelfragmentsgrund; 

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentTransaction; 

public class MainActivity extends FragmentActivity implements MenyFragment.onMenyKnappClickListener{ 

    @Override 
    public void onCreate (Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_main); 

     if (findViewById(R.id.fragment_container_liten) != null){ 
      if (savedInstanceState != null){ 
       return; 
      } 

      MenyFragment menyFragment = new MenyFragment(); 
      menyFragment.setArguments(getIntent().getExtras()); 
      getSupportFragmentManager().beginTransaction() 
      .add(R.id.fragment_container, menyFragment).commit(); 
     } 
    } 

    public void onMenyKnappVald (int position){ 


    VisaFragment visaFrag = (VisaFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container_stor); 

    if (visaFrag != null) { 
     visaFrag.visaFragmentArgument(position); 

    }else{ 
     VisaFragment nyttFragment = new VisaFragment(); 
     Bundle argument = new Bundle(); 

     argument.putInt(VisaFragment.ARG_POSITION, position); 
     nyttFragment.setArguments(argument); 
     FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
     transaction.replace(R.id.fragment_container, nyttFragment); 
     transaction.addToBackStack(null); 
     transaction.commit(); 
    } 


    } 

} 

답변

1

변경 com.example.exempelfragmentgrund.VisaFragment 당신은 '의'

+0

gaaah가 누락되었습니다. 내가 얼마나 바보 같 냐고. 나는 정말로 내가 그것을 점검했다라고 생각했다. .. 고마워! – Sluggo