davidhlynsson
davidhlynsson

Reputation: 79

Call requires api level 11. What to do when i get this error?

I am using this code

public class MainActivity extends Activity {

    TextView textview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    String hallo = "blabla " + "jojo " + "lol " + "\n" + "doj " + "drasl " + "\n"; 
    InputStream is = new ByteArrayInputStream(hallo.getBytes());
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);

    String line;
    try {
        while ((line = in.readLine()) != null) {
            String[] RowData = line.split(" ");
            String eitt = RowData[0];
            String tvo = RowData[1];

            TextView textView = new TextView(this);
            textView.setText(line);
            textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT
           ,LayoutParams.WRAP_CONTENT));
            linearLayout.addView(textView);
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    }
}

With this xml code

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        </LinearLayout>

</ScrollView>

I want to insert these parts of a string into a table layout, so that when my pieces of text are printed they come out in nice columns. The way this works, it just prints the string line for line instead of putting it into columns. It's also very important to know that I don't know how many lines are going to be in the string, so I can't just make 4 textview boxes because there could be 50 og a hundred lines, so I need to make an i amount of textview boxes in a table view with i being the number of lines. But i always get this error, call requires api level 11, and i am using api level 10. The error is coming because of this line

textView.setLayoutParams(newLayoutParams(LayoutParams.FILL_PARENT
           ,LayoutParams.WRAP_CONTENT));

What kind of paramlayout options can i use to let this work.

Upvotes: 2

Views: 2110

Answers (2)

ebeilmann
ebeilmann

Reputation: 171

Your not showing the imports but it may be possible you are using the wrong LayoutParams import (like meowmeow suggested). It looks like you might want to use the following import instead.

import android.view.ViewGroup.LayoutParams;

Upvotes: 3

meowmeow
meowmeow

Reputation: 1

I just had the same issue. Double check your imports to see you aren't importing an inappropriate LayoutParams. I ended up having something random like Actionbar.LayoutParams imported when it should have been LinearLayout.LayoutParams.

Upvotes: 0

Related Questions