2015-06-15 6 views
11
package com.example.utkarsh.beatle.app; 

import android.app.Fragment; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

import java.util.ArrayList; 
import java.util.Arrays; 
import java.util.List; 


public class MainActivity extends FragmentActivity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    if(savedInstanceState==null) 
    { 
     getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit(); 
    } 
} 


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

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

public static class PlaceholderFragment extends Fragment { 

    private ArrayAdapter<String> mForecastAdapter; 


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

     View rootView = inflater.inflate(R.layout.fragment_main, container, false); 
     String[] forecastArray = {"Today-Sunny-88/63", "Tommorrow-windy-88/94", "wed-aloo-alooo"}; 
     List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray)); 
     mForecastAdapter = new ArrayAdapter<String>(getActivity(), R.layout.fragment_main, R.id.list_item_forecast_textview, weekForecast); 
     ListView listView = (ListView) rootView.findViewById(R.id.list_view_forecast); 
     listView.setAdapter(mForecastAdapter); 
     return rootView; 

    } 
}} 

Messages Gradle Build Error:(27, 59) error: no suitable method found for add(int,PlaceholderFragment) method FragmentTransaction.add(Fragment,String) is not applicable (argument mismatch; int cannot be converted to Fragment) method FragmentTransaction.add(int,Fragment) is not applicable (argument mismatch; PlaceholderFragment cannot be converted to Fragment) Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output Error:Execution failed for task ':app:compileDebugJava'. Compilation failed; see the compiler error output for details.विधि को हल नहीं किया जा सकता 'जोड़ने (पूर्णांक, com.example.utkarsh.beatle.app.MainActivity.PlaceholderFragment)

+2

'आयात android.support.v4.app.Fragment;' आयात के बजाय android.app.Fragment; ' –

+0

मैंने इसे बदल दिया है अब ऐसा लगता है: import android.support.v4.app.Fragment; आयात android.os.Bundle; आयात android.view.LayoutInflater; गियरेटिंग त्रुटियां: त्रुटि: (1 9, 35) त्रुटि: प्रतीक वर्ग नहीं मिल सकता है FragmentActivity त्रुटि: (21, 5) त्रुटि: विधि supertypeError से किसी विधि को ओवरराइड या कार्यान्वित नहीं करती है: (23, 9) त्रुटि: प्रतीक चर सुपर नहीं मिल सकता त्रुटि: (24, 9) त्रुटि: प्रतीक विधि सेट नहीं मिल सकता है CONTentView (int) त्रुटि: (27, 13) त्रुटि: प्रतीक विधि नहीं मिल सकती है समर्थन समर्थन फ़ाइल() त्रुटि: (32, 5), और कई और त्रुटियां, मैं नौसिखिया हूँ कृपया – JSONParser

उत्तर

33

आप FragmentActivity और getSupportFragmentManager() उपयोग कर रहे हैं। इसलिए, PlaceholderFragment को android.support.v4.app.Fragment से प्राप्त करने की आवश्यकता है, android.app.Fragment नहीं।

+0

ऐसा करने में सहायता करें, विभिन्न त्रुटियों को उत्पन्न करता है जैसे: 'त्रुटि: (1 9, 35) त्रुटि: प्रतीक वर्ग नहीं मिल सकता है FragmentActivity त्रुटि: (21, 5) त्रुटि: विधि supertype से किसी विधि को ओवरराइड या कार्यान्वित नहीं करता है त्रुटि :(23, 9) त्रुटि: प्रतीक परिवर्तनीय सुपर नहीं मिल सका त्रुटि: (24, 9) त्रुटि: प्रतीक विधि सेट नहीं मिल सकता है CONTentView (int) त्रुटि: (27, 13) त्रुटि: प्रतीक विधि नहीं मिल सकती है समर्थन फ्रेगमेंट प्रबंधक() त्रुटि: (32, 5) त्रुटि: विधि supertype से किसी विधि को ओवरराइड या कार्यान्वित नहीं करती है त्रुटि: (35, 9) त्रुटि: प्रतीक विधि नहीं मिल सकती हैमेनूफ्लैटर () त्रुटि: (51, 16) त्रुटि: प्रतीक परिवर्तनीय supe – JSONParser

+0

@sesy नहीं मिल सकता: क्षमा करें, लेकिन आपकी टिप्पणी काम नहीं कर सका। आप एक अलग स्टैक ओवरफ़्लो प्रश्न पूछने के लिए स्वागत करते हैं जहां आप अपना संशोधित कोड दिखाते हैं और जो भी त्रुटियां देखते हैं उसका विवरण प्रदान करते हैं। – CommonsWare

+0

@ कॉमनवेयर: मैंने जो कुछ भी कहा है, वह मैंने किया है, इससे भी अधिक त्रुटियां उत्पन्न हुईं, इसलिए मैंने इसे हटा दिया है, आप इसे अधिक उत्तर देने का सुझाव दे सकते हैं – JSONParser

2

'आयात करें android.support.v4.app.Fragment; 'अपने प्रत्येक टुकड़े के लिए।

संबंधित मुद्दे